void CryptoDigest::addBytes(const void* input, size_t length) { switch (m_context->algorithm) { case CryptoDigest::Algorithm::SHA_1: CC_SHA1_Update(toSHA1Context(m_context.get()), input, length); return; case CryptoDigest::Algorithm::SHA_224: CC_SHA224_Update(toSHA224Context(m_context.get()), input, length); return; case CryptoDigest::Algorithm::SHA_256: CC_SHA256_Update(toSHA256Context(m_context.get()), input, length); return; case CryptoDigest::Algorithm::SHA_384: CC_SHA384_Update(toSHA384Context(m_context.get()), input, length); return; case CryptoDigest::Algorithm::SHA_512: CC_SHA512_Update(toSHA512Context(m_context.get()), input, length); return; } }
static void _wi_sha2_ctx_update(_wi_sha2_ctx_t *ctx, const void *data, unsigned long length) { #ifdef WI_SHA2_OPENSSL switch(ctx->bits) { case WI_SHA2_224: SHA224_Update(&ctx->openssl_256_ctx, data, length); break; case WI_SHA2_256: SHA256_Update(&ctx->openssl_256_ctx, data, length); break; case WI_SHA2_384: SHA384_Update(&ctx->openssl_512_ctx, data, length); break; case WI_SHA2_512: SHA512_Update(&ctx->openssl_512_ctx, data, length); break; } #endif #ifdef WI_SHA2_COMMONCRYPTO switch(ctx->bits) { case WI_SHA2_224: CC_SHA224_Update(&ctx->commondigest_256_ctx, data, length); break; case WI_SHA2_256: CC_SHA256_Update(&ctx->commondigest_256_ctx, data, length); break; case WI_SHA2_384: CC_SHA384_Update(&ctx->commondigest_512_ctx, data, length); break; case WI_SHA2_512: CC_SHA512_Update(&ctx->commondigest_512_ctx, data, length); break; } #endif }
void CryptoDigest::addBytes(const void* input, size_t length) { switch (m_context->algorithm) { case CryptoAlgorithmIdentifier::SHA_1: CC_SHA1_Update(toSHA1Context(m_context.get()), input, length); return; case CryptoAlgorithmIdentifier::SHA_224: CC_SHA224_Update(toSHA224Context(m_context.get()), input, length); return; case CryptoAlgorithmIdentifier::SHA_256: CC_SHA256_Update(toSHA256Context(m_context.get()), input, length); return; case CryptoAlgorithmIdentifier::SHA_384: CC_SHA384_Update(toSHA384Context(m_context.get()), input, length); return; case CryptoAlgorithmIdentifier::SHA_512: CC_SHA512_Update(toSHA512Context(m_context.get()), input, length); return; default: ASSERT_NOT_REACHED(); } }
ssize_t /* O - Size of hash or -1 on error */ cupsHashData(const char *algorithm, /* I - Algorithm name */ const void *data, /* I - Data to hash */ size_t datalen, /* I - Length of data to hash */ unsigned char *hash, /* I - Hash buffer */ size_t hashsize) /* I - Size of hash buffer */ { if (!algorithm || !data || datalen == 0 || !hash || hashsize == 0) { _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Bad arguments to function"), 1); return (-1); } #ifdef __APPLE__ if (!strcmp(algorithm, "sha")) { /* * SHA-1... */ CC_SHA1_CTX ctx; /* SHA-1 context */ if (hashsize < CC_SHA1_DIGEST_LENGTH) goto too_small; CC_SHA1_Init(&ctx); CC_SHA1_Update(&ctx, data, (CC_LONG)datalen); CC_SHA1_Final(hash, &ctx); return (CC_SHA1_DIGEST_LENGTH); } else if (!strcmp(algorithm, "sha2-224")) { CC_SHA256_CTX ctx; /* SHA-224 context */ if (hashsize < CC_SHA224_DIGEST_LENGTH) goto too_small; CC_SHA224_Init(&ctx); CC_SHA224_Update(&ctx, data, (CC_LONG)datalen); CC_SHA224_Final(hash, &ctx); return (CC_SHA224_DIGEST_LENGTH); } else if (!strcmp(algorithm, "sha2-256")) { CC_SHA256_CTX ctx; /* SHA-256 context */ if (hashsize < CC_SHA256_DIGEST_LENGTH) goto too_small; CC_SHA256_Init(&ctx); CC_SHA256_Update(&ctx, data, (CC_LONG)datalen); CC_SHA256_Final(hash, &ctx); return (CC_SHA256_DIGEST_LENGTH); } else if (!strcmp(algorithm, "sha2-384")) { CC_SHA512_CTX ctx; /* SHA-384 context */ if (hashsize < CC_SHA384_DIGEST_LENGTH) goto too_small; CC_SHA384_Init(&ctx); CC_SHA384_Update(&ctx, data, (CC_LONG)datalen); CC_SHA384_Final(hash, &ctx); return (CC_SHA384_DIGEST_LENGTH); } else if (!strcmp(algorithm, "sha2-512")) { CC_SHA512_CTX ctx; /* SHA-512 context */ if (hashsize < CC_SHA512_DIGEST_LENGTH) goto too_small; CC_SHA512_Init(&ctx); CC_SHA512_Update(&ctx, data, (CC_LONG)datalen); CC_SHA512_Final(hash, &ctx); return (CC_SHA512_DIGEST_LENGTH); } else if (!strcmp(algorithm, "sha2-512_224")) { CC_SHA512_CTX ctx; /* SHA-512 context */ unsigned char temp[CC_SHA512_DIGEST_LENGTH]; /* SHA-512 hash */ /* * SHA2-512 truncated to 224 bits (28 bytes)... */ if (hashsize < CC_SHA224_DIGEST_LENGTH) goto too_small; CC_SHA512_Init(&ctx); CC_SHA512_Update(&ctx, data, (CC_LONG)datalen); CC_SHA512_Final(temp, &ctx); memcpy(hash, temp, CC_SHA224_DIGEST_LENGTH); return (CC_SHA224_DIGEST_LENGTH); } else if (!strcmp(algorithm, "sha2-512_256")) { CC_SHA512_CTX ctx; /* SHA-512 context */ unsigned char temp[CC_SHA512_DIGEST_LENGTH]; /* SHA-512 hash */ /* * SHA2-512 truncated to 256 bits (32 bytes)... */ if (hashsize < CC_SHA256_DIGEST_LENGTH) goto too_small; CC_SHA512_Init(&ctx); CC_SHA512_Update(&ctx, data, (CC_LONG)datalen); CC_SHA512_Final(temp, &ctx); memcpy(hash, temp, CC_SHA256_DIGEST_LENGTH); return (CC_SHA256_DIGEST_LENGTH); } #elif defined(HAVE_GNUTLS) gnutls_digest_algorithm_t alg = GNUTLS_DIG_UNKNOWN; /* Algorithm */ unsigned char temp[64]; /* Temporary hash buffer */ size_t tempsize = 0; /* Truncate to this size? */ if (!strcmp(algorithm, "sha")) alg = GNUTLS_DIG_SHA1; else if (!strcmp(algorithm, "sha2-224")) alg = GNUTLS_DIG_SHA224; else if (!strcmp(algorithm, "sha2-256")) alg = GNUTLS_DIG_SHA256; else if (!strcmp(algorithm, "sha2-384")) alg = GNUTLS_DIG_SHA384; else if (!strcmp(algorithm, "sha2-512")) alg = GNUTLS_DIG_SHA512; else if (!strcmp(algorithm, "sha2-512_224")) { alg = GNUTLS_DIG_SHA512; tempsize = 28; } else if (!strcmp(algorithm, "sha2-512_256")) { alg = GNUTLS_DIG_SHA512; tempsize = 32; } if (alg != GNUTLS_DIG_UNKNOWN) { if (tempsize > 0) { /* * Truncate result to tempsize bytes... */ if (hashsize < tempsize) goto too_small; gnutls_hash_fast(alg, data, datalen, temp); memcpy(hash, temp, tempsize); return ((ssize_t)tempsize); } if (hashsize < gnutls_hash_get_len(alg)) goto too_small; gnutls_hash_fast(alg, data, datalen, hash); return (gnutls_hash_get_len(alg)); } #else /* * No hash support without CommonCrypto or GNU TLS... */ if (hashsize < 64) goto too_small; #endif /* __APPLE__ */ /* * Unknown hash algorithm... */ _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Unknown hash algorithm."), 1); return (-1); /* * We get here if the buffer is too small. */ too_small: _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Hash buffer too small."), 1); return (-1); }
void SHA224Object::digestUpdate( const void *data, size_t len) { CC_SHA224_Update(&mCtx, (const unsigned char *)data, (CC_LONG)len); }
void SHA224Digest::Update(const void* buffer, size_t length) { CC_SHA224_Update(&mContext, buffer, (CC_LONG)length); }
int sCCHashUpdateSHA224(void *ctx, const unsigned char *in, unsigned long inlen) { CC_SHA224_Update(ctx, in, (CC_LONG)inlen); return CRYPT_OK; }