summaryrefslogtreecommitdiff
path: root/cypher.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cypher.cpp')
-rw-r--r--cypher.cpp25
1 files changed, 9 insertions, 16 deletions
diff --git a/cypher.cpp b/cypher.cpp
index 76a7d92..c77f883 100644
--- a/cypher.cpp
+++ b/cypher.cpp
@@ -31,8 +31,6 @@
#include <stdexcept>
#include <vector>
-//#include "datatypes.h"
-
#include "cypher.h"
extern "C" {
@@ -63,17 +61,15 @@ Buffer NullCypher::getBitStream(u_int32_t length, seq_nr_t seq_nr, sender_id_t s
return buf;
}
-void AesIcmCypher::cypher(Buffer& buf, seq_nr_t seq_nr, sender_id_t sender_id)
-{
-}
-Buffer AesIcmCypher::getBitStream(u_int32_t length, seq_nr_t seq_nr, sender_id_t sender_id)
+void AesIcmCypher::cypher(Buffer& buf, seq_nr_t seq_nr, sender_id_t sender_id)
{
- Buffer buf(length);
extern cipher_type_t aes_icm;
- err_status_t status;
+ err_status_t status = err_status_ok;
cipher_t* cipher = NULL;
- uint8_t key[20] = {
+ uint32_t length = 0;
+
+ uint8_t key[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13
@@ -84,13 +80,9 @@ Buffer AesIcmCypher::getBitStream(u_int32_t length, seq_nr_t seq_nr, sender_id_t
// allocate cipher
status = cipher_type_alloc(&aes_icm, &cipher, 30);
- if(status)
- return buf;
// init cipher
status = cipher_init(cipher, key, direction_any);
- if(status)
- return buf;
//set iv
// where the 128-bit integer value IV SHALL be defined by the SSRC, the
@@ -100,17 +92,18 @@ Buffer AesIcmCypher::getBitStream(u_int32_t length, seq_nr_t seq_nr, sender_id_t
// sizeof(k_s) = 112, random
-
iv.v32[0] ^= 0;
iv.v32[1] ^= sender_id;
iv.v32[2] ^= (seq_nr >> 16);
iv.v32[3] ^= (seq_nr << 16);
+
status = cipher_set_iv(cipher, &iv);
+
+ length = buf.getLength();
- status = cipher_output(cipher, buf, length);
+ status = cipher_encrypt(cipher, buf, &length);
status = cipher_dealloc(cipher);
- return buf;
}