node:crypto: add blake2s256 hasher (#22958)

This commit is contained in:
Meghan Denny
2025-09-25 14:28:42 -08:00
committed by GitHub
parent be15f6c80c
commit 20854fb285
9 changed files with 11 additions and 1 deletions

View File

@@ -184,6 +184,7 @@ Bun.hash.rapidhash("data", 1234);
- `"blake2b256"`
- `"blake2b512"`
- `"blake2s256"`
- `"md4"`
- `"md5"`
- `"ripemd160"`

View File

@@ -5047,6 +5047,7 @@ declare module "bun" {
type SupportedCryptoAlgorithms =
| "blake2b256"
| "blake2b512"
| "blake2s256"
| "md4"
| "md5"
| "ripemd160"

View File

@@ -488,6 +488,7 @@ const CryptoHasherZig = struct {
.{ "sha3-512", std.crypto.hash.sha3.Sha3_512 },
.{ "shake128", std.crypto.hash.sha3.Shake128 },
.{ "shake256", std.crypto.hash.sha3.Shake256 },
.{ "blake2s256", std.crypto.hash.blake2.Blake2s256 },
};
inline fn digestLength(Algorithm: type) comptime_int {

View File

@@ -21,6 +21,7 @@ pub const Algorithm = enum {
// @"ecdsa-with-SHA1",
blake2b256,
blake2b512,
blake2s256,
md4,
md5,
ripemd160,
@@ -69,6 +70,7 @@ pub const Algorithm = enum {
pub const map = bun.ComptimeStringMap(Algorithm, .{
.{ "blake2b256", .blake2b256 },
.{ "blake2b512", .blake2b512 },
.{ "blake2s256", .blake2s256 },
.{ "ripemd160", .ripemd160 },
.{ "rmd160", .ripemd160 },
.{ "md4", .md4 },

View File

@@ -185,6 +185,7 @@ describe("CryptoHasher", () => {
const algorithms = [
"blake2b256",
"blake2b512",
"blake2s256",
"ripemd160",
"rmd160",
"md4",

View File

@@ -21,6 +21,7 @@ test("createHmac works with various algorithm names", () => {
const toRemove = [
"blake2b256",
"blake2b512",
"blake2s256",
"md4",
"sha512-224",
"sha512-256",

View File

@@ -39,6 +39,7 @@ describe("crypto.hash", () => {
[
"blake2b256",
"blake2b512",
"blake2s256",
"ripemd160",
"rmd160",
"md4",

View File

@@ -11,6 +11,7 @@ describe("CryptoHasher", () => {
expect(CryptoHasher.algorithms).toEqual([
"blake2b256",
"blake2b512",
"blake2s256",
"md4",
"md5",
"ripemd160",
@@ -34,6 +35,7 @@ describe("CryptoHasher", () => {
const expected = {
blake2b256: "256c83b297114d201b30179f3f0ef0cace9783622da5974326b436178aeef610",
blake2b512: "021ced8799296ceca557832ab941a50b4a11f83478cf141f51f933f653ab9fbcc05a037cddbed06e309bf334942c4e58cdf1a46e237911ccd7fcf9787cbc7fd0",
blake2s256: "9aec6806794561107e594b1f6a8a6b0c92a0cba9acf5e5e93cca06f781813b0b",
md4: "aa010fbc1d14c795d86ef98c95479d17",
md5: "5eb63bbbe01eeed093cb22bb8f5acdc3",
ripemd160: "98c615784ccb5fe5936fbc0cbe9dfdb408d92f0f",
@@ -55,6 +57,7 @@ describe("CryptoHasher", () => {
const expectedBitLength = {
blake2b256: 256,
blake2b512: 512,
blake2s256: 256,
md4: 128,
md5: 128,
ripemd160: 160,

View File

@@ -255,7 +255,6 @@ describe("createHash", () => {
};
const unsupported = [
"blake2s256",
"id-rsassa-pkcs1-v1_5-with-sha3-224",
"id-rsassa-pkcs1-v1_5-with-sha3-256",
"id-rsassa-pkcs1-v1_5-with-sha3-384",