summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cypher.cpp3
-rw-r--r--keyDerivation.cpp28
-rw-r--r--keyDerivation.h7
3 files changed, 19 insertions, 19 deletions
diff --git a/cypher.cpp b/cypher.cpp
index ad590fa..0e48ae7 100644
--- a/cypher.cpp
+++ b/cypher.cpp
@@ -72,7 +72,8 @@ void AesIcmCypher::cypher(Buffer& buf, seq_nr_t seq_nr, sender_id_t sender_id)
uint8_t key[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
- 0x10, 0x11, 0x12, 0x13
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d
};
v128_t iv;
diff --git a/keyDerivation.cpp b/keyDerivation.cpp
index 5663ac1..d6b1ca3 100644
--- a/keyDerivation.cpp
+++ b/keyDerivation.cpp
@@ -37,11 +37,18 @@ extern "C" {
err_status_t KeyDerivation::init(const uint8_t key[30], const uint8_t salt[14])
{
- aes_icm_context_init(&kdf_, key);
+ extern cipher_type_t aes_icm;
+ err_status_t status = err_status_ok;
for(uint8_t i = 0; i < 14; i++)
salt_[i] = salt[i];
+ // allocate cipher
+ status = cipher_type_alloc(&aes_icm, &cipher_, 30);
+
+ // init cipher
+ status = cipher_init(cipher_, key, direction_any);
+
return err_status_ok;
}
@@ -56,8 +63,9 @@ err_status_t KeyDerivation::setLogKDRate(const uint8_t log_rate)
}
-err_status_t KeyDerivation::generate(satp_prf_label label, seq_nr_t seq_nr, uint8_t *key, int length)
+err_status_t KeyDerivation::generate(satp_prf_label label, seq_nr_t seq_nr, uint8_t *key, uint32_t length)
{
+ err_status_t status = err_status_ok;
v128_t iv, salt, key_id;
uint8_t r = 0;
@@ -78,10 +86,10 @@ err_status_t KeyDerivation::generate(satp_prf_label label, seq_nr_t seq_nr, uint
v128_copy_octet_string(&salt, salt_);
v128_xor(&iv, &salt, &key_id);
- aes_icm_set_iv(&kdf_, &iv);
+ status = cipher_set_iv(cipher_, &iv);
/* generate keystream output */
- aes_icm_output(&kdf_, key, length);
+ status = cipher_output(cipher_, key, length);
return err_status_ok;
}
@@ -89,17 +97,7 @@ err_status_t KeyDerivation::generate(satp_prf_label label, seq_nr_t seq_nr, uint
err_status_t KeyDerivation::clear()
{
- /* zeroize aes context */
-
- v128_set_to_zero(&kdf_.counter);
- v128_set_to_zero(&kdf_.offset);
- v128_set_to_zero(&kdf_.keystream_buffer);
- for(uint8_t i = 0; i < 11; i++)
- {
- v128_set_to_zero(&kdf_.expanded_key[i]);
- }
- kdf_.bytes_in_buffer = 0;
-
+ cipher_dealloc(cipher_);
return err_status_ok;
}
diff --git a/keyDerivation.h b/keyDerivation.h
index a625342..9033d30 100644
--- a/keyDerivation.h
+++ b/keyDerivation.h
@@ -49,18 +49,19 @@ typedef enum {
class KeyDerivation
{
public:
- KeyDerivation() : ld_kdr_(-1) {};
+ KeyDerivation() : ld_kdr_(-1), cipher_(NULL) {};
virtual ~KeyDerivation() {};
err_status_t init(const uint8_t key[30], const uint8_t salt[14]);
err_status_t setLogKDRate(const uint8_t ld_rate);
- err_status_t generate(satp_prf_label label, seq_nr_t seq_nr, uint8_t *key, int length);
+ err_status_t generate(satp_prf_label label, seq_nr_t seq_nr, uint8_t *key, uint32_t length);
err_status_t clear();
protected:
- aes_icm_ctx_t kdf_;
int8_t ld_kdr_; // ld(key_derivation_rate)
uint8_t salt_[14];
+
+ cipher_t* cipher_;
};
#endif