Skip to content

Commit

Permalink
brush up
Browse files Browse the repository at this point in the history
  • Loading branch information
ROZ-MOFUMOFU-ME committed May 25, 2024
1 parent a45425c commit 99da45f
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 478 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"files.associations": {
"sha256.h": "c",
"stdlib.h": "c",
"errno.h": "c"
"errno.h": "c",
"functional": "cpp"
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Cryptocurrency hashing functions for node.js.

Algorithms
----------
Supported algorithms: `quark, x11, x13, x16r, x16rv2, nist5, scrypt, scryptn, scryptjane, keccak, bcrypt, skein, groestl, blake, fugue, qubit, hefty1, shavite3, cryptonight, boolberry, sha256d, lbry, kawpaw, allium, hsr, lyra2re2, m7, minotaur, odo, phi1612, skunk, skydoge, tribus, x17, x25x, yescrypt, yespower`, *__and more!__*
Supported algorithms: `quark, x11, x13, x16r, x16rv2, nist5, scrypt, scryptn, scryptjane, keccak, bcrypt, skein, groestl, blake, fugue, qubit, hefty1, shavite3, cryptonight, boolberry, sha256d, lbry, kawpaw, allium, blake2s, gost, hsr, lyra2re2, lyra2z, m7, m7m, minotaur, odo, phi1612, sha1, skunk, skydoge, tribus, whirlpoolx, x17, x25x, xevan, zr5, yescrypt, yespower`, *__and more!__*


Usage
Expand Down
30 changes: 30 additions & 0 deletions src/crypto/sha256.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,36 @@ typedef struct HMAC_SHA256Context {
sha256_ctx octx;
} hmac_sha256_ctx;

/**
* SHA256_Buf(in, len, digest):
* Compute the SHA256 hash of ${len} bytes from ${in} and write it to ${digest}.
*/
static void
sha256_buf(const void* in, size_t len, uint8_t digest[32])
{
sha256_ctx ctx;

sha256_init(&ctx);
sha256_update(&ctx, in, len);
sha256_final(digest, &ctx);
}

/**
* HMAC_SHA256_Buf(K, Klen, in, len, digest):
* Compute the HMAC-SHA256 of ${len} bytes from ${in} using the key ${K} of
* length ${Klen}, and write the result to ${digest}.
*/
static void
hmac_sha256_buf(const void* K, size_t Klen, const void* in, size_t len,
uint8_t digest[32])
{
hmac_sha256_ctx ctx;

hmac_sha256_init(&ctx, K, Klen);
hmac_sha256_update(&ctx, in, len);
hmac_sha256_final(digest, &ctx);
}

void sha256_init(sha256_ctx *);
void sha256_update(sha256_ctx *, const void *, size_t);
void sha256_final(unsigned char [32], sha256_ctx *);
Expand Down
Loading

0 comments on commit 99da45f

Please sign in to comment.