summaryrefslogtreecommitdiff
path: root/libs/libaxolotl/src/hkdf.c
diff options
context:
space:
mode:
Diffstat (limited to 'libs/libaxolotl/src/hkdf.c')
-rw-r--r--libs/libaxolotl/src/hkdf.c70
1 files changed, 35 insertions, 35 deletions
diff --git a/libs/libaxolotl/src/hkdf.c b/libs/libaxolotl/src/hkdf.c
index 63b35ddaa4..d8df253c8b 100644
--- a/libs/libaxolotl/src/hkdf.c
+++ b/libs/libaxolotl/src/hkdf.c
@@ -6,7 +6,7 @@
#include <math.h>
#include <assert.h>
-#include "axolotl_internal.h"
+#include "signal_protocol_internal.h"
#define HASH_OUTPUT_SIZE 32
@@ -15,22 +15,22 @@
struct hkdf_context
{
- axolotl_type_base base;
- axolotl_context *global_context;
+ signal_type_base base;
+ signal_context *global_context;
int iteration_start_offset;
};
-int hkdf_create(hkdf_context **context, int message_version, axolotl_context *global_context)
+int hkdf_create(hkdf_context **context, int message_version, signal_context *global_context)
{
assert(global_context);
*context = malloc(sizeof(hkdf_context));
if(!(*context)) {
- return AX_ERR_NOMEM;
+ return SG_ERR_NOMEM;
}
memset(*context, 0, sizeof(hkdf_context));
- AXOLOTL_INIT(*context, hkdf_destroy);
+ SIGNAL_INIT(*context, hkdf_destroy);
(*context)->global_context = global_context;
if(message_version == 2) {
@@ -41,7 +41,7 @@ int hkdf_create(hkdf_context **context, int message_version, axolotl_context *gl
}
else {
free(*context);
- return AX_ERR_INVAL;
+ return SG_ERR_INVAL;
}
return 0;
@@ -53,43 +53,43 @@ ssize_t hkdf_extract(hkdf_context *context,
const uint8_t *input_key_material, size_t input_key_material_len)
{
int result = 0;
- axolotl_buffer *mac_buffer = 0;
+ signal_buffer *mac_buffer = 0;
uint8_t *mac = 0;
size_t mac_len = 0;
void *hmac_context;
assert(context);
- result = axolotl_hmac_sha256_init(context->global_context,
+ result = signal_hmac_sha256_init(context->global_context,
&hmac_context, salt, salt_len);
if(result < 0) {
goto complete;
}
- result = axolotl_hmac_sha256_update(context->global_context,
+ result = signal_hmac_sha256_update(context->global_context,
hmac_context, input_key_material, input_key_material_len);
if(result < 0) {
goto complete;
}
- result = axolotl_hmac_sha256_final(context->global_context,
+ result = signal_hmac_sha256_final(context->global_context,
hmac_context, &mac_buffer);
if(result < 0) {
goto complete;
}
- mac_len = axolotl_buffer_len(mac_buffer);
+ mac_len = signal_buffer_len(mac_buffer);
mac = malloc(mac_len);
if(!mac) {
- result = AX_ERR_NOMEM;
+ result = SG_ERR_NOMEM;
goto complete;
}
- memcpy(mac, axolotl_buffer_data(mac_buffer), mac_len);
+ memcpy(mac, signal_buffer_data(mac_buffer), mac_len);
complete:
- axolotl_hmac_sha256_cleanup(context->global_context, hmac_context);
- axolotl_buffer_free(mac_buffer);
+ signal_hmac_sha256_cleanup(context->global_context, hmac_context);
+ signal_buffer_free(mac_buffer);
if(result >= 0) {
*output = mac;
@@ -108,7 +108,7 @@ ssize_t hkdf_expand(hkdf_context *context,
{
int iterations = (int)ceil((double)output_len / (double)HASH_OUTPUT_SIZE);
size_t remaining_len = output_len;
- axolotl_buffer *step_buffer = 0;
+ signal_buffer *step_buffer = 0;
size_t step_size = 0;
uint8_t *result_buf = 0;
size_t result_buf_len = 0;
@@ -119,66 +119,66 @@ ssize_t hkdf_expand(hkdf_context *context,
assert(context);
for(i = context->iteration_start_offset; i < iterations + context->iteration_start_offset; i++) {
- result = axolotl_hmac_sha256_init(context->global_context,
+ result = signal_hmac_sha256_init(context->global_context,
&hmac_context, prk, prk_len);
if(result < 0) {
goto complete;
}
if(step_buffer) {
- result = axolotl_hmac_sha256_update(context->global_context,
+ result = signal_hmac_sha256_update(context->global_context,
hmac_context,
- axolotl_buffer_data(step_buffer),
- axolotl_buffer_len(step_buffer));
+ signal_buffer_data(step_buffer),
+ signal_buffer_len(step_buffer));
if(result < 0) {
goto complete;
}
- axolotl_buffer_free(step_buffer);
+ signal_buffer_free(step_buffer);
step_buffer = 0;
}
if(info) {
- result = axolotl_hmac_sha256_update(context->global_context,
+ result = signal_hmac_sha256_update(context->global_context,
hmac_context, info, info_len);
if(result < 0) {
goto complete;
}
}
- result = axolotl_hmac_sha256_update(context->global_context,
+ result = signal_hmac_sha256_update(context->global_context,
hmac_context, &i, sizeof(uint8_t));
if(result < 0) {
goto complete;
}
- result = axolotl_hmac_sha256_final(context->global_context,
+ result = signal_hmac_sha256_final(context->global_context,
hmac_context, &step_buffer);
if(result < 0) {
goto complete;
}
- axolotl_hmac_sha256_cleanup(context->global_context, hmac_context);
+ signal_hmac_sha256_cleanup(context->global_context, hmac_context);
hmac_context = 0;
- step_size = MIN(remaining_len, axolotl_buffer_len(step_buffer));
+ step_size = MIN(remaining_len, signal_buffer_len(step_buffer));
if(!result_buf) {
result_buf = malloc(step_size);
if(!result_buf) {
- result = AX_ERR_NOMEM;
+ result = SG_ERR_NOMEM;
goto complete;
}
- memcpy(result_buf, axolotl_buffer_data(step_buffer), step_size);
+ memcpy(result_buf, signal_buffer_data(step_buffer), step_size);
result_buf_len = step_size;
}
else {
uint8_t *tmp_buf = realloc(result_buf, result_buf_len + step_size);
if(!tmp_buf) {
- result = AX_ERR_NOMEM;
+ result = SG_ERR_NOMEM;
goto complete;
}
result_buf = tmp_buf;
- memcpy(result_buf + result_buf_len, axolotl_buffer_data(step_buffer), step_size);
+ memcpy(result_buf + result_buf_len, signal_buffer_data(step_buffer), step_size);
result_buf_len += step_size;
}
remaining_len -= step_size;
@@ -186,9 +186,9 @@ ssize_t hkdf_expand(hkdf_context *context,
complete:
if(hmac_context) {
- axolotl_hmac_sha256_cleanup(context->global_context, hmac_context);
+ signal_hmac_sha256_cleanup(context->global_context, hmac_context);
}
- axolotl_buffer_free(step_buffer);
+ signal_buffer_free(step_buffer);
if(result < 0) {
free(result_buf);
return result;
@@ -214,7 +214,7 @@ ssize_t hkdf_derive_secrets(hkdf_context *context,
prk_len = hkdf_extract(context, &prk, salt, salt_len, input_key_material, input_key_material_len);
if(prk_len < 0) {
- axolotl_log(context->global_context, AX_LOG_ERROR, "hkdf_extract error: %d", prk_len);
+ signal_log(context->global_context, SG_LOG_ERROR, "hkdf_extract error: %d", prk_len);
return prk_len;
}
@@ -249,7 +249,7 @@ int hkdf_compare(const hkdf_context *context1, const hkdf_context *context2)
}
}
-void hkdf_destroy(axolotl_type_base *type)
+void hkdf_destroy(signal_type_base *type)
{
hkdf_context *context = (hkdf_context *)type;
free(context);