mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-02-21 09:51:50 +00:00
Ensure encryption buffer doesn't move between nonce and cypher text allocation
This commit is contained in:
parent
48f7cd7d5d
commit
af584994a2
@ -147,7 +147,7 @@ int ob_makespace(struct overlay_buffer *b,int bytes)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// already enough space?
|
// already enough space?
|
||||||
if (b->position + bytes < b->allocSize)
|
if (b->position + bytes <= b->allocSize)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (b->bytes && !b->allocated)
|
if (b->bytes && !b->allocated)
|
||||||
|
@ -327,8 +327,13 @@ int overlay_mdp_decrypt(struct overlay_frame *f, overlay_mdp_frame *mdp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
unsigned char *nonce=ob_get_bytes_ptr(f->payload, nb);
|
unsigned char *nonce=ob_get_bytes_ptr(f->payload, nb);
|
||||||
|
if (!nonce)
|
||||||
|
RETURN(WHYF("Expected %d bytes of nonce", nb));
|
||||||
|
|
||||||
int cipher_len=ob_remaining(f->payload);
|
int cipher_len=ob_remaining(f->payload);
|
||||||
unsigned char *cipher_text=ob_get_bytes_ptr(f->payload, cipher_len);
|
unsigned char *cipher_text=ob_get_bytes_ptr(f->payload, cipher_len);
|
||||||
|
if (!cipher_text)
|
||||||
|
RETURN(WHYF("Expected %d bytes of cipher text", cipher_len));
|
||||||
|
|
||||||
unsigned char plain_block[cipher_len+cz];
|
unsigned char plain_block[cipher_len+cz];
|
||||||
|
|
||||||
@ -680,9 +685,9 @@ int overlay_mdp_dispatch(overlay_mdp_frame *mdp,int userGeneratedFrameP,
|
|||||||
ob_free(plaintext);
|
ob_free(plaintext);
|
||||||
|
|
||||||
frame->payload = ob_new();
|
frame->payload = ob_new();
|
||||||
ob_makespace(frame->payload, nb+cipher_len);
|
|
||||||
|
|
||||||
unsigned char *nonce = ob_append_space(frame->payload, nb);
|
unsigned char *nonce = ob_append_space(frame->payload, nb+cipher_len);
|
||||||
|
unsigned char *cipher_text = nonce + nb;
|
||||||
if (!nonce)
|
if (!nonce)
|
||||||
RETURN(-1);
|
RETURN(-1);
|
||||||
if (urandombytes(nonce,nb)) {
|
if (urandombytes(nonce,nb)) {
|
||||||
@ -699,12 +704,6 @@ int overlay_mdp_dispatch(overlay_mdp_frame *mdp,int userGeneratedFrameP,
|
|||||||
op_free(frame);
|
op_free(frame);
|
||||||
RETURN(WHY("could not compute Curve25519(NxM)"));
|
RETURN(WHY("could not compute Curve25519(NxM)"));
|
||||||
}
|
}
|
||||||
/* Get pointer to place in frame where the ciphered text needs to go */
|
|
||||||
unsigned char *cipher_text=ob_append_space(frame->payload,cipher_len);
|
|
||||||
if ((!cipher_text)){
|
|
||||||
op_free(frame);
|
|
||||||
RETURN(WHY("could not make space for ciphered text"));
|
|
||||||
}
|
|
||||||
/* Actually authcrypt the payload */
|
/* Actually authcrypt the payload */
|
||||||
if (crypto_box_curve25519xsalsa20poly1305_afternm
|
if (crypto_box_curve25519xsalsa20poly1305_afternm
|
||||||
(cipher_text,plain,cipher_len,nonce,k)){
|
(cipher_text,plain,cipher_len,nonce,k)){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user