Skip to content

Implement belt dwp #604

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 30 commits into from
Mar 29, 2025
Merged

Implement belt dwp #604

merged 30 commits into from
Mar 29, 2025

Conversation

makavity
Copy link
Contributor

Implemented Belt-DWP, republic of Belarus AEAD algorithm.

@makavity
Copy link
Contributor Author

makavity commented Mar 4, 2025

Hey, @newpavlov!
Could you check it, please? :)

@baloo
Copy link
Member

baloo commented Mar 5, 2025

This could use a rebase.

@makavity
Copy link
Contributor Author

makavity commented Mar 5, 2025

Looks like benches is broken in master

Copy link
Member

@newpavlov newpavlov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late review!

use hex_literal::hex;

type BeltDwp = belt_dwp::BeltDwp<BeltBlock>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, just use BeltDwp with the default type parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

   Compiling belt-dwp v0.1.0 (/Users/makavity/dev/crypto/AEADs/belt-dwp)
error[E0283]: type annotations needed for `BeltDwp<_>`
   --> belt-dwp/tests/belt.rs:39:13
    |
39  |         let belt_dwp = BeltDwp::new_from_slice(&vec.k).unwrap();
    |             ^^^^^^^^   ------- type must be known at this point
    |
    = note: cannot satisfy `_: cipher::block::BlockCipherEncrypt`
    = help: the following types implement trait `cipher::block::BlockCipherEncrypt`:
              &Alg
              BeltBlock
              cipher::tweak::zero::ZeroTweak<C>
note: required by a bound in `BeltDwp`
   --> /Users/makavity/dev/crypto/AEADs/belt-dwp/src/lib.rs:106:8
    |
104 | pub struct BeltDwp<C = BeltBlock>
    |            ------- required by a bound in this struct
105 | where
106 |     C: BlockCipherEncrypt + BlockSizeUser<BlockSize = U16>,
    |        ^^^^^^^^^^^^^^^^^^ required by this bound in `BeltDwp`
help: consider giving `belt_dwp` an explicit type, where the type for type parameter `C` is specified
    |
39  |         let belt_dwp: BeltDwp<C> = BeltDwp::new_from_slice(&vec.k).unwrap();
    |                     ++++++++++++

For more information about this error, try `rustc --explain E0283`.
error: could not compile `belt-dwp` (test "belt") due to 1 previous error

Should I use

let dwp: BeltDwp = BeltDwp::new_from_slice(&vec.k).unwrap();

?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh... weird. I guess one way to work around this issue is to write this:

pub struct Dwp<C> {
    cipher: C,
}

pub type BeltDwp = Dwp<BeltBlock>;

Though I am interested in learning why the default type parameter does not work here as expected.

Copy link
Contributor Author

@makavity makavity Mar 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same problem is also in belt-ctr crate. Should I commit same fix for that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's probably worth to define a generic Ctr type and BeltCtr = Ctr<BeltBlock> type alias on top of it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, thank you.
Fixed generic default by type alias, as you suggest.

@newpavlov
Copy link
Member

Thank you!

@newpavlov newpavlov merged commit e70cca0 into RustCrypto:master Mar 29, 2025
118 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants