Skip to content
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

deprecate use of GenericArray #126

Open
lthiery opened this issue Sep 11, 2023 · 2 comments
Open

deprecate use of GenericArray #126

lthiery opened this issue Sep 11, 2023 · 2 comments

Comments

@lthiery
Copy link
Collaborator

lthiery commented Sep 11, 2023

With const generics, it should be possible now. I think we use GenericArray because it impls Default though. I'm not sure what we need to use instead @lulf

eg:

let mut phy: DataPayloadCreator<[u8; 255], C> = DataPayloadCreator::default();
    |                                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `core::default::Default` is not implemented for `[u8; 255]`
@plaes
Copy link
Collaborator

plaes commented Sep 18, 2024

Firstly, GenericArray dependency is used both in our code and our dependencies, whenever default-crypto is used.

Our unconditional usage

Internal re-export usage

  • EncryptedJoinAcceptPayload.decrypt(...):

    let block = GenericArray::from_mut_slice(&mut bytes[start..(start + 16)]);
    aes_enc.encrypt_block(block);

  • Encrypter, Decrypter and Keys traits:

    pub trait Encrypter {
    fn encrypt_block(&self, block: &mut GenericArray<u8, U16>);
    }
    /// Trait for implementations of AES128 decryption.
    pub trait Decrypter {
    fn decrypt_block(&self, block: &mut GenericArray<u8, U16>);
    }
    /// Trait for implementations of CMAC.
    pub trait Mac {
    fn input(&mut self, data: &[u8]);
    fn reset(&mut self);
    fn result(self) -> GenericArray<u8, U16>;
    }

Use by dependencies

Regarding dependencies, RustCrypto (from where our aes and cmac implementations are coming from) is trying to get rid of GenericArray dependency as well in favor of const generics - RustCrypto/traits#1481

As an interim step they have introduced a hybrid_array crate and have ported latest release candidate version to use it instead of GenericArray.
Relevant PRs:

@plaes
Copy link
Collaborator

plaes commented Sep 18, 2024

I have a quick and dirty (with only minimal changes to get it to build) branch here that uses the pre-release crates: https://github.com/plaes/lora-rs/tree/hybrid-array

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

No branches or pull requests

2 participants