diff options
author | Hubert Chathi <hubert@uhoreg.ca> | 2018-12-28 13:41:25 -0500 |
---|---|---|
committer | Hubert Chathi <hubert@uhoreg.ca> | 2018-12-28 13:41:25 -0500 |
commit | 17a989db6c4d42828f68afed20bafcb377c65cfb (patch) | |
tree | de29380ff1ecd0ad17e7134caab8c1054fbb9667 | |
parent | ded55f50536d852b544c7255551fc3b8c1e7b044 (diff) |
allow specifying the info parameter for the HKDF
-rw-r--r-- | include/olm/sas.h | 2 | ||||
-rw-r--r-- | javascript/olm_sas.js | 12 | ||||
-rw-r--r-- | javascript/test/sas.spec.js | 4 | ||||
-rw-r--r-- | src/sas.c | 6 | ||||
-rw-r--r-- | tests/test_sas.cpp | 8 |
5 files changed, 21 insertions, 11 deletions
diff --git a/include/olm/sas.h b/include/olm/sas.h index 688b587..480c3e1 100644 --- a/include/olm/sas.h +++ b/include/olm/sas.h @@ -62,6 +62,7 @@ size_t olm_sas_set_their_key( size_t olm_sas_generate_bytes( OlmSAS * sas, + const void * info, size_t info_length, void * output, size_t output_length ); @@ -72,6 +73,7 @@ size_t olm_sas_mac_length( size_t olm_sas_calculate_mac( OlmSAS * sas, void * input, size_t input_length, + const void * info, size_t info_length, void * mac, size_t mac_length ); diff --git a/javascript/olm_sas.js b/javascript/olm_sas.js index 8fc535b..d5044ce 100644 --- a/javascript/olm_sas.js +++ b/javascript/olm_sas.js @@ -42,10 +42,13 @@ SAS.prototype['set_their_key'] = restore_stack(function(their_key) { ); }); -SAS.prototype['generate_bytes'] = restore_stack(function(length) { +SAS.prototype['generate_bytes'] = restore_stack(function(info, length) { + var info_array = array_from_string(info); + var info_buffer = stack(info_array); var output_buffer = stack(length); sas_method(Module['_olm_sas_generate_bytes'])( this.ptr, + info_buffer, info_array.length, output_buffer, length ); // The inner Uint8Array creates a view of the buffer. The outer Uint8Array @@ -57,14 +60,17 @@ SAS.prototype['generate_bytes'] = restore_stack(function(length) { return output_arr; }); -SAS.prototype['calculate_mac'] = restore_stack(function(input) { +SAS.prototype['calculate_mac'] = restore_stack(function(input, info) { var input_array = array_from_string(input); - var input_buffer = stack(input_array) + var input_buffer = stack(input_array); + var info_array = array_from_string(info); + var info_buffer = stack(info_array); var mac_length = sas_method(Module['_olm_sas_mac_length'])(this.ptr); var mac_buffer = stack(mac_length + NULL_BYTE_PADDING_LENGTH); sas_method(Module['_olm_sas_calculate_mac'])( this.ptr, input_buffer, input_array.length, + info_buffer, info_array.length, mac_buffer, mac_length ); return Pointer_stringify(mac_buffer); diff --git a/javascript/test/sas.spec.js b/javascript/test/sas.spec.js index 544131d..af7ea65 100644 --- a/javascript/test/sas.spec.js +++ b/javascript/test/sas.spec.js @@ -42,12 +42,12 @@ describe("sas", function() { it('should create matching SAS bytes', function () { alice.set_their_key(bob.get_pubkey()); bob.set_their_key(alice.get_pubkey()); - expect(alice.generate_bytes(5).toString()).toEqual(bob.generate_bytes(5).toString()); + expect(alice.generate_bytes("SAS", 5).toString()).toEqual(bob.generate_bytes("SAS", 5).toString()); }); it('should create matching MACs', function () { alice.set_their_key(bob.get_pubkey()); bob.set_their_key(alice.get_pubkey()); - expect(alice.calculate_mac("test").toString()).toEqual(bob.calculate_mac("test").toString()); + expect(alice.calculate_mac("test", "MAC").toString()).toEqual(bob.calculate_mac("test", "MAC").toString()); }); }); @@ -100,12 +100,13 @@ size_t olm_sas_set_their_key( size_t olm_sas_generate_bytes( OlmSAS * sas, + const void * info, size_t info_length, void * output, size_t output_length ) { _olm_crypto_hkdf_sha256( sas->secret, sizeof(sas->secret), NULL, 0, - (const uint8_t *) "SAS", 3, + (const uint8_t *) info, info_length, output, output_length ); return 0; @@ -120,6 +121,7 @@ size_t olm_sas_mac_length( size_t olm_sas_calculate_mac( OlmSAS * sas, void * input, size_t input_length, + const void * info, size_t info_length, void * mac, size_t mac_length ) { if (mac_length < olm_sas_mac_length(sas)) { @@ -131,7 +133,7 @@ size_t olm_sas_calculate_mac( _olm_crypto_hkdf_sha256( sas->secret, sizeof(sas->secret), NULL, 0, - (const uint8_t *) "MAC", 3, + (const uint8_t *) info, info_length, key, 256 ); _olm_crypto_hmac_sha256(key, 256, input, input_length, mac); diff --git a/tests/test_sas.cpp b/tests/test_sas.cpp index bbb43d8..3578244 100644 --- a/tests/test_sas.cpp +++ b/tests/test_sas.cpp @@ -55,8 +55,8 @@ olm_sas_set_their_key(alice_sas, pubkey, olm_sas_pubkey_length(alice_sas)); std::uint8_t alice_bytes[6]; std::uint8_t bob_bytes[6]; -olm_sas_generate_bytes(alice_sas, alice_bytes, 6); -olm_sas_generate_bytes(bob_sas, bob_bytes, 6); +olm_sas_generate_bytes(alice_sas, "SAS", 3, alice_bytes, 6); +olm_sas_generate_bytes(bob_sas, "SAS", 3, bob_bytes, 6); assert_equals(alice_bytes, bob_bytes, 6); @@ -108,8 +108,8 @@ olm_sas_set_their_key(alice_sas, pubkey, olm_sas_pubkey_length(alice_sas)); std::uint8_t alice_mac[olm_sas_mac_length(alice_sas)]; std::uint8_t bob_mac[olm_sas_mac_length(bob_sas)]; -olm_sas_calculate_mac(alice_sas, (void *) "Hello world!", 12, alice_mac, olm_sas_mac_length(alice_sas)); -olm_sas_calculate_mac(bob_sas, (void *) "Hello world!", 12, bob_mac, olm_sas_mac_length(bob_sas)); +olm_sas_calculate_mac(alice_sas, (void *) "Hello world!", 12, "MAC", 3, alice_mac, olm_sas_mac_length(alice_sas)); +olm_sas_calculate_mac(bob_sas, (void *) "Hello world!", 12, "MAC", 3, bob_mac, olm_sas_mac_length(bob_sas)); assert_equals(alice_mac, bob_mac, olm_sas_mac_length(alice_sas)); |