Repository: RustCrypto/block-modes (language: rust)

Issue:
belt-ctr implementation
Hello!
Just tried to implement STB 34.101.31-2020 belt-ctr cipher:
<img width="637" alt="image" src="https://user-images.githubusercontent.com/5614215/222424602-a47ed18e-1416-4787-ac1b-3e1f64189e66.png">

With code:
```rust
pub type BeltCtr = ctr::Ctr128LE<belt_block::BeltBlock>;

#[cfg(test)]
mod tests {
    use ctr::cipher::{KeyIvInit, StreamCipher};
    use hex_literal::hex;
    use super::*;

    #[test]
    fn test() {
        let x = hex!("B194BAC8 0A08F53B 366D008E 584A5DE4 8504FA9D 1BB6C7AC 252E72C2 02FDCE0D 5BE3D612 17B96181 FE6786AD 716B890B");
        let k = hex!("E9DEE72C 8F0C0FA6 2DDB49F4 6F739647 06075316 ED247A37 39CBA383 03A98BF6");
        let s = hex!("BE329713 43FC9A48 A02A885F 194B09A1");
        let y = hex!("52C9AF96 FF50F644 35FC43DE F56BD797 D5B5B1FF 79FB4125 7AB9CDF6 E63E81F8 F0034147 3EAE4098 33622DE0 5213773A");

        let mut cipher = BeltCtr::new(&k.into(), &s.into());
        let mut buf = x.to_vec();
        cipher.apply_keystream(&mut buf);
        assert_eq!(buf, y);
    }
}
```

And got some problems:
gen_ks_block return bytes:
```
72 8a f3 c2   9a e7 56 4f 
54 01 c9 10   13 31 d8 a4
```

But in STB, we need to add +1 in LE (so, bytes will be):
```
73 8a f3 c2   9a e7 56 4f  
54 01 c9 10   13 31 d8 a3
```

And it should be reversed. What I suppose to do, to resolve this problem? Implement self own gen_ks_block?
Thank you!
@newpavlov 


Discussion / hints:
I think it will be better to implement the mode in a separate crate (feel free to submit a PR with it). In addition to not counting from 0, the specification also encrypts IV before using it with counter.
Should I create crate stb-modes, like gost-modes?
Hm, I am not sure. If you do not plan to implement the other modes, then I think we can publish it under `belt-ctr` for now. The mode could be defined generically, but would use `belt-block` by default.
I need to implement ecb, cfb, ctr modes, also belt-mac and bign (elliptic curves) :)
And also, should I PR into stream-ciphers with belt-ctr?
What about repo for ecb and mac?
Since we keep the `ctr` crate in this repository, `belt-ctr` should go here as well.

I think `belt-cfb` should be compatible with implementation in `cfb-mode`. Can you check it?

`belt-ecb` and `belt-cbc` use variation of the classic ciphertext stealing, but with the tweak for messages with length multiple of the block size. They can go into this repository with inherent methods for encryption and decryption since we currently do not have traits for ciphertext stealing algorithms.

