• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

namib-project / dcaf-rs / 10516465139

22 Aug 2024 10:16PM UTC coverage: 85.144% (+0.2%) from 84.95%
10516465139

Pull #24

github

web-flow
Merge 0da044a44 into d087ba7ef
Pull Request #24: Add support for AES-CCM

2185 of 4715 branches covered (46.34%)

229 of 266 new or added lines in 16 files covered. (86.09%)

1 existing line in 1 file now uncovered.

3158 of 3709 relevant lines covered (85.14%)

48.86 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.62
/src/token/cose/crypto_impl/rustcrypto/encrypt/aes_ccm.rs
1
/*
2
 * Copyright (c) 2024 The NAMIB Project Developers.
3
 * Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4
 * https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5
 * <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
6
 * option. This file may not be copied, modified, or distributed
7
 * except according to those terms.
8
 *
9
 * SPDX-License-Identifier: MIT OR Apache-2.0
10
 */
11
use aes::{Aes128, Aes256};
12
use ccm::Ccm;
13
use coset::{iana, Algorithm};
14
use rand::CryptoRng;
15
use rand::RngCore;
16
use typenum::consts::{U13, U16, U7, U8};
17

18
use crate::error::CoseCipherError;
19
use crate::token::cose::{CoseSymmetricKey, CryptoBackend};
20

21
use super::RustCryptoContext;
22

23
impl<RNG: RngCore + CryptoRng> RustCryptoContext<RNG> {
24
    /// Perform an AES-CCM encryption operation on `plaintext` and the additional authenticated
25
    /// data `aad` using the given `iv` and `key` with the given `algorithm` variant of AES-GCM.
26
    pub(super) fn encrypt_aes_ccm(
17✔
27
        algorithm: iana::Algorithm,
28
        key: &CoseSymmetricKey<'_, <Self as CryptoBackend>::Error>,
29
        plaintext: &[u8],
30
        aad: &[u8],
31
        iv: &[u8],
32
    ) -> Result<Vec<u8>, CoseCipherError<<Self as CryptoBackend>::Error>> {
33
        match algorithm {
17!
34
            iana::Algorithm::AES_CCM_16_64_128 => {
35
                Self::encrypt_aead::<Ccm<Aes128, U8, U13>>(key, plaintext, aad, iv)
3✔
36
            }
37
            iana::Algorithm::AES_CCM_16_64_256 => {
38
                Self::encrypt_aead::<Ccm<Aes256, U8, U13>>(key, plaintext, aad, iv)
2✔
39
            }
40
            iana::Algorithm::AES_CCM_64_64_128 => {
41
                Self::encrypt_aead::<Ccm<Aes128, U8, U7>>(key, plaintext, aad, iv)
2✔
42
            }
43
            iana::Algorithm::AES_CCM_64_64_256 => {
44
                Self::encrypt_aead::<Ccm<Aes256, U8, U7>>(key, plaintext, aad, iv)
2✔
45
            }
46
            iana::Algorithm::AES_CCM_16_128_128 => {
47
                Self::encrypt_aead::<Ccm<Aes128, U16, U13>>(key, plaintext, aad, iv)
2✔
48
            }
49
            iana::Algorithm::AES_CCM_16_128_256 => {
50
                Self::encrypt_aead::<Ccm<Aes256, U16, U13>>(key, plaintext, aad, iv)
2✔
51
            }
52
            iana::Algorithm::AES_CCM_64_128_128 => {
53
                Self::encrypt_aead::<Ccm<Aes128, U16, U7>>(key, plaintext, aad, iv)
2✔
54
            }
55
            iana::Algorithm::AES_CCM_64_128_256 => {
56
                Self::encrypt_aead::<Ccm<Aes256, U16, U7>>(key, plaintext, aad, iv)
2✔
57
            }
NEW
58
            a => Err(CoseCipherError::UnsupportedAlgorithm(Algorithm::Assigned(
×
59
                a,
NEW
60
            ))),
×
61
        }
62
    }
17✔
63

64
    /// Perform an AES-CCM decryption operation on `ciphertext` and the additional authenticated
65
    /// data `aad` using the given `iv` and `key` with the given `algorithm` variant of AES-GCM.
66
    pub(super) fn decrypt_aes_ccm(
33✔
67
        algorithm: iana::Algorithm,
68
        key: &CoseSymmetricKey<'_, <Self as CryptoBackend>::Error>,
69
        ciphertext_with_tag: &[u8],
70
        aad: &[u8],
71
        iv: &[u8],
72
    ) -> Result<Vec<u8>, CoseCipherError<<Self as CryptoBackend>::Error>> {
73
        match algorithm {
33!
74
            iana::Algorithm::AES_CCM_16_64_128 => {
75
                Self::decrypt_aead::<Ccm<Aes128, U8, U13>>(key, ciphertext_with_tag, aad, iv)
5✔
76
            }
77
            iana::Algorithm::AES_CCM_16_64_256 => {
78
                Self::decrypt_aead::<Ccm<Aes256, U8, U13>>(key, ciphertext_with_tag, aad, iv)
4✔
79
            }
80
            iana::Algorithm::AES_CCM_64_64_128 => {
81
                Self::decrypt_aead::<Ccm<Aes128, U8, U7>>(key, ciphertext_with_tag, aad, iv)
4✔
82
            }
83
            iana::Algorithm::AES_CCM_64_64_256 => {
84
                Self::decrypt_aead::<Ccm<Aes256, U8, U7>>(key, ciphertext_with_tag, aad, iv)
4✔
85
            }
86
            iana::Algorithm::AES_CCM_16_128_128 => {
87
                Self::decrypt_aead::<Ccm<Aes128, U16, U13>>(key, ciphertext_with_tag, aad, iv)
4✔
88
            }
89
            iana::Algorithm::AES_CCM_16_128_256 => {
90
                Self::decrypt_aead::<Ccm<Aes256, U16, U13>>(key, ciphertext_with_tag, aad, iv)
4✔
91
            }
92
            iana::Algorithm::AES_CCM_64_128_128 => {
93
                Self::decrypt_aead::<Ccm<Aes128, U16, U7>>(key, ciphertext_with_tag, aad, iv)
4✔
94
            }
95
            iana::Algorithm::AES_CCM_64_128_256 => {
96
                Self::decrypt_aead::<Ccm<Aes256, U16, U7>>(key, ciphertext_with_tag, aad, iv)
4✔
97
            }
NEW
98
            a => Err(CoseCipherError::UnsupportedAlgorithm(Algorithm::Assigned(
×
99
                a,
NEW
100
            ))),
×
101
        }
102
    }
33✔
103
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc