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

AES-CCM with Tag Length of 16 bytes fails #1593

Open
kedars opened this issue Jan 16, 2022 · 0 comments
Open

AES-CCM with Tag Length of 16 bytes fails #1593

kedars opened this issue Jan 16, 2022 · 0 comments

Comments

@kedars
Copy link

kedars commented Jan 16, 2022

Specifically, the {encrypt, decrypt}_aead function returns TLS stack error.

The following is a test code from test case 225 of NIST Test Vectors:

    #[test]
    fn test_aes128_ccm_tag16() {
        // Test case 225 from
        // https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Algorithm-Validation-Program/documents/mac/ccmtestvectors.zip
        let key = "26511fb51fcfa75cb4b44da75a6e5a0e";
        let nonce = "5a8aa485c316e9403aff859fbb";
        let aad = "a16a2e741f1cd9717285b6d882c1fc53655e9773761ad697a7ee6410184c7982";

        let pt = "8739b4bea1a099fe547499cbc6d1b13d849b8084c9b6acc5";
        let ct = "50038b5fdd364ee747b70d00bd36840ece4ea19998123375";
        let tag = "c0a458bfcafa3b2609afe0f825cbf503";

        let mut actual_tag = [0; 16];
        let out = encrypt_aead(
            Cipher::aes_128_ccm(),
            &Vec::from_hex(key).unwrap(),
            Some(&Vec::from_hex(nonce).unwrap()),
            &Vec::from_hex(aad).unwrap(),
            &Vec::from_hex(pt).unwrap(),
            &mut actual_tag,
        )
        .unwrap();

        assert_eq!(ct, hex::encode(out));
        assert_eq!(tag, hex::encode(actual_tag));

        let out = decrypt_aead(
            Cipher::aes_128_ccm(),
            &Vec::from_hex(key).unwrap(),
            Some(&Vec::from_hex(nonce).unwrap()),
            &Vec::from_hex(aad).unwrap(),
            &Vec::from_hex(ct).unwrap(),
            &Vec::from_hex(tag).unwrap(),
        )
        .unwrap();
        assert_eq!(pt, hex::encode(out));
    }
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

1 participant