Skip to content

Commit

Permalink
update wolfssl to support not-in-place io
Browse files Browse the repository at this point in the history
  • Loading branch information
pabuhler committed May 5, 2024
1 parent 8b50c31 commit 1a414fc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
31 changes: 18 additions & 13 deletions crypto/cipher/aes_gcm_wssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,10 @@ static srtp_err_status_t srtp_aes_gcm_wolfssl_set_aad(void *cv,
* enc_len length of encrypt buffer
*/
static srtp_err_status_t srtp_aes_gcm_wolfssl_encrypt(void *cv,
unsigned char *buf,
size_t *enc_len)
const uint8_t *src,
size_t src_len,
uint8_t *dst,
size_t *dst_len)
{
FUNC_ENTRY();
srtp_aes_gcm_ctx_t *c = (srtp_aes_gcm_ctx_t *)cv;
Expand All @@ -333,17 +335,18 @@ static srtp_err_status_t srtp_aes_gcm_wolfssl_encrypt(void *cv,
}

#ifndef WOLFSSL_AESGCM_STREAM
err = wc_AesGcmEncrypt(c->ctx, buf, buf, *enc_len, c->iv, c->iv_len, c->tag,
err = wc_AesGcmEncrypt(c->ctx, dst, src, src_len, c->iv, c->iv_len, c->tag,
c->tag_len, c->aad, c->aad_size);

c->aad_size = 0;
#else
err = wc_AesGcmEncryptUpdate(c->ctx, buf, buf, *enc_len, NULL, 0);
err = wc_AesGcmEncryptUpdate(c->ctx, dst, src, src_len, NULL, 0);
#endif
if (err < 0) {
debug_print(srtp_mod_aes_gcm, "wolfSSL error code: %d", err);
return srtp_err_status_bad_param;
}
*dst_len = src_len;

return (srtp_err_status_ok);
}
Expand Down Expand Up @@ -392,8 +395,10 @@ static srtp_err_status_t srtp_aes_gcm_wolfssl_get_tag(void *cv,
* enc_len length of encrypt buffer
*/
static srtp_err_status_t srtp_aes_gcm_wolfssl_decrypt(void *cv,
unsigned char *buf,
size_t *enc_len)
const uint8_t *src,
size_t src_len,
uint8_t *dst,
size_t *dst_len)
{
FUNC_ENTRY();
srtp_aes_gcm_ctx_t *c = (srtp_aes_gcm_ctx_t *)cv;
Expand All @@ -407,19 +412,19 @@ static srtp_err_status_t srtp_aes_gcm_wolfssl_decrypt(void *cv,
debug_print(srtp_mod_aes_gcm, "AAD: %s",
srtp_octet_string_hex_string(c->aad, c->aad_size));

err = wc_AesGcmDecrypt(c->ctx, buf, buf, (*enc_len - c->tag_len), c->iv,
c->iv_len, buf + (*enc_len - c->tag_len), c->tag_len,
err = wc_AesGcmDecrypt(c->ctx, dst, src, (src_len - c->tag_len), c->iv,
c->iv_len, src + (src_len - c->tag_len), c->tag_len,
c->aad, c->aad_size);
c->aad_size = 0;
#else
err = wc_AesGcmDecryptUpdate(c->ctx, buf, buf, (*enc_len - c->tag_len),
NULL, 0);
err = wc_AesGcmDecryptUpdate(c->ctx, dst, src, (src_len - c->tag_len), NULL,
0);
if (err < 0) {
debug_print(srtp_mod_aes_gcm, "wolfSSL error code: %d", err);
return (srtp_err_status_algo_fail);
}
err = wc_AesGcmDecryptFinal(c->ctx, buf + (*enc_len - c->tag_len),
c->tag_len);
err =
wc_AesGcmDecryptFinal(c->ctx, src + (src_len - c->tag_len), c->tag_len);
#endif
if (err < 0) {
debug_print(srtp_mod_aes_gcm, "wolfSSL error code: %d", err);
Expand All @@ -430,7 +435,7 @@ static srtp_err_status_t srtp_aes_gcm_wolfssl_decrypt(void *cv,
* Reduce the buffer size by the tag length since the tag
* is not part of the original payload
*/
*enc_len -= c->tag_len;
*dst_len = src_len -= c->tag_len;

return (srtp_err_status_ok);
}
Expand Down
9 changes: 6 additions & 3 deletions crypto/cipher/aes_icm_wssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,19 +308,22 @@ static srtp_err_status_t srtp_aes_icm_wolfssl_set_iv(
* enc_len length of encrypt buffer
*/
static srtp_err_status_t srtp_aes_icm_wolfssl_encrypt(void *cv,
uint8_t *buf,
size_t *enc_len)
const uint8_t *src,
size_t src_len,
uint8_t *dst,
size_t *dst_len)
{
srtp_aes_icm_ctx_t *c = (srtp_aes_icm_ctx_t *)cv;

int err;
debug_print(srtp_mod_aes_icm, "rs0: %s", v128_hex_string(&c->counter));

err = wc_AesCtrEncrypt(c->ctx, buf, buf, *enc_len);
err = wc_AesCtrEncrypt(c->ctx, dst, src, src_len);
if (err < 0) {
debug_print(srtp_mod_aes_icm, "wolfSSL encrypt error: %d", err);
return srtp_err_status_cipher_fail;
}
*dst_len = src_len;

return srtp_err_status_ok;
}
Expand Down

0 comments on commit 1a414fc

Please sign in to comment.