`belt-mac` looks like CMAC, but I am not sure that padding handling is the same. If not, we would need a separate crate in the [MACs repository](https://github.com/RustCrypto/MACs).

For elliptic curves take a look at the [`primeorder`](https://github.com/RustCrypto/elliptic-curves/tree/master/primeorder) crate. If you have any questions about it, I think it will be better to ask @tarcieri in our Zulip chat.
Belt-cfb is compatible, just checked it right now.
Ecb is not compatible, because stealing, right.

Okay, thank you for help!
If I have any question - I will ask :)

Fix patch:
diff --git a/.github/workflows/belt-ctr.yaml b/.github/workflows/belt-ctr.yaml
new file mode 100644
index 0000000..544ab17
--- /dev/null
+++ b/.github/workflows/belt-ctr.yaml
@@ -0,0 +1,62 @@
+name: belt-ctr
+
+on:
+  pull_request:
+    paths:
+      - "belt-ctr/**"
+      - "Cargo.*"
+  push:
+    branches: master
+
+defaults:
+  run:
+    working-directory: belt-ctr
+
+env:
+  CARGO_INCREMENTAL: 0
+  RUSTFLAGS: "-Dwarnings"
+
+jobs:
+  build:
+    runs-on: ubuntu-latest
+    strategy:
+      matrix:
+        rust:
+          - 1.57.0 # MSRV
+          - stable
+        target:
+          - thumbv7em-none-eabi
+          - wasm32-unknown-unknown
+    steps:
+      - uses: actions/checkout@v3
+      - uses: RustCrypto/actions/cargo-cache@master
+      - uses: actions-rs/toolchain@v1
+        with:
+          toolchain: ${{ matrix.rust }}
+          target: ${{ matrix.target }}
+          override: true
+          profile: minimal
+      - run: cargo build --no-default-features --release --target ${{ matrix.target }}
+
+  minimal-versions:
+    uses: RustCrypto/actions/.github/workflows/minimal-versions.yml@master
+    with:
+        working-directory: ${{ github.workflow }}
+
+  test:
+    runs-on: ubuntu-latest
+    strategy:
+      matrix:
+        rust:
+          - 1.57.0 # MSRV
+          - stable
+    steps:
+      - uses: actions/checkout@v3
+      - uses: RustCrypto/actions/cargo-cache@master
+      - uses: actions-rs/toolchain@v1
+        with:
+          toolchain: ${{ matrix.rust }}
+          override: true
+          profile: minimal
+      - run: cargo test
+      - run: cargo test --all-features
diff --git a/Cargo.lock b/Cargo.lock
index 604c2d3..4397426 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -22,6 +22,15 @@ dependencies = [
  "cipher",
 ]
 
+[[package]]
+name = "belt-ctr"
+version = "0.1.0"
+dependencies = [
+ "belt-block",
+ "cipher",
+ "hex-literal 0.4.0",
+]
+
 [[package]]
 name = "blobby"
 version = "0.3.1"
@@ -43,7 +52,7 @@ version = "0.1.2"
 dependencies = [
  "aes",
  "cipher",
- "hex-literal",
+ "hex-literal 0.3.4",
 ]
 
 [[package]]
@@ -53,7 +62,7 @@ dependencies = [
  "aes",
  "belt-block",
  "cipher",
- "hex-literal",
+ "hex-literal 0.3.4",
 ]
 
 [[package]]
@@ -62,7 +71,7 @@ version = "0.8.1"
 dependencies = [
  "aes",
  "cipher",
- "hex-literal",
+ "hex-literal 0.3.4",
 ]
 
 [[package]]
@@ -108,7 +117,7 @@ version = "0.9.2"
 dependencies = [
  "aes",
  "cipher",
- "hex-literal",
+ "hex-literal 0.3.4",
  "kuznyechik",
  "magma",
 ]
@@ -129,13 +138,19 @@ version = "0.3.4"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0"
 
+[[package]]
+name = "hex-literal"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4bcb5b3e439c92a7191df2f9bbe733de8de55c3f86368cdb1c63f8be7e9e328e"
+
 [[package]]
 name = "ige"
 version = "0.1.1"
 dependencies = [
  "aes",
  "cipher",
- "hex-literal",
+ "hex-literal 0.3.4",
 ]
 
 [[package]]
@@ -178,7 +193,7 @@ version = "0.6.1"
 dependencies = [
  "aes",
  "cipher",
- "hex-literal",
+ "hex-literal 0.3.4",
 ]
 
 [[package]]
@@ -187,7 +202,7 @@ version = "0.1.2"
 dependencies = [
  "aes",
  "cipher",
- "hex-literal",
+ "hex-literal 0.3.4",
 ]
 
 [[package]]
diff --git a/Cargo.toml b/Cargo.toml
index e82a512..1d90026 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,5 +1,6 @@
 [workspace]
 members = [
+    "belt-ctr",
     "cbc",
     "cfb8",
     "cfb-mode",
diff --git a/README.md b/README.md
index cf899a6..c660220 100644
--- a/README.md
+++ b/README.md
@@ -5,8 +5,7 @@
 ![Apache2/MIT licensed][license-image]
 [![HAZMAT][hazmat-image]][hazmat-link]
 
-Collection of [block modes] written in pure Rust generic over
-block ciphers.
+Collection of [block modes] written in pure Rust generic over block ciphers.
 
 ## ⚠️ Security Warning: [Hazmat!][hazmat-link]
 
@@ -22,6 +21,7 @@ less error-prone than manual integrity verification.
 
 | Name | Crate name | crates.io |  Docs  | MSRV |
 |------|------------|-----------|--------|------|
+| [BelT CTR] | [`belt-ctr`] |  [![crates.io](https://img.shields.io/crates/v/belt-ctr.svg)](https://crates.io/crates/belt-ctr) | [![Documentation](https://docs.rs/belt-ctr/badge.svg)](https://docs.rs/belt-ctr) |  ![MSRV 1.57][msrv-1.57] |
 | [Cipher Block Chaining][CBC] | [`cbc`] | [![crates.io](https://img.shields.io/crates/v/cbc.svg)](https://crates.io/crates/cbc) | [![Documentation](https://docs.rs/cbc/badge.svg)](https://docs.rs/cbc) |  ![MSRV 1.56][msrv-1.56] |
 | [8-bit Cipher Feedback][CFB-8] | [`cfb8`] | [![crates.io](https://img.shields.io/crates/v/cfb8.svg)](https://crates.io/crates/cfb8) | [![Documentation](https://docs.rs/cfb8/badge.svg)](https://docs.rs/cfb8) |  ![MSRV 1.56][msrv-1.56] |
 | [Full-block Cipher Feedback][CFB] | [`cfb-mode`] | [![crates.io](https://img.shields.io/crates/v/cfb-mode.svg)](https://crates.io/crates/cfb-mode) | [![Documentation](https://docs.rs/cfb-mode/badge.svg)](https://docs.rs/cfb-mode) |  ![MSRV 1.56][msrv-1.56] |
@@ -59,9 +59,11 @@ Unless you explicitly state otherwise, any contribution intentionally submitted
 [hazmat-link]: https://github.com/RustCrypto/meta/blob/master/HAZMAT.md
 [aead-link]: https://github.com/RustCrypto/AEADs
 [msrv-1.56]: https://img.shields.io/badge/rustc-1.56.0+-blue.svg
+[msrv-1.57]: https://img.shields.io/badge/rustc-1.57.0+-blue.svg
 
 [//]: # (crates)
 
+[`belt-ctr`]: ./belt-ctr
 [`cbc`]: ./cbc
 [`cfb8`]: ./cfb8
 [`cfb-mode`]: ./cfb-mode
@@ -74,6 +76,7 @@ Unless you explicitly state otherwise, any contribution intentionally submitted
 [//]: # (links)
 
 [block modes]: https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation
+[BelT CTR]: https://apmi.bsu.by/assets/files/std/belt-spec371.pdf
 [CBC]: https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Cipher_block_chaining_(CBC)
 [CFB-8]: https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#CFB-1,_CFB-8,_CFB-64,_CFB-128,_etc.
 [CFB]: https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Full-block_CFB
diff --git a/belt-ctr/CHANGELOG.md b/belt-ctr/CHANGELOG.md
new file mode 100644
index 0000000..82958b1
--- /dev/null
+++ b/belt-ctr/CHANGELOG.md
@@ -0,0 +1,9 @@
+# Changelog
+
+All notable changes to this project will be documented in this file.
+
+The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
+and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+
+## 0.1.0 (2023-04-02)
+- Initial release
diff --git a/belt-ctr/Cargo.toml b/belt-ctr/Cargo.toml
new file mode 100644
index 0000000..3d4a201
--- /dev/null
+++ b/belt-ctr/Cargo.toml
@@ -0,0 +1,31 @@
+[package]
+name = "belt-ctr"
+version = "0.1.0"
+description = "CTR block mode of operation specified by the BelT standard"
+authors = ["RustCrypto Developers"]
+license = "MIT OR Apache-2.0"
+edition = "2021"
+rust-version = "1.56"
+readme = "README.md"
+documentation = "https://docs.rs/belt-ctr"
+repository = "https://github.com/RustCrypto/block-modes"
+keywords = ["crypto", "block-mode", "stream-cipher", "ciphers", "belt"]
+categories = ["cryptography", "no-std"]
+
+[dependencies]
+cipher = "0.4"
+belt-block = "0.1"
+
+[dev-dependencies]
+hex-literal = "0.4"
+belt-block = "0.1"
+cipher = { version = "0.4", features = ["dev"] }
+
+[features]
+alloc = ["cipher/alloc"]
+std = ["cipher/std", "alloc"]
+zeroize = ["cipher/zeroize"]
+
+[package.metadata.docs.rs]
+all-features = true
+rustdoc-args = ["--cfg", "docsrs"]
diff --git a/belt-ctr/LICENSE-APACHE b/belt-ctr/LICENSE-APACHE
new file mode 100644
index 0000000..78173fa
--- /dev/null
+++ b/belt-ctr/LICENSE-APACHE
@@ -0,0 +1,201 @@
+                              Apache License
+                        Version 2.0, January 2004
+                     http://www.apache.org/licenses/
+
+TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+1. Definitions.
+
+   "License" shall mean the terms and conditions for use, reproduction,
+   and distribution as defined by Sections 1 through 9 of this document.
+
+   "Licensor" shall mean the copyright owner or entity authorized by
+   the copyright owner that is granting the License.
+
+   "Legal Entity" shall mean the union of the acting entity and all
+   other entities that control, are controlled by, or are under common
+   control with that entity. For the purposes of this definition,
+   "control" means (i) the power, direct or indirect, to cause the
+   direction or management of such entity, whether by contract or
+   otherwise, or (ii) ownership of fifty percent (50%) or more of the
+   outstanding shares, or (iii) beneficial ownership of such entity.
+
+   "You" (or "Your") shall mean an individual or Legal Entity
+   exercising permissions granted by this License.
+
+   "Source" form shall mean the preferred form for making modifications,
+   including but not limited to software source code, documentation
+   source, and configuration files.
+
+   "Object" form shall mean any form resulting from mechanical
+   transformation or translation of a Source form, including but
+   not limited to compiled object code, generated documentation,
+   and conversions to other media types.
+
+   "Work" shall mean the work of authorship, whether in Source or
+   Object form, made available under the License, as indicated by a
+   copyright notice that is included in or attached to the work
+   (an example is provided in the Appendix below).
+
+   "Derivative Works" shall mean any work, whether in Source or Object
+   form, that is based on (or derived from) the Work and for which the
+   editorial revisions, annotations, elaborations, or other modifications
+   represent, as a whole, an original work of authorship. For the purposes
+   of this License, Derivative Works shall not include works that remain
+   separable from, or merely link (or bind by name) to the interfaces of,
+   the Work and Derivative Works thereof.
+
+   "Contribution" shall mean any work of authorship, including
+   the original version of the Work and any modifications or additions
+   to that Work or Derivative Works thereof, that is intentionally
+   submitted to Licensor for inclusion in the Work by the copyright owner
+   or by an individual or Legal Entity authorized to submit on behalf of
+   the copyright owner. For the purposes of this definition, "submitted"
+   means any form of electronic, verbal, or written communication sent
+   to the Licensor or its representatives, including but not limited to
+   communication on electronic mailing lists, source code control systems,
+   and issue tracking systems that are managed by, or on behalf of, the
+   Licensor for the purpose of discussing and improving the Work, but
+   excluding communication that is conspicuously marked or otherwise
+   designated in writing by the copyright owner as "Not a Contribution."
+
+   "Contributor" shall mean Licensor and any individual or Legal Entity
+   on behalf of whom a Contribution has been received by Licensor and
+   subsequently incorporated within the Work.
+
+2. Grant of Copyright License. Subject to the terms and conditions of
+   this License, each Contributor hereby grants to You a perpetual,
+   worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+   copyright license to reproduce, prepare Derivative Works of,
+   publicly display, publicly perform, sublicense, and distribute the
+   Work and such Derivative Works in Source or Object form.
+
+3. Grant of Patent License. Subject to the terms and conditions of
+   this License, each Contributor hereby grants to You a perpetual,
+   worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+   (except as stated in this section) patent license to make, have made,
+   use, offer to sell, sell, import, and otherwise transfer the Work,
+   where such license applies only to those patent claims licensable
+   by such Contributor that are necessarily infringed by their
+   Contribution(s) alone or by combination of their Contribution(s)
+   with the Work to which such Contribution(s) was submitted. If You
+   institute patent litigation against any entity (including a
+   cross-claim or counterclaim in a lawsuit) alleging that the Work
+   or a Contribution incorporated within the Work constitutes direct
+   or contributory patent infringement, then any patent licenses
+   granted to You under this License for that Work shall terminate
+   as of the date such litigation is filed.
+
+4. Redistribution. You may reproduce and distribute copies of the
+   Work or Derivative Works thereof in any medium, with or without
+   modifications, and in Source or Object form, provided that You
+   meet the following conditions:
+
+   (a) You must give any other recipients of the Work or
+       Derivative Works a copy of this License; and
+
+   (b) You must cause any modified files to carry prominent notices
+       stating that You changed the files; and
+
+   (c) You must retain, in the Source form of any Derivative Works
+       that You distribute, all copyright, patent, trademark, and
+       attribution notices from the Source form of the Work,
+       excluding those notices that do not pertain to any part of
+       the Derivative Works; and
+
+   (d) If the Work includes a "NOTICE" text file as part of its
+       distribution, then any Derivative Works that You distribute must
+       include a readable copy of the attribution notices contained
+       within such NOTICE file, excluding those notices that do not
+       pertain to any part of the Derivative Works, in at least one
+       of the following places: within a NOTICE text file distributed
+       as part of the Derivative Works; within the Source form or
+       documentation, if provided along with the Derivative Works; or,
+       within a display generated by the Derivative Works, if and
+       wherever such third-party notices normally appear. The contents
+       of the NOTICE file are for informational purposes only and
+       do not modify the License. You may add Your own attribution
+       notices within Derivative Works that You distribute, alongside
+       or as an addendum to the NOTICE text from the Work, provided
+       that such additional attribution notices cannot be construed
+       as modifying the License.
+
+   You may add Your own copyright statement to Your modifications and
+   may provide additional or different license terms and conditions
+   for use, reproduction, or distribution of Your modifications, or
+   for any such Derivative Works as a whole, provided Your use,
+   reproduction, and distribution of the Work otherwise complies with
+   the conditions stated in this License.
+
+5. Submission of Contributions. Unless You explicitly state otherwise,
+   any Contribution intentionally submitted for inclusion in the Work
+   by You to the Licensor shall be under the terms and conditions of
+   this License, without any additional terms or conditions.
+   Notwithstanding the above, nothing herein shall supersede or modify
+   the terms of any separate license agreement you may have executed
+   with Licensor regarding such Contributions.
+
+6. Trademarks. This License does not grant permission to use the trade
+   names, trademarks, service marks, or product names of the Licensor,
+   except as required for reasonable and customary use in describing the
+   origin of the Work and reproducing the content of the NOTICE file.
+
+7. Disclaimer of Warranty. Unless required by applicable law or
+   agreed to in writing, Licensor provides the Work (and each
+   Contributor provides its Contributions) on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+   implied, including, without limitation, any warranties or conditions
+   of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+   PARTICULAR PURPOSE. You are solely responsible for determining the
+   appropriateness of using or redistributing the Work and assume any
+   risks associated with Your exercise of permissions under this License.
+
+8. Limitation of Liability. In no event and under no legal theory,
+   whether in tort (including negligence), contract, or otherwise,
+   unless required by applicable law (such as deliberate and grossly
+   negligent acts) or agreed to in writing, shall any Contributor be
+   liable to You for damages, including any direct, indirect, special,
+   incidental, or consequential damages of any character arising as a
+   result of this License or out of the use or inability to use the
+   Work (including but not limited to damages for loss of goodwill,
+   work stoppage, computer failure or malfunction, or any and all
+   other commercial damages or losses), even if such Contributor
+   has been advised of the possibility of such damages.
+
+9. Accepting Warranty or Additional Liability. While redistributing
+   the Work or Derivative Works thereof, You may choose to offer,
+   and charge a fee for, acceptance of support, warranty, indemnity,
+   or other liability obligations and/or rights consistent with this
+   License. However, in accepting such obligations, You may act only
+   on Your own behalf and on Your sole responsibility, not on behalf
+   of any other Contributor, and only if You agree to indemnify,
+   defend, and hold each Contributor harmless for any liability
+   incurred by, or claims asserted against, such Contributor by reason
+   of your accepting any such warranty or additional liability.
+
+END OF TERMS AND CONDITIONS
+
+APPENDIX: How to apply the Apache License to your work.
+
+   To apply the Apache License to your work, attach the following
+   boilerplate notice, with the fields enclosed by brackets "[]"
+   replaced with your own identifying information. (Don't include
+   the brackets!)  The text should be enclosed in the appropriate
+   comment syntax for the file format. We also recommend that a
+   file or class name and description of purpose be included on the
+   same "printed page" as the copyright notice for easier
+   identification within third-party archives.
+
+Copyright [yyyy] [name of copyright owner]
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
diff --git a/belt-ctr/LICENSE-MIT b/belt-ctr/LICENSE-MIT
new file mode 100644
index 0000000..50c6180
--- /dev/null
+++ b/belt-ctr/LICENSE-MIT
@@ -0,0 +1,25 @@
+Copyright (c) 2023 The RustCrypto Project Developers
+
+Permission is hereby granted, free of charge, to any
+person obtaining a copy of this software and associated
+documentation files (the "Software"), to deal in the
+Software without restriction, including without
+limitation the rights to use, copy, modify, merge,
+publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software
+is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice
+shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
+ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
+TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
+PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
+SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
+IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
diff --git a/belt-ctr/README.md b/belt-ctr/README.md
new file mode 100644
index 0000000..3ab88a4
--- /dev/null
+++ b/belt-ctr/README.md
@@ -0,0 +1,91 @@
+# RustCrypto: belt-ctr
+
+[![crate][crate-image]][crate-link]
+[![Docs][docs-image]][docs-link]
+![Apache2/MIT licensed][license-image]
+![Rust Version][rustc-image]
+[![Project Chat][chat-image]][chat-link]
+[![Build Status][build-image]][build-link]
+
+Generic implementation of the [`belt-ctr`] block mode of operation.
+
+Mode functionality is accessed using traits from the [`cipher`] crate.
+
+# ⚠️ Security Warning: Hazmat!
+
+This crate does not ensure ciphertexts are authentic! Thus ciphertext integrity
+is not verified, which can lead to serious vulnerabilities!
+[AEADs] provide simple authenticated encryption,
+which is much less error-prone than manual integrity verification.
+
+# Example
+```
+use hex_literal::hex;
+use belt_ctr::{BeltCtr, cipher::{KeyIvInit, StreamCipher, StreamCipherSeek}};
+
+let key = &[0x42; 32];
+let iv = &[0x24; 16];
+let plaintext: &[u8; 34] = b"hello world! this is my plaintext.";
+let ciphertext: &[u8; 34] = &hex!(
+    "38DF06243BD85DA1CAE597CE680D3AFE"
+    "0EBB372A4F6A858DB2DBE20A63567EED"
+    "7D1B"
+);
+
+let mut cipher: BeltCtr = BeltCtr::new_from_slices(key, iv).unwrap();
+
+// encrypt in-place
+let mut buf = plaintext.clone();
+cipher.apply_keystream(&mut buf);
+assert_eq!(buf[..], ciphertext[..]);
+
+cipher.seek(0);
+cipher.apply_keystream(&mut buf);
+assert_eq!(buf[..], plaintext[..]);
+```
+
+## Minimum Supported Rust Version
+
+Rust **1.57** or higher.
+
+Minimum supported Rust version can be changed in the future, but it will be
+done with a minor version bump.
+
+## SemVer Policy
+
+- All on-by-default features of this library are covered by SemVer
+- MSRV is considered exempt from SemVer as noted above
+
+## License
+
+Licensed under either of:
+
+ * [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)
+ * [MIT license](http://opensource.org/licenses/MIT)
+
+at your option.
+
+### Contribution
+
+Unless you explicitly state otherwise, any contribution intentionally submitted
+for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
+dual licensed as above, without any additional terms or conditions.
+
+[//]: # (badges)
+
+[crate-image]: https://img.shields.io/crates/v/belt-ctr.svg
+[crate-link]: https://crates.io/crates/belt-ctr
+[docs-image]: https://docs.rs/belt-ctr/badge.svg
+[docs-link]: https://docs.rs/belt-ctr/
+[license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg
+[rustc-image]: https://img.shields.io/badge/rustc-1.57+-blue.svg
+[chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg
+[chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/308460-block-modes
+[build-image]: https://github.com/RustCrypto/block-modes/workflows/belt-ctr/badge.svg?branch=master&event=push
+[build-link]: https://github.com/RustCrypto/block-modes/actions?query=workflow%3Abelt-ctr+branch%3Amaster
+
+[//]: # (general links)
+
+[cipher]: https://docs.rs/cipher/
+[`belt-ctr`]: https://apmi.bsu.by/assets/files/std/belt-spec371.pdf
+[AEADs]: https://github.com/RustCrypto/AEADs
diff --git a/belt-ctr/benches/belt-ctr.rs b/belt-ctr/benches/belt-ctr.rs
new file mode 100644
index 0000000..6ed2d8d
--- /dev/null
+++ b/belt-ctr/benches/belt-ctr.rs
@@ -0,0 +1,10 @@
+#![feature(test)]
+extern crate test;
+
+cipher::stream_cipher_bench!(
+    belt_ctr::BeltCtr;
+    belt_ctr_bench1_16b 16;
+    belt_ctr_bench2_256b 256;
+    belt_ctr_bench3_1kib 1024;
+    belt_ctr_bench4_16kib 16384;
+);
diff --git a/belt-ctr/src/backend.rs b/belt-ctr/src/backend.rs
new file mode 100644
index 0000000..f965d49
--- /dev/null
+++ b/belt-ctr/src/backend.rs
@@ -0,0 +1,76 @@
+use cipher::{
+    consts::U16, Block, BlockBackend, BlockClosure, BlockSizeUser, ParBlocks, ParBlocksSizeUser,
+    StreamBackend, StreamClosure,
+};
+
+struct Backend<'a, B>
+where
+    B: BlockBackend<BlockSize = U16>,
+{
+    s: &'a mut u128,
+    backend: &'a mut B,
+}
+
+impl<'a, B> BlockSizeUser for Backend<'a, B>
+where
+    B: BlockBackend<BlockSize = U16>,
+{
+    type BlockSize = B::BlockSize;
+}
+
+impl<'a, B> ParBlocksSizeUser for Backend<'a, B>
+where
+    B: BlockBackend<BlockSize = U16>,
+{
+    type ParBlocksSize = B::ParBlocksSize;
+}
+
+impl<'a, B> StreamBackend for Backend<'a, B>
+where
+    B: BlockBackend<BlockSize = U16>,
+{
+    #[inline(always)]
+    fn gen_ks_block(&mut self, block: &mut Block<Self>) {
+        *self.s = self.s.wrapping_add(1);
+        let tmp = self.s.to_le_bytes().into();
+        self.backend.proc_block((&tmp, block).into());
+    }
+
+    #[inline(always)]
+    fn gen_par_ks_blocks(&mut self, blocks: &mut ParBlocks<Self>) {
+        let mut tmp = ParBlocks::<Self>::default();
+        let mut s = *self.s;
+        for block in tmp.iter_mut() {
+            s = s.wrapping_add(1);
+            *block = s.to_le_bytes().into();
+        }
+        *self.s = s;
+        self.backend.proc_par_blocks((&tmp, blocks).into());
+    }
+}
+
+pub(crate) struct Closure<'a, SC>
+where
+    SC: StreamClosure<BlockSize = U16>,
+{
+    pub(crate) s: &'a mut u128,
+    pub(crate) f: SC,
+}
+
+impl<'a, SC> BlockSizeUser for Closure<'a, SC>
+where
+    SC: StreamClosure<BlockSize = U16>,
+{
+    type BlockSize = U16;
+}
+
+impl<'a, SC> BlockClosure for Closure<'a, SC>
+where
+    SC: StreamClosure<BlockSize = U16>,
+{
+    #[inline(always)]
+    fn call<B: BlockBackend<BlockSize = U16>>(self, backend: &mut B) {
+        let Self { s, f } = self;
+        f.call(&mut Backend::<B> { s, backend })
+    }
+}
diff --git a/belt-ctr/src/lib.rs b/belt-ctr/src/lib.rs
new file mode 100644
index 0000000..57dacc8
--- /dev/null
+++ b/belt-ctr/src/lib.rs
@@ -0,0 +1,112 @@
+#![no_std]
+#![doc = include_str!("../README.md")]
+#![doc(
+    html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg",
+    html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg"
+)]
+#![forbid(unsafe_code)]
+#![cfg_attr(docsrs, feature(doc_cfg))]
+#![warn(missing_docs, rust_2018_idioms)]
+
+pub use cipher;
+
+use belt_block::BeltBlock;
+use cipher::{
+    consts::U16, crypto_common::InnerUser, generic_array::GenericArray, BlockDecrypt, BlockEncrypt,
+    BlockSizeUser, InnerIvInit, Iv, IvSizeUser, IvState, StreamCipherCore, StreamCipherCoreWrapper,
+    StreamCipherSeekCore, StreamClosure,
+};
+
+mod backend;
+
+/// Byte-level BelT CTR
+pub type BeltCtr<C = BeltBlock> = StreamCipherCoreWrapper<BeltCtrCore<C>>;
+
+/// Block-level BelT CTR
+pub struct BeltCtrCore<C = BeltBlock>
+where
+    C: BlockEncrypt + BlockSizeUser<BlockSize = U16>,
+{
+    cipher: C,
+    s: u128,
+    s_init: u128,
+}
+
+impl<C> StreamCipherCore for BeltCtrCore<C>
+where
+    C: BlockEncrypt + BlockSizeUser<BlockSize = U16>,
+{
+    fn remaining_blocks(&self) -> Option<usize> {
+        let used = self.s.wrapping_sub(self.s_init);
+        (u128::MAX - used).try_into().ok()
+    }
+
+    fn process_with_backend(&mut self, f: impl StreamClosure<BlockSize = Self::BlockSize>) {
+        let Self { cipher, s, .. } = self;
+        cipher.encrypt_with_backend(backend::Closure { s, f });
+    }
+}
+
+impl<C> StreamCipherSeekCore for BeltCtrCore<C>
+where
+    C: BlockEncrypt + BlockSizeUser<BlockSize = U16>,
+{
+    type Counter = u128;
+
+    fn get_block_pos(&self) -> Self::Counter {
+        self.s.wrapping_sub(self.s_init)
+    }
+
+    fn set_block_pos(&mut self, pos: Self::Counter) {
+        self.s = self.s_init.wrapping_add(pos);
+    }
+}
+
+impl<C> BlockSizeUser for BeltCtrCore<C>
+where
+    C: BlockEncrypt + BlockSizeUser<BlockSize = U16>,
+{
+    type BlockSize = C::BlockSize;
+}
+
+impl<C> IvSizeUser for BeltCtrCore<C>
+where
+    C: BlockEncrypt + BlockSizeUser<BlockSize = U16>,
+{
+    type IvSize = C::BlockSize;
+}
+
+impl<C> InnerUser for BeltCtrCore<C>
+where
+    C: BlockEncrypt + BlockSizeUser<BlockSize = U16>,
+{
+    type Inner = C;
+}
+
+impl<C> InnerIvInit for BeltCtrCore<C>
+where
+    C: BlockEncrypt + BlockSizeUser<BlockSize = U16>,
+{
+    #[inline]
+    fn inner_iv_init(cipher: C, iv: &Iv<Self>) -> Self {
+        let mut t = GenericArray::default();
+        cipher.encrypt_block_b2b(iv, &mut t);
+        let s = u128::from_le_bytes(t.into());
+        Self {
+            cipher,
+            s,
+            s_init: s,
+        }
+    }
+}
+
+impl<C> IvState for BeltCtrCore<C>
+where
+    C: BlockEncrypt + BlockDecrypt + BlockSizeUser<BlockSize = U16>,
+{
+    fn iv_state(&self) -> Iv<Self> {
+        let mut t = self.s.to_le_bytes().into();
+        self.cipher.decrypt_block(&mut t);
+        t
+    }
+}


Test patch:
diff --git a/belt-ctr/tests/data/belt-ctr.blb b/belt-ctr/tests/data/belt-ctr.blb
new file mode 100644
index 0000000..259d79d
Binary files /dev/null and b/belt-ctr/tests/data/belt-ctr.blb differ
diff --git a/belt-ctr/tests/mod.rs b/belt-ctr/tests/mod.rs
new file mode 100644
index 0000000..2fe044d
--- /dev/null
+++ b/belt-ctr/tests/mod.rs
@@ -0,0 +1,7 @@
+use belt_ctr::{BeltCtr, BeltCtrCore};
+
+// Test vectors from the BelT standard (tables A.15 and A.16):
+// https://apmi.bsu.by/assets/files/std/belt-spec371.pdf
+cipher::stream_cipher_test!(belt_ctr_core, "belt-ctr", BeltCtr);
+cipher::stream_cipher_seek_test!(belt_ctr_seek, BeltCtr);
+cipher::iv_state_test!(belt_ctr_iv_state, BeltCtrCore, apply_ks);