|
@ -1478,7 +1478,7 @@ int enc_init(const char *pass, const char *method) |
|
|
return m; |
|
|
return m; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int ss_check_hash(char **buf_ptr, ssize_t *buf_len, struct chunk *chunk, int buf_size) |
|
|
|
|
|
|
|
|
int ss_check_hash(char **buf_ptr, ssize_t *buf_len, struct chunk *chunk, struct enc_ctx *ctx, int buf_size) |
|
|
{ |
|
|
{ |
|
|
int i, j, k; |
|
|
int i, j, k; |
|
|
char *buf = *buf_ptr; |
|
|
char *buf = *buf_ptr; |
|
@ -1511,12 +1511,12 @@ int ss_check_hash(char **buf_ptr, ssize_t *buf_len, struct chunk *chunk, int buf |
|
|
if (cidx == chunk->len + AUTH_BYTES) { |
|
|
if (cidx == chunk->len + AUTH_BYTES) { |
|
|
// Compare hash |
|
|
// Compare hash |
|
|
uint8_t *hash = (uint8_t *)malloc(chunk->len); |
|
|
uint8_t *hash = (uint8_t *)malloc(chunk->len); |
|
|
uint8_t key[MAX_KEY_LENGTH + sizeof(uint32_t)]; |
|
|
|
|
|
|
|
|
uint8_t key[MAX_IV_LENGTH + sizeof(uint32_t)]; |
|
|
|
|
|
|
|
|
memcpy(key, enc_key, enc_key_len); |
|
|
|
|
|
memcpy(key + enc_key_len, &chunk->counter, sizeof(uint32_t)); |
|
|
|
|
|
|
|
|
memcpy(key, ctx->evp.iv, enc_key_len); |
|
|
|
|
|
memcpy(key + enc_iv_len, &chunk->counter, sizeof(uint32_t)); |
|
|
crypto_generichash(hash, HASH_BYTES, (uint8_t *)chunk->buf + AUTH_BYTES, chunk->len, |
|
|
crypto_generichash(hash, HASH_BYTES, (uint8_t *)chunk->buf + AUTH_BYTES, chunk->len, |
|
|
key, enc_key_len + sizeof(uint32_t)); |
|
|
|
|
|
|
|
|
key, enc_iv_len + sizeof(uint32_t)); |
|
|
|
|
|
|
|
|
if (memcmp(hash, chunk->buf + CLEN_BYTES, HASH_BYTES) != 0) return 0; |
|
|
if (memcmp(hash, chunk->buf + CLEN_BYTES, HASH_BYTES) != 0) return 0; |
|
|
|
|
|
|
|
@ -1538,7 +1538,7 @@ int ss_check_hash(char **buf_ptr, ssize_t *buf_len, struct chunk *chunk, int buf |
|
|
return 1; |
|
|
return 1; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
char *ss_gen_hash(char *buf, ssize_t *buf_len, uint32_t *counter, int buf_size) |
|
|
|
|
|
|
|
|
char *ss_gen_hash(char *buf, ssize_t *buf_len, uint32_t *counter, struct enc_ctx *ctx, int buf_size) |
|
|
{ |
|
|
{ |
|
|
ssize_t blen = *buf_len; |
|
|
ssize_t blen = *buf_len; |
|
|
int size = max(AUTH_BYTES + blen, buf_size); |
|
|
int size = max(AUTH_BYTES + blen, buf_size); |
|
@ -1549,11 +1549,11 @@ char *ss_gen_hash(char *buf, ssize_t *buf_len, uint32_t *counter, int buf_size) |
|
|
|
|
|
|
|
|
uint16_t chunk_len = htons((uint16_t)blen); |
|
|
uint16_t chunk_len = htons((uint16_t)blen); |
|
|
uint8_t hash[HASH_BYTES]; |
|
|
uint8_t hash[HASH_BYTES]; |
|
|
uint8_t key[MAX_KEY_LENGTH + sizeof(uint32_t)]; |
|
|
|
|
|
|
|
|
uint8_t key[MAX_IV_LENGTH + sizeof(uint32_t)]; |
|
|
|
|
|
|
|
|
memcpy(key, enc_key, enc_key_len); |
|
|
|
|
|
memcpy(key + enc_key_len, counter, sizeof(uint32_t)); |
|
|
|
|
|
crypto_generichash(hash, HASH_BYTES, (uint8_t *)buf, blen, key, enc_key_len + sizeof(uint32_t)); |
|
|
|
|
|
|
|
|
memcpy(key, ctx->evp.iv, enc_iv_len); |
|
|
|
|
|
memcpy(key + enc_iv_len, counter, sizeof(uint32_t)); |
|
|
|
|
|
crypto_generichash(hash, HASH_BYTES, (uint8_t *)buf, blen, key, enc_iv_len + sizeof(uint32_t)); |
|
|
|
|
|
|
|
|
memmove(buf + AUTH_BYTES, buf, blen); |
|
|
memmove(buf + AUTH_BYTES, buf, blen); |
|
|
memcpy(buf + CLEN_BYTES, hash, HASH_BYTES); |
|
|
memcpy(buf + CLEN_BYTES, hash, HASH_BYTES); |
|
|