diff options
author | 2022-12-28 22:24:37 -0800 | |
---|---|---|
committer | 2022-12-28 22:24:37 -0800 | |
commit | 0504bb89848255c64bee3ba5a36601444de0c97c (patch) | |
tree | 374d7408eee064665c7328046956aadb2ff3a572 | |
parent | d726a17aca6a0b7e98ee86c193158e7860bb0834 (diff) | |
download | bun-0504bb89848255c64bee3ba5a36601444de0c97c.tar.gz bun-0504bb89848255c64bee3ba5a36601444de0c97c.tar.zst bun-0504bb89848255c64bee3ba5a36601444de0c97c.zip |
Expose the rest of RIPEMD160
-rw-r--r-- | src/deps/patches/boringssl/fix_sync_evp_get_cipherbynid_and_evp_get_cipherbyname.patch | 25 | ||||
-rw-r--r-- | src/sha.zig | 12 | ||||
-rw-r--r-- | test/bun.js/crypto.test.js | 16 |
3 files changed, 52 insertions, 1 deletions
diff --git a/src/deps/patches/boringssl/fix_sync_evp_get_cipherbynid_and_evp_get_cipherbyname.patch b/src/deps/patches/boringssl/fix_sync_evp_get_cipherbynid_and_evp_get_cipherbyname.patch new file mode 100644 index 000000000..e739ae8f7 --- /dev/null +++ b/src/deps/patches/boringssl/fix_sync_evp_get_cipherbynid_and_evp_get_cipherbyname.patch @@ -0,0 +1,25 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Shelley Vohr <shelley.vohr@gmail.com> +Date: Mon, 28 Jun 2021 10:41:09 +0200 +Subject: fix: sync EVP_get_cipherbynid and EVP_get_cipherbyname + +This commit syncs the results of EVP_get_cipherbynid and +EVP_get_cipherbyname. Node.js logic assumes that calling EVP_get_cipherbynid +on a NID returned from a call to `getCipherInfo` with the cipher name +will return the same cipher information - this assumption holds in OpenSSL +and should also hold in BoringSSL. + +This will be upstreamed. + +diff --git a/crypto/cipher_extra/cipher_extra.c b/crypto/cipher_extra/cipher_extra.c +index d97f67fb03756169446edf6b41d3a33fe3ae8205..cfdb69e3c556fea11aa7c2d28d4b7da524df15c3 100644 +--- a/crypto/cipher_extra/cipher_extra.c ++++ b/crypto/cipher_extra/cipher_extra.c +@@ -97,6 +97,7 @@ static const struct { + {NID_des_ede3_cbc, "des-ede3-cbc", EVP_des_ede3_cbc}, + {NID_rc2_cbc, "rc2-cbc", EVP_rc2_cbc}, + {NID_rc4, "rc4", EVP_rc4}, ++ {NID_rc2_40_cbc, "rc2-40-cbc", EVP_rc2_40_cbc} + }; + + const EVP_CIPHER *EVP_get_cipherbynid(int nid) { diff --git a/src/sha.zig b/src/sha.zig index 80d5f6b36..ec58954de 100644 --- a/src/sha.zig +++ b/src/sha.zig @@ -18,14 +18,17 @@ fn NewHasher(comptime digest_size: comptime_int, comptime ContextType: type, com } pub fn hash(bytes: []const u8, out: *Digest) void { + @setRuntimeSafety(false); _ = Full(bytes.ptr, bytes.len, out); } pub fn update(this: *@This(), data: []const u8) void { + @setRuntimeSafety(false); std.debug.assert(Update(&this.hasher, data.ptr, data.len) == 1); } pub fn final(this: *@This(), out: *Digest) void { + @setRuntimeSafety(false); std.debug.assert(Final(out, &this.hasher) == 1); } }; @@ -137,6 +140,15 @@ pub const Hashers = struct { BoringSSL.SHA512_256_Update, BoringSSL.SHA512_256_Final, ); + + pub const RIPEMD160 = NewHasher( + BoringSSL.RIPEMD160_DIGEST_LENGTH, + BoringSSL.RIPEMD160_CTX, + BoringSSL.RIPEMD160, + BoringSSL.RIPEMD160_Init, + BoringSSL.RIPEMD160_Update, + BoringSSL.RIPEMD160_Final, + ); }; const boring = [_]type{ diff --git a/test/bun.js/crypto.test.js b/test/bun.js/crypto.test.js index c489e11c1..30a0f227d 100644 --- a/test/bun.js/crypto.test.js +++ b/test/bun.js/crypto.test.js @@ -3,17 +3,31 @@ import { MD5, MD4, SHA1, + SHA224, SHA256, SHA384, SHA512, SHA512_256, + RIPEMD160, gc, } from "bun"; import { it, expect, describe } from "bun:test"; import { readFileSync } from "fs"; +const HashClasses = [ + MD5, + MD4, + SHA1, + SHA224, + SHA256, + SHA384, + SHA512, + SHA512_256, + RIPEMD160, +]; + describe("crypto", () => { - for (let Hash of [MD5, MD4, SHA1, SHA256, SHA384, SHA512, SHA512_256]) { + for (let Hash of HashClasses) { for (let [input, label] of [ ["hello world", '"hello world"'], ["hello world".repeat(20).slice(), '"hello world" x 20'], |