unsigned char* sha384_MemBlock(const unsigned char* msg, size_t size, HASH_ctx* ctx) { sha384_init(ctx); sha384_update(ctx, msg, size); sha384_final(ctx, msg, size); return ctx->SHA384_result; }
static int __archive_nettle_sha384update(archive_sha384_ctx *ctx, const void *indata, size_t insize) { sha384_update(ctx, insize, indata); return (ARCHIVE_OK); }
void hmac_sha384_init(hmac_sha384_ctx *ctx, unsigned char *key, unsigned int key_size) { unsigned int fill; unsigned int num; unsigned char *key_used; unsigned char key_temp[SHA384_DIGEST_SIZE]; int i; if (key_size == SHA384_BLOCK_SIZE) { key_used = key; num = SHA384_BLOCK_SIZE; } else { if (key_size > SHA384_BLOCK_SIZE){ key_used = key_temp; num = SHA384_DIGEST_SIZE; sha384(key, key_size, key_used); } else { /* key_size > SHA384_BLOCK_SIZE */ key_used = key; num = key_size; } fill = SHA384_BLOCK_SIZE - num; memset(ctx->block_ipad + num, 0x36, fill); memset(ctx->block_opad + num, 0x5c, fill); } for (i = 0; i < num; i++) { ctx->block_ipad[i] = key_used[i] ^ 0x36; ctx->block_opad[i] = key_used[i] ^ 0x5c; } sha384_init(&ctx->ctx_inside); sha384_update(&ctx->ctx_inside, ctx->block_ipad, SHA384_BLOCK_SIZE); sha384_init(&ctx->ctx_outside); sha384_update(&ctx->ctx_outside, ctx->block_opad, SHA384_BLOCK_SIZE); /* for hmac_reinit */ memcpy(&ctx->ctx_inside_reinit, &ctx->ctx_inside, sizeof(sha384_ctx)); memcpy(&ctx->ctx_outside_reinit, &ctx->ctx_outside, sizeof(sha384_ctx)); }
void sha384(unsigned char *digest, int len, unsigned char *hash) { SHA384CTX c = sha384_init(); if (c != NULL) { sha384_update(c, digest, len); sha384_final(hash, c); } }
void sha384(const unsigned char *message, unsigned int len, unsigned char *digest) { sha384_ctx ctx; sha384_init(&ctx); sha384_update(&ctx, message, len); sha384_final(&ctx, digest); }
void sha384_complete(const void *buf, size_t len, uint8_t *digest) { sha384_ctx ctx; sha384_init(&ctx); sha384_update(&ctx, buf, len); sha384_final(&ctx, digest); }
void hmac_sha384_final(hmac_sha384_ctx *ctx, unsigned char *mac, unsigned int mac_size) { unsigned char digest_inside[SHA384_DIGEST_SIZE]; unsigned char mac_temp[SHA384_DIGEST_SIZE]; sha384_final(&ctx->ctx_inside, digest_inside); sha384_update(&ctx->ctx_outside, digest_inside, SHA384_DIGEST_SIZE); sha384_final(&ctx->ctx_outside, mac_temp); memcpy(mac, mac_temp, mac_size); }
ssh_string SshAgentSignEcdsaSha384(uint8_t* data, int dataSize, ssh_key key, uint32_t flags) { // Compute the hash. unsigned char hash[SHA384_DIGEST_LEN] = {0}; SHACTX ctx; ctx = sha384_init(); if (ctx == NULL) { return NULL; } sha384_update(ctx, data, dataSize); sha384_final(hash, ctx); // This release ctx. // Sign the hash. ECDSA_SIG* sig = NULL; sig = ECDSA_do_sign(hash, sizeof(hash), key->ecdsa); if (sig == NULL) { return NULL; } // Format the signature in a blob of the form: // blobLength[ typeNameLength[ typeName ] signatureLength[ rLength[ r ] sLength[ s ] ] ] int rMpiLength = BN_bn2mpi(sig->r, NULL); int sMpiLength = BN_bn2mpi(sig->s, NULL); int signatureLength = rMpiLength + sMpiLength; int typeNameLength = 19; int blobLength = 8 + typeNameLength + signatureLength; uint8_t* signatureBlob = malloc(4 + blobLength); if (signatureBlob == NULL) { return NULL; } pack32(signatureBlob, blobLength); int index = 4; pack32(signatureBlob + index, typeNameLength); index += 4; memcpy(signatureBlob + index, "ecdsa-sha2-nistp384", typeNameLength); index += typeNameLength; pack32(signatureBlob + 15, signatureLength); index += 4; BN_bn2mpi(sig->r, signatureBlob + index); index += rMpiLength; BN_bn2mpi(sig->s, signatureBlob + index); return (ssh_string)signatureBlob; }
void ssh_mac_update(ssh_mac_ctx ctx, const void *data, unsigned long len) { switch(ctx->mac_type){ case SSH_MAC_SHA1: sha1_update(ctx->ctx.sha1_ctx, data, len); break; case SSH_MAC_SHA256: sha256_update(ctx->ctx.sha256_ctx, data, len); break; case SSH_MAC_SHA384: sha384_update(ctx->ctx.sha384_ctx, data, len); break; case SSH_MAC_SHA512: sha512_update(ctx->ctx.sha512_ctx, data, len); break; default: break; } }
static int _digest_nettle(int algo, uint8_t* buf, size_t len, unsigned char* res) { switch(algo) { case SHA1_DIGEST_SIZE: { struct sha1_ctx ctx; sha1_init(&ctx); sha1_update(&ctx, len, buf); sha1_digest(&ctx, SHA1_DIGEST_SIZE, res); return 1; } case SHA256_DIGEST_SIZE: { struct sha256_ctx ctx; sha256_init(&ctx); sha256_update(&ctx, len, buf); sha256_digest(&ctx, SHA256_DIGEST_SIZE, res); return 1; } case SHA384_DIGEST_SIZE: { struct sha384_ctx ctx; sha384_init(&ctx); sha384_update(&ctx, len, buf); sha384_digest(&ctx, SHA384_DIGEST_SIZE, res); return 1; } case SHA512_DIGEST_SIZE: { struct sha512_ctx ctx; sha512_init(&ctx); sha512_update(&ctx, len, buf); sha512_digest(&ctx, SHA512_DIGEST_SIZE, res); return 1; } default: break; } return 0; }
static NTSTATUS hash_update( struct hash_impl *hash, enum alg_id alg_id, UCHAR *input, ULONG size ) { switch (alg_id) { case ALG_ID_MD2: md2_update( &hash->u.md2, input, size ); break; case ALG_ID_MD4: MD4Update( &hash->u.md4, input, size ); break; case ALG_ID_MD5: MD5Update( &hash->u.md5, input, size ); break; case ALG_ID_SHA1: A_SHAUpdate( &hash->u.sha1, input, size ); break; case ALG_ID_SHA256: sha256_update( &hash->u.sha256, input, size ); break; case ALG_ID_SHA384: sha384_update( &hash->u.sha512, input, size ); break; case ALG_ID_SHA512: sha512_update( &hash->u.sha512, input, size ); break; default: ERR( "unhandled id %u\n", alg_id ); return STATUS_NOT_IMPLEMENTED; } return STATUS_SUCCESS; }
void hmac_sha384_update(hmac_sha384_ctx *ctx, unsigned char *message, unsigned int message_len) { sha384_update(&ctx->ctx_inside, message, message_len); }
void mySHA384_Update(void *c, unsigned char *in, int len) {sha384_update((sha384_ctx *)c, in, len); }
void libmaus::digest::SHA2_384::update(uint8_t const * t, size_t l) { sha384_update(reinterpret_cast<sha384_ctx *>(ctx),l,t); }