Skip to content

Commit

Permalink
cmac: avoid using CMAC_resume()
Browse files Browse the repository at this point in the history
The function was removed in LibreSSL 3.9.
  • Loading branch information
kmfukuda committed Sep 17, 2024
1 parent 63e7e5f commit 741eabf
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions ext/openssl/ossl_cmac.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,17 +229,25 @@ ossl_cmac_mac(VALUE self)
return ret;
#else
VALUE ret;
CMAC_CTX *ctx;
CMAC_CTX *ctx1, *ctx2;
size_t len;

GetCMAC(self, ctx);
if (CMAC_Final(ctx, NULL, &len) != 1)
GetCMAC(self, ctx1);
if (CMAC_Final(ctx1, NULL, &len) != 1)
ossl_raise(eCMACError, "CMAC_Final");
ret = rb_str_new(NULL, len);
if (CMAC_Final(ctx, (unsigned char *)RSTRING_PTR(ret), &len) != 1)
ctx2 = CMAC_CTX_new();
if (!ctx2)
ossl_raise(eCMACError, "CMAC_CTX_new");
if (CMAC_CTX_copy(ctx2, ctx1) != 1) {
CMAC_CTX_free(ctx2);
ossl_raise(eCMACError, "CMAC_CTX_copy");
}
if (CMAC_Final(ctx2, (unsigned char *)RSTRING_PTR(ret), &len) != 1) {
CMAC_CTX_free(ctx2);
ossl_raise(eCMACError, "CMAC_Final");
if (CMAC_resume(ctx) != 1)
ossl_raise(eCMACError, "CMAC_resume");
}
CMAC_CTX_free(ctx2);

return ret;
#endif
Expand Down

0 comments on commit 741eabf

Please sign in to comment.