예제 #1
0
void
isc_hmacsha224_init(isc_hmacsha224_t *ctx, const unsigned char *key,
		    unsigned int len)
{
#ifdef HMAC_RETURN_INT
	RUNTIME_CHECK(HMAC_Init(ctx, (const void *) key,
				(int) len, EVP_sha224()) == 1);
#else
	HMAC_Init(ctx, (const void *) key, (int) len, EVP_sha224());
#endif
}
예제 #2
0
파일: hash.c 프로젝트: latchset/jose
static jose_io_t *
hsh(const jose_hook_alg_t *alg, jose_cfg_t *cfg, jose_io_t *next)
{
    jose_io_auto_t *io = NULL;
    const EVP_MD *md = NULL;
    io_t *i = NULL;

    switch (str2enum(alg->name, "S512", "S384", "S256", "S224", "S1", NULL)) {
    case 0: md = EVP_sha512(); break;
    case 1: md = EVP_sha384(); break;
    case 2: md = EVP_sha256(); break;
    case 3: md = EVP_sha224(); break;
    case 4: md = EVP_sha1();   break;
    }

    i = calloc(1, sizeof(*i));
    if (!i)
        return NULL;

    io = jose_io_incref(&i->io);
    io->feed = hsh_feed;
    io->done = hsh_done;
    io->free = hsh_free;

    i->next = jose_io_incref(next);
    i->emc = EVP_MD_CTX_new();
    if (!i->next || !i->emc)
        return NULL;

    if (EVP_DigestInit(i->emc, md) <= 0)
        return NULL;

    return jose_io_incref(io);
}
예제 #3
0
파일: t1_lib.c 프로젝트: bbbrumley/openbsd
const EVP_MD *
tls12_get_hash(unsigned char hash_alg)
{
	switch (hash_alg) {
	case TLSEXT_hash_sha1:
		return EVP_sha1();
	case TLSEXT_hash_sha224:
		return EVP_sha224();
	case TLSEXT_hash_sha256:
		return EVP_sha256();
	case TLSEXT_hash_sha384:
		return EVP_sha384();
	case TLSEXT_hash_sha512:
		return EVP_sha512();
#ifndef OPENSSL_NO_GOST
	case TLSEXT_hash_gost94:
		return EVP_gostr341194();
	case TLSEXT_hash_streebog_256:
		return EVP_streebog256();
	case TLSEXT_hash_streebog_512:
		return EVP_streebog512();
#endif
	default:
		return NULL;
	}
}
예제 #4
0
KDF_FUNC KDF_get_x9_63(const EVP_MD *md)
{
	if (md == EVP_md5()) {
		return x963_md5kdf;

	} else if (md == EVP_ripemd160()) {
		return x963_rmd160kdf;

	} else if (md == EVP_sha1()) {
		return x963_sha1kdf;

	} else if (md == EVP_sha224()) {
		return x963_sha224kdf;

	} else if (md == EVP_sha256()) {
		return x963_sha256kdf;

	} else if (md == EVP_sha384()) {
		return x963_sha384kdf;

	} else if (md == EVP_sha512()) {
		return x963_sha512kdf;

	} else if (md == EVP_whirlpool()) {
		return x963_whirlpoolkdf;

	} else if (md == EVP_sm3()) {
		return x963_sm3kdf;
	}

	return NULL;
}
예제 #5
0
const EVP_MD *
tsig_get_EVP_MD(u8 algorithm)
{
    switch(algorithm)
    {
#ifndef OPENSSL_NO_MD5
        case HMAC_MD5:
            return EVP_md5();
#endif
#ifndef OPENSSL_NO_SHA
        case HMAC_SHA1:
            return EVP_sha1();
#endif
#ifndef OPENSSL_NO_SHA256
        case HMAC_SHA224:
            return EVP_sha224();
        case HMAC_SHA256:
            return EVP_sha256();
#endif
#ifndef OPENSSL_NO_SHA512
        case HMAC_SHA384:
            return EVP_sha384();
        case HMAC_SHA512:
            return EVP_sha512();
#endif
        default:
            return EVP_md_null();
    }
}
예제 #6
0
void openssl_add_all_digests_internal(void)
{
#ifndef OPENSSL_NO_MD4
    EVP_add_digest(EVP_md4());
#endif
#ifndef OPENSSL_NO_MD5
    EVP_add_digest(EVP_md5());
    EVP_add_digest_alias(SN_md5, "ssl3-md5");
    EVP_add_digest(EVP_md5_sha1());
#endif
    EVP_add_digest(EVP_sha1());
    EVP_add_digest_alias(SN_sha1, "ssl3-sha1");
    EVP_add_digest_alias(SN_sha1WithRSAEncryption, SN_sha1WithRSA);
#if !defined(OPENSSL_NO_MDC2) && !defined(OPENSSL_NO_DES)
    EVP_add_digest(EVP_mdc2());
#endif
#ifndef OPENSSL_NO_RMD160
    EVP_add_digest(EVP_ripemd160());
    EVP_add_digest_alias(SN_ripemd160, "ripemd");
    EVP_add_digest_alias(SN_ripemd160, "rmd160");
#endif
    EVP_add_digest(EVP_sha224());
    EVP_add_digest(EVP_sha256());
    EVP_add_digest(EVP_sha384());
    EVP_add_digest(EVP_sha512());
#ifndef OPENSSL_NO_WHIRLPOOL
    EVP_add_digest(EVP_whirlpool());
#endif
}
int server_finished(FILE* log_server, char * master_secret, char * ciphersuite_to_use){
    
	FILE* channel = fopen (link_channel,"w");
    unsigned char * hash_server_log = calloc (24 , sizeof(unsigned char));

    const EVP_MD * evp_md;
    
    if(atoi(ciphersuite_to_use) == atoi(TLS_DHE_RSA_WITH_SHA224) || atoi(ciphersuite_to_use) == atoi(TLS_RSA_WITH_SHA224)){
        evp_md = EVP_sha224();
    }
    else if(atoi(ciphersuite_to_use) == atoi(TLS_RSA_WITH_SHA256) || atoi(ciphersuite_to_use) == atoi(TLS_DHE_RSA_WITH_SHA256)){
        evp_md = EVP_sha256();
    }
    else if(atoi(ciphersuite_to_use) == atoi(TLS_DHE_RSA_WITH_SHA384) || atoi(ciphersuite_to_use) == atoi(TLS_RSA_WITH_SHA384)){
        evp_md = EVP_sha384();
    }
    else {
        evp_md = EVP_sha512();
    }
    
    
     // Compute the hash of the log
    fclose(log_server); log_server = fopen("./log/log_server.txt","r");
    compute_hash_log(log_server, evp_md, (unsigned char *) master_secret, 48, hash_server_log);
    fclose(log_server); log_server = fopen("./log/log_server.txt","a");
	// Send finish
	send_message (channel, 4, TLS_VERSION, TLS_HANDSHAKE , TLS_FINISHED , hash_server_log);
	send_message (log_server, 5, sending, TLS_VERSION, TLS_HANDSHAKE , TLS_FINISHED , hash_server_log);
	fclose(channel);
	return 1;
}
예제 #8
0
static const EVP_MD *getEVPMD(int hashalgo)
{
    switch (hashalgo) {

    case PGPHASHALGO_MD5:
        return EVP_md5();

    case PGPHASHALGO_SHA1:
        return EVP_sha1();

    case PGPHASHALGO_SHA256:
        return EVP_sha256();

    case PGPHASHALGO_SHA384:
        return EVP_sha384();

    case PGPHASHALGO_SHA512:
        return EVP_sha512();

    case PGPHASHALGO_SHA224:
        return EVP_sha224();

    default:
        return EVP_md_null();
    }
}
bool OpensslManager::HMACString(Openssl_Hash algorithm, char *key, int key_len, unsigned char *input, int input_len, unsigned char *output, unsigned int *outlength)
{
	switch(algorithm)
	{
		case Openssl_Hash_MD5:
			HMAC(EVP_md5(), key, key_len, input, input_len, output, outlength);
			return true;
		case Openssl_Hash_MD4:
			HMAC(EVP_md4(), key, key_len, input, input_len, output, outlength);
			return true;
		case Openssl_Hash_SHA:
			HMAC(EVP_sha(), key, key_len, input, input_len, output, outlength);
			return true;
		case Openssl_Hash_SHA1:
			HMAC(EVP_sha1(), key, key_len, input, input_len, output, outlength);
			return true;
		case Openssl_Hash_SHA224:
			HMAC(EVP_sha224(), key, key_len, input, input_len, output, outlength);
			return true;
		case Openssl_Hash_SHA256:
			HMAC(EVP_sha256(), key, key_len, input, input_len, output, outlength);
			return true;
		case Openssl_Hash_SHA384:
			HMAC(EVP_sha384(), key, key_len, input, input_len, output, outlength);
			return true;
		case Openssl_Hash_SHA512:
			HMAC(EVP_sha512(), key, key_len, input, input_len, output, outlength);
			return true;
		case Openssl_Hash_RIPEMD160:
			HMAC(EVP_ripemd160(), key, key_len, input, input_len, output, outlength);
			return true;
	}
	return false;
}
int receive_exchange_key(FILE * log_server, char * ciphersuite_to_use, unsigned char * master_secret, char * premaster_secret, char * random_from_client, char * random_from_server){

    if(!decrypt_secret_RSA(log_server, premaster_secret)){
        printf("SERVER: decription failed\n");
        return 0;
    }
    
    const EVP_MD * evp_md;
    
    if(atoi(ciphersuite_to_use) == atoi(TLS_DHE_RSA_WITH_SHA224) || atoi(ciphersuite_to_use) == atoi(TLS_RSA_WITH_SHA224)){
        evp_md = EVP_sha224();
    }
    else if(atoi(ciphersuite_to_use) == atoi(TLS_RSA_WITH_SHA256) || atoi(ciphersuite_to_use) == atoi(TLS_DHE_RSA_WITH_SHA256)){
        evp_md = EVP_sha256();
    }
    else if(atoi(ciphersuite_to_use) == atoi(TLS_DHE_RSA_WITH_SHA384) || atoi(ciphersuite_to_use) == atoi(TLS_RSA_WITH_SHA384)){
        evp_md = EVP_sha384();
    }
    else {
        evp_md = EVP_sha512();
    }
    
	if(!compute_master_secret (master_secret, evp_md, random_from_client, random_from_server, premaster_secret, "master secret")){
		printf("SERVER: computing master_secret failed\n");
		return 0;
	}
	return 1;
}
예제 #11
0
파일: c_all.c 프로젝트: flrl/openbsd
void
OpenSSL_add_all_digests(void)
{
#ifndef OPENSSL_NO_MD4
	EVP_add_digest(EVP_md4());
#endif

#ifndef OPENSSL_NO_MD5
	EVP_add_digest(EVP_md5());
	EVP_add_digest_alias(SN_md5, "ssl2-md5");
	EVP_add_digest_alias(SN_md5, "ssl3-md5");
#endif

#if !defined(OPENSSL_NO_SHA) && !defined(OPENSSL_NO_SHA0)
	EVP_add_digest(EVP_sha());
#ifndef OPENSSL_NO_DSA
	EVP_add_digest(EVP_dss());
#endif
#endif
#if !defined(OPENSSL_NO_SHA) && !defined(OPENSSL_NO_SHA1)
	EVP_add_digest(EVP_sha1());
	EVP_add_digest_alias(SN_sha1, "ssl3-sha1");
	EVP_add_digest_alias(SN_sha1WithRSAEncryption, SN_sha1WithRSA);
#ifndef OPENSSL_NO_DSA
	EVP_add_digest(EVP_dss1());
	EVP_add_digest_alias(SN_dsaWithSHA1, SN_dsaWithSHA1_2);
	EVP_add_digest_alias(SN_dsaWithSHA1, "DSS1");
	EVP_add_digest_alias(SN_dsaWithSHA1, "dss1");
#endif
#ifndef OPENSSL_NO_ECDSA
	EVP_add_digest(EVP_ecdsa());
#endif
#endif

#ifndef OPENSSL_NO_GOST
	EVP_add_digest(EVP_gostr341194());
	EVP_add_digest(EVP_gost2814789imit());
	EVP_add_digest(EVP_streebog256());
	EVP_add_digest(EVP_streebog512());
#endif
#if !defined(OPENSSL_NO_MDC2) && !defined(OPENSSL_NO_DES)
	EVP_add_digest(EVP_mdc2());
#endif
#ifndef OPENSSL_NO_RIPEMD
	EVP_add_digest(EVP_ripemd160());
	EVP_add_digest_alias(SN_ripemd160, "ripemd");
	EVP_add_digest_alias(SN_ripemd160, "rmd160");
#endif
#ifndef OPENSSL_NO_SHA256
	EVP_add_digest(EVP_sha224());
	EVP_add_digest(EVP_sha256());
#endif
#ifndef OPENSSL_NO_SHA512
	EVP_add_digest(EVP_sha384());
	EVP_add_digest(EVP_sha512());
#endif
#ifndef OPENSSL_NO_WHIRLPOOL
	EVP_add_digest(EVP_whirlpool());
#endif
}
예제 #12
0
파일: s2n_prf.c 프로젝트: alexw91/s2n
static int s2n_evp_hmac_p_hash_init(struct s2n_prf_working_space *ws, s2n_hmac_algorithm alg, struct s2n_blob *secret)
{
    /* Initialize the message digest */
    switch (alg) {
    case S2N_HMAC_SSLv3_MD5:
    case S2N_HMAC_MD5:
        ws->tls.p_hash.evp_hmac.evp_digest.md = EVP_md5();
        break;
    case S2N_HMAC_SSLv3_SHA1:
    case S2N_HMAC_SHA1:
        ws->tls.p_hash.evp_hmac.evp_digest.md = EVP_sha1();
        break;
    case S2N_HMAC_SHA224:
        ws->tls.p_hash.evp_hmac.evp_digest.md = EVP_sha224();
        break;
    case S2N_HMAC_SHA256:
        ws->tls.p_hash.evp_hmac.evp_digest.md = EVP_sha256();
        break;
    case S2N_HMAC_SHA384:
        ws->tls.p_hash.evp_hmac.evp_digest.md = EVP_sha384();
        break;
    case S2N_HMAC_SHA512:
        ws->tls.p_hash.evp_hmac.evp_digest.md = EVP_sha512();
        break;
    default:
        S2N_ERROR(S2N_ERR_P_HASH_INVALID_ALGORITHM);
    }

    /* Initialize the mac key using the provided secret */
    notnull_check(ws->tls.p_hash.evp_hmac.mac_key = EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL, secret->data, secret->size));

    /* Initialize the message digest context with the above message digest and mac key */
    return s2n_evp_hmac_p_hash_digest_init(ws);
}
예제 #13
0
bool HMACAuth::setKey(const char* keyValue, int keyLen) {
    const EVP_MD* sslStruct = nullptr;

    switch (_authMethod) {
    case MD5:
        sslStruct = EVP_md5();
        break;

    case SHA1:
        sslStruct = EVP_sha1();
        break;

    case SHA224:
        sslStruct = EVP_sha224();
        break;

    case SHA256:
        sslStruct = EVP_sha256();
        break;

    case RIPEMD160:
        sslStruct = EVP_ripemd160();
        break;

    default:
        return false;
    }

    QMutexLocker lock(&_lock);
    return (bool) HMAC_Init_ex(_hmacContext, keyValue, keyLen, sslStruct, nullptr);
}
예제 #14
0
int fips_drbg_hmac_init(DRBG_CTX *dctx)
{
    const EVP_MD *md = NULL;
    DRBG_HMAC_CTX *hctx = &dctx->d.hmac;
    dctx->strength = 256;
    switch (dctx->type) {
    case NID_hmacWithSHA1:
        md = EVP_sha1();
        dctx->strength = 128;
        break;

    case NID_hmacWithSHA224:
        md = EVP_sha224();
        dctx->strength = 192;
        break;

    case NID_hmacWithSHA256:
        md = EVP_sha256();
        break;

    case NID_hmacWithSHA384:
        md = EVP_sha384();
        break;

    case NID_hmacWithSHA512:
        md = EVP_sha512();
        break;

    default:
        dctx->strength = 0;
        return -2;
    }
    dctx->instantiate = drbg_hmac_instantiate;
    dctx->reseed = drbg_hmac_reseed;
    dctx->generate = drbg_hmac_generate;
    dctx->uninstantiate = drbg_hmac_uninstantiate;
    hctx->hctx = HMAC_CTX_new();
    if (hctx->hctx == NULL)
        return -1;
    hctx->md = md;
    dctx->blocklength = M_EVP_MD_size(md);
    dctx->seedlen = M_EVP_MD_size(md);

    dctx->min_entropy = dctx->strength / 8;
    dctx->max_entropy = DRBG_MAX_LENGTH;

    dctx->min_nonce = dctx->min_entropy / 2;
    dctx->max_nonce = DRBG_MAX_LENGTH;

    dctx->max_pers = DRBG_MAX_LENGTH;
    dctx->max_adin = DRBG_MAX_LENGTH;

    dctx->max_request = 1 << 16;
    dctx->reseed_interval = 1 << 24;

    return 1;
}
int change_cipher_spec(FILE * log_server, unsigned char * master_secret, char * ciphersuite_to_use){

	FILE* channel = fopen(link_channel,"r");
	char * received_message = calloc(BUF_SIZE+1,sizeof(char));
	// Read data from channel
	read_channel (channel, received_message);
	fclose(channel);
	if(!strcmp(received_message,TLS_ERROR_OCCURRED)){
		closeConversation(log_server);
	}
    // Get the hash of the client_log
    unsigned char * hash_client_log = calloc(24, sizeof(unsigned char));
    unsigned char * hash_server_log = calloc(24, sizeof(unsigned char));
    get_block(received_message, 4, (char*) hash_client_log);
    
    const EVP_MD * evp_md;
    
    if(atoi(ciphersuite_to_use) == atoi(TLS_DHE_RSA_WITH_SHA224) || atoi(ciphersuite_to_use) == atoi(TLS_RSA_WITH_SHA224)){
        evp_md = EVP_sha224();
    }
    else if(atoi(ciphersuite_to_use) == atoi(TLS_RSA_WITH_SHA256) || atoi(ciphersuite_to_use) == atoi(TLS_DHE_RSA_WITH_SHA256)){
        evp_md = EVP_sha256();
    }
    else if(atoi(ciphersuite_to_use) == atoi(TLS_DHE_RSA_WITH_SHA384) || atoi(ciphersuite_to_use) == atoi(TLS_RSA_WITH_SHA384)){
        evp_md = EVP_sha384();
    }
    else {
        evp_md = EVP_sha512();
    }
    
    fclose(log_server); log_server = fopen("./log/log_server.txt","r");
    // Compute the hash of the log
    compute_hash_log(log_server, evp_md, (unsigned char *) master_secret, 48, hash_server_log);
    fclose(log_server); log_server = fopen("./log/log_server.txt","a");
    // Compare the two hash
	if(strcmp( (char*) hash_client_log, (char*) hash_server_log)){
		printf("SERVER: comparing hash log failed\n");
		free(received_message); free(hash_server_log);
		return 0;
	}
	else{
		// Save it in log_server
		send_message (log_server, 2, receiving, received_message);
		fprintf(log_server, "\n\n");
		free(received_message); free(hash_server_log);

		FILE* channel = fopen (link_channel,"w");

		// Send ChangeCipherSuite to the Server
		send_message (channel, 3, TLS_VERSION, TLS_HANDSHAKE, TLS_CHANGECIPHERSPEC);
		send_message (log_server, 4, sending , TLS_VERSION, TLS_HANDSHAKE, TLS_CHANGECIPHERSPEC);
		fprintf(log_server,  "\n\n");
		fclose (channel);
		return 1;
	}
}
예제 #16
0
	void DtlsTransport::GenerateFingerprints()
	{
		MS_TRACE();

		for (auto it = DtlsTransport::string2FingerprintAlgorithm.begin(); it != DtlsTransport::string2FingerprintAlgorithm.end(); ++it)
		{
			std::string algorithm_str = it->first;
			FingerprintAlgorithm algorithm = it->second;
			uint8_t binary_fingerprint[EVP_MAX_MD_SIZE];
			unsigned int size = 0;
			char hex_fingerprint[(EVP_MAX_MD_SIZE * 2) + 1];
			const EVP_MD* hash_function;
			int ret;

			switch (algorithm)
			{
				case FingerprintAlgorithm::SHA1:
					hash_function = EVP_sha1();
					break;
				case FingerprintAlgorithm::SHA224:
					hash_function = EVP_sha224();
					break;
				case FingerprintAlgorithm::SHA256:
					hash_function = EVP_sha256();
					break;
				case FingerprintAlgorithm::SHA384:
					hash_function = EVP_sha384();
					break;
				case FingerprintAlgorithm::SHA512:
					hash_function = EVP_sha512();
					break;
				default:
					MS_ABORT("unknown algorithm");
			}

			ret = X509_digest(DtlsTransport::certificate, hash_function, binary_fingerprint, &size);
			if (ret == 0)
			{
				MS_ERROR("X509_digest() failed");
				MS_THROW_ERROR("Fingerprints generation failed");
			}

			// Convert to hexadecimal format in lowecase without colons.
			for (unsigned int i = 0; i < size; i++)
			{
				std::sprintf(hex_fingerprint + (i * 2), "%.2x", binary_fingerprint[i]);
			}
			hex_fingerprint[size * 2] = '\0';

			MS_DEBUG("%-7s fingerprint: %s", algorithm_str.c_str(), hex_fingerprint);

			// Store in the JSON.
			DtlsTransport::localFingerprints[algorithm_str] = hex_fingerprint;
		}
	}
예제 #17
0
int
SSL_library_init(void)
{

#ifndef OPENSSL_NO_DES
	EVP_add_cipher(EVP_des_cbc());
	EVP_add_cipher(EVP_des_ede3_cbc());
#endif
#ifndef OPENSSL_NO_IDEA
	EVP_add_cipher(EVP_idea_cbc());
#endif
#ifndef OPENSSL_NO_RC4
	EVP_add_cipher(EVP_rc4());
#if !defined(OPENSSL_NO_MD5) && (defined(__x86_64) || defined(__x86_64__))
	EVP_add_cipher(EVP_rc4_hmac_md5());
#endif
#endif  
#ifndef OPENSSL_NO_RC2
	EVP_add_cipher(EVP_rc2_cbc());
	/* Not actually used for SSL/TLS but this makes PKCS#12 work
	 * if an application only calls SSL_library_init().
	 */
	EVP_add_cipher(EVP_rc2_40_cbc());
#endif
	EVP_add_cipher(EVP_aes_128_cbc());
	EVP_add_cipher(EVP_aes_192_cbc());
	EVP_add_cipher(EVP_aes_256_cbc());
	EVP_add_cipher(EVP_aes_128_gcm());
	EVP_add_cipher(EVP_aes_256_gcm());
	EVP_add_cipher(EVP_aes_128_cbc_hmac_sha1());
	EVP_add_cipher(EVP_aes_256_cbc_hmac_sha1());
#ifndef OPENSSL_NO_CAMELLIA
	EVP_add_cipher(EVP_camellia_128_cbc());
	EVP_add_cipher(EVP_camellia_256_cbc());
#endif

	EVP_add_digest(EVP_md5());
	EVP_add_digest_alias(SN_md5, "ssl2-md5");
	EVP_add_digest_alias(SN_md5, "ssl3-md5");
	EVP_add_digest(EVP_sha1()); /* RSA with sha1 */
	EVP_add_digest_alias(SN_sha1, "ssl3-sha1");
	EVP_add_digest_alias(SN_sha1WithRSAEncryption, SN_sha1WithRSA);
	EVP_add_digest(EVP_sha224());
	EVP_add_digest(EVP_sha256());
	EVP_add_digest(EVP_sha384());
	EVP_add_digest(EVP_sha512());
	EVP_add_digest(EVP_dss1()); /* DSA with sha1 */
	EVP_add_digest_alias(SN_dsaWithSHA1, SN_dsaWithSHA1_2);
	EVP_add_digest_alias(SN_dsaWithSHA1, "DSS1");
	EVP_add_digest_alias(SN_dsaWithSHA1, "dss1");
	EVP_add_digest(EVP_ecdsa());
	/* initialize cipher/digest methods table */
	ssl_load_ciphers();
	return (1);
}
예제 #18
0
void EVP_MD_do_all_sorted(void (*callback)(const EVP_MD *cipher,
                                           const char *name, const char *unused,
                                           void *arg),
                          void *arg) {
  callback(EVP_md4(), "MD4", NULL, arg);
  callback(EVP_md5(), "MD5", NULL, arg);
  callback(EVP_sha1(), "SHA1", NULL, arg);
  callback(EVP_sha224(), "SHA224", NULL, arg);
  callback(EVP_sha256(), "SHA256", NULL, arg);
  callback(EVP_sha384(), "SHA384", NULL, arg);
  callback(EVP_sha512(), "SHA512", NULL, arg);

  callback(EVP_md4(), "md4", NULL, arg);
  callback(EVP_md5(), "md5", NULL, arg);
  callback(EVP_sha1(), "sha1", NULL, arg);
  callback(EVP_sha224(), "sha224", NULL, arg);
  callback(EVP_sha256(), "sha256", NULL, arg);
  callback(EVP_sha384(), "sha384", NULL, arg);
  callback(EVP_sha512(), "sha512", NULL, arg);
}
void PBKDF2_HMAC_SHA_224(const char* pass, const unsigned char* salt, int32_t iterations, uint32_t outputBytes, char* hexResult, uint8_t* binResult)
{
    unsigned int i;
    unsigned char digest[outputBytes];
    PKCS5_PBKDF2_HMAC(pass, strlen(pass), salt, strlen(salt), iterations, EVP_sha224(), outputBytes, digest);
    for (i = 0; i < sizeof(digest); i++)
    {
        sprintf(hexResult + (i * 2), "%02x", 255 & digest[i]);
        binResult[i] = digest[i];
    };
}
ikptr
ikrt_openssl_evp_sha224 (ikpcb * pcb)
{
#ifdef HAVE_EVP_SHA224
  const EVP_MD *	rv;
  rv = EVP_sha224();
  return ika_pointer_alloc(pcb, (long)rv);
#else
  feature_failure(__func__);
#endif
}
예제 #21
0
	explicit Hmac(Hash::Name name = Hash::N_SHA1)
	{
		switch (name) {
		case Hash::N_SHA1: evp_ = EVP_sha1(); break;
		case Hash::N_SHA224: evp_ = EVP_sha224(); break;
		case Hash::N_SHA256: evp_ = EVP_sha256(); break;
		case Hash::N_SHA384: evp_ = EVP_sha384(); break;
		case Hash::N_SHA512: evp_ = EVP_sha512(); break;
		default:
			throw cybozu::Exception("crypto:Hmac:") << name;
		}
	}
예제 #22
0
void OpenSSL_add_all_digests(void)
  {
#ifndef OPENSSL_NO_MD2
  EVP_add_digest(EVP_md2());
#endif
#ifndef OPENSSL_NO_MD4
  EVP_add_digest(EVP_md4());
#endif
#ifndef OPENSSL_NO_MD5
  EVP_add_digest(EVP_md5());
  EVP_add_digest_alias(SN_md5,"ssl2-md5");
  EVP_add_digest_alias(SN_md5,"ssl3-md5");
#endif
#if !defined(OPENSSL_NO_SHA) && !defined(OPENSSL_NO_SHA0)
  EVP_add_digest(EVP_sha());
#ifndef OPENSSL_NO_DSA
  EVP_add_digest(EVP_dss());
#endif
#endif
#ifndef OPENSSL_NO_SHA
  EVP_add_digest(EVP_sha1());
  EVP_add_digest_alias(SN_sha1,"ssl3-sha1");
  EVP_add_digest_alias(SN_sha1WithRSAEncryption,SN_sha1WithRSA);
#ifndef OPENSSL_NO_DSA
  EVP_add_digest(EVP_dss1());
  EVP_add_digest_alias(SN_dsaWithSHA1,SN_dsaWithSHA1_2);
  EVP_add_digest_alias(SN_dsaWithSHA1,"DSS1");
  EVP_add_digest_alias(SN_dsaWithSHA1,"dss1");
#endif
#ifndef OPENSSL_NO_ECDSA
  EVP_add_digest(EVP_ecdsa());
#endif
#endif
#if !defined(OPENSSL_NO_MDC2) && !defined(OPENSSL_NO_DES)
  EVP_add_digest(EVP_mdc2());
#endif
#ifndef OPENSSL_NO_RIPEMD
  EVP_add_digest(EVP_ripemd160());
  EVP_add_digest_alias(SN_ripemd160,"ripemd");
  EVP_add_digest_alias(SN_ripemd160,"rmd160");
#endif
#ifndef OPENSSL_NO_SHA256
  EVP_add_digest(EVP_sha224());
  EVP_add_digest(EVP_sha256());
#endif
#ifndef OPENSSL_NO_SHA512
  EVP_add_digest(EVP_sha384());
  EVP_add_digest(EVP_sha512());
#endif
  }
예제 #23
0
const EVP_MD * hb_EVP_MD_par( int iParam )
{
   const EVP_MD * p;

   if( HB_ISCHAR( iParam ) )
      return EVP_get_digestbyname( hb_parc( iParam ) );

   switch( hb_parni( iParam ) )
   {
      case HB_EVP_MD_MD_NULL:    p = EVP_md_null();   break;
#ifndef OPENSSL_NO_MD4
      case HB_EVP_MD_MD4:        p = EVP_md4();       break;
#endif
#ifndef OPENSSL_NO_MD5
      case HB_EVP_MD_MD5:        p = EVP_md5();       break;
#endif
#ifndef OPENSSL_NO_SHA
#if OPENSSL_VERSION_NUMBER < 0x10100000L && \
    ! defined( LIBRESSL_VERSION_NUMBER )
      case HB_EVP_MD_SHA:        p = EVP_sha();       break;
#endif
      case HB_EVP_MD_SHA1:       p = EVP_sha1();      break;
#if OPENSSL_VERSION_NUMBER < 0x10100000L
      case HB_EVP_MD_DSS:        p = EVP_dss();       break;
      case HB_EVP_MD_DSS1:       p = EVP_dss1();      break;
#endif
#if OPENSSL_VERSION_NUMBER >= 0x00908000L && \
    OPENSSL_VERSION_NUMBER < 0x10100000L
      case HB_EVP_MD_ECDSA:      p = EVP_ecdsa();     break;
#endif
#endif
#ifndef OPENSSL_NO_SHA256
      case HB_EVP_MD_SHA224:     p = EVP_sha224();    break;
      case HB_EVP_MD_SHA256:     p = EVP_sha256();    break;
#endif
#ifndef OPENSSL_NO_SHA512
      case HB_EVP_MD_SHA384:     p = EVP_sha384();    break;
      case HB_EVP_MD_SHA512:     p = EVP_sha512();    break;
#endif
#ifndef OPENSSL_NO_RIPEMD
      case HB_EVP_MD_RIPEMD160:  p = EVP_ripemd160(); break;
#endif
      default:                   p = NULL;
   }

   return p;
}
예제 #24
0
/* HMAC-SHA224: generate hash of known digest value and compare to known
   precomputed correct hash
*/
static int FIPS_hmac_sha224_test()
    {
    unsigned char key[] = "etaonrishd";
    unsigned char iv[] = "Sample text";
    unsigned char kaval[EVP_MAX_MD_SIZE] =
	{0x75, 0x58, 0xd5, 0xbd, 0x55, 0x6d, 0x87, 0x0f, 0x75, 0xff, 0xbe, 0x1c, 0xb2, 0xf0, 0x20, 0x35,
	 0xe5, 0x62, 0x49, 0xb6, 0x94, 0xb9, 0xfc, 0x65, 0x34, 0x33, 0x3a, 0x19};

    unsigned char out[EVP_MAX_MD_SIZE];
    unsigned int outlen;

    ERR_clear_error();
    if (!HMAC(EVP_sha224(),key,sizeof(key)-1,iv,sizeof(iv)-1,out,&outlen)) return 0;
    if (memcmp(out,kaval,outlen))
        return 0;
    return 1;
    }
예제 #25
0
static const EVP_MD *dtlsFingerprintTypeToEVP(DTLS_FINGERPRINT_TYPE_T type) {
  switch(type) {
    case DTLS_FINGERPRINT_TYPE_MD5:
      return EVP_md5();
    //case DTLS_FINGERPRINT_TYPE_MD2:
    //  return EVP_md2();
    case DTLS_FINGERPRINT_TYPE_SHA1: 
      return EVP_sha1();
    case DTLS_FINGERPRINT_TYPE_SHA256: 
      return EVP_sha256();
    case DTLS_FINGERPRINT_TYPE_SHA512: 
      return EVP_sha512();
    case DTLS_FINGERPRINT_TYPE_SHA224: 
      return EVP_sha224();
    case DTLS_FINGERPRINT_TYPE_SHA384: 
      return EVP_sha384();
    default:
      return NULL;
  }
}
예제 #26
0
static int hb_EVP_MD_ptr_to_id( const EVP_MD * p )
{
   int n;

   if(      p == EVP_md_null()   ) n = HB_EVP_MD_MD_NULL;
#ifndef OPENSSL_NO_MD4
   else if( p == EVP_md4()       ) n = HB_EVP_MD_MD4;
#endif
#ifndef OPENSSL_NO_MD5
   else if( p == EVP_md5()       ) n = HB_EVP_MD_MD5;
#endif
#ifndef OPENSSL_NO_SHA
#if OPENSSL_VERSION_NUMBER < 0x10100000L && \
    ! defined( LIBRESSL_VERSION_NUMBER )
   else if( p == EVP_sha()       ) n = HB_EVP_MD_SHA;
#endif
   else if( p == EVP_sha1()      ) n = HB_EVP_MD_SHA1;
#if OPENSSL_VERSION_NUMBER < 0x10100000L
   else if( p == EVP_dss()       ) n = HB_EVP_MD_DSS;
   else if( p == EVP_dss1()      ) n = HB_EVP_MD_DSS1;
#endif
#if OPENSSL_VERSION_NUMBER >= 0x00908000L && \
    OPENSSL_VERSION_NUMBER < 0x10100000L
   else if( p == EVP_ecdsa()     ) n = HB_EVP_MD_ECDSA;
#endif
#endif
#ifndef OPENSSL_NO_SHA256
   else if( p == EVP_sha224()    ) n = HB_EVP_MD_SHA224;
   else if( p == EVP_sha256()    ) n = HB_EVP_MD_SHA256;
#endif
#ifndef OPENSSL_NO_SHA512
   else if( p == EVP_sha384()    ) n = HB_EVP_MD_SHA384;
   else if( p == EVP_sha512()    ) n = HB_EVP_MD_SHA512;
#endif
#ifndef OPENSSL_NO_RIPEMD
   else if( p == EVP_ripemd160() ) n = HB_EVP_MD_RIPEMD160;
#endif
   else                            n = HB_EVP_MD_UNSUPPORTED;

   return n;
}
예제 #27
0
파일: evpmd.c 프로젝트: ggargano/hbtest2
static int hb_EVP_MD_ptr_to_id( const EVP_MD * p )
{
   int n;

   if(      p == EVP_md_null()   ) n = HB_EVP_MD_MD_NULL;
#ifndef OPENSSL_NO_MD2
   else if( p == EVP_md2()       ) n = HB_EVP_MD_MD2;
#endif
#ifndef OPENSSL_NO_MD4
   else if( p == EVP_md4()       ) n = HB_EVP_MD_MD4;
#endif
#ifndef OPENSSL_NO_MD5
   else if( p == EVP_md5()       ) n = HB_EVP_MD_MD5;
#endif
#ifndef OPENSSL_NO_SHA
   else if( p == EVP_sha()       ) n = HB_EVP_MD_SHA;
   else if( p == EVP_sha1()      ) n = HB_EVP_MD_SHA1;
   else if( p == EVP_dss()       ) n = HB_EVP_MD_DSS;
   else if( p == EVP_dss1()      ) n = HB_EVP_MD_DSS1;
#if ! defined( HB_OPENSSL_OLD_OSX_ )
   else if( p == EVP_ecdsa()     ) n = HB_EVP_MD_ECDSA;
#endif
#endif
#ifndef OPENSSL_NO_SHA256
   else if( p == EVP_sha224()    ) n = HB_EVP_MD_SHA224;
   else if( p == EVP_sha256()    ) n = HB_EVP_MD_SHA256;
#endif
#ifndef OPENSSL_NO_SHA512
   else if( p == EVP_sha384()    ) n = HB_EVP_MD_SHA384;
   else if( p == EVP_sha512()    ) n = HB_EVP_MD_SHA512;
#endif
#ifndef OPENSSL_NO_MDC2
   else if( p == EVP_mdc2()      ) n = HB_EVP_MD_MDC2;
#endif
#ifndef OPENSSL_NO_RIPEMD
   else if( p == EVP_ripemd160() ) n = HB_EVP_MD_RIPEMD160;
#endif
   else                            n = HB_EVP_MD_UNSUPPORTED;

   return n;
}
예제 #28
0
파일: fips_md.c 프로젝트: vathpela/mallory
const EVP_MD *FIPS_get_digestbynid(int nid)
{
    switch (nid) {
    case NID_sha1:
        return EVP_sha1();

    case NID_sha224:
        return EVP_sha224();

    case NID_sha256:
        return EVP_sha256();

    case NID_sha384:
        return EVP_sha384();

    case NID_sha512:
        return EVP_sha512();

    default:
        return NULL;
    }
}
예제 #29
0
const EVP_MD *
eac_oid2md(int protocol)
{
    if (       protocol == NID_id_TA_ECDSA_SHA_1
            || protocol == NID_id_TA_RSA_v1_5_SHA_1
            || protocol == NID_id_TA_RSA_PSS_SHA_1) {
        return EVP_sha1();
    } else if (protocol == NID_id_TA_ECDSA_SHA_224) {
        return EVP_sha224();
    } else if (protocol == NID_id_TA_ECDSA_SHA_256
            || protocol == NID_id_TA_RSA_v1_5_SHA_256
            || protocol == NID_id_TA_RSA_PSS_SHA_256) {
        return EVP_sha256();
    } else if (protocol == NID_id_TA_ECDSA_SHA_384) {
        return EVP_sha384();
    } else if (protocol == NID_id_TA_ECDSA_SHA_512
            || protocol == NID_id_TA_RSA_v1_5_SHA_512
            || protocol == NID_id_TA_RSA_PSS_SHA_512) {
        return EVP_sha512();
    } else {
        log_err("Unknown protocol");
        return NULL;
    }
}
예제 #30
0
void
isc_hmacsha224_init(isc_hmacsha224_t *ctx, const unsigned char *key,
		    unsigned int len)
{
	HMAC_Init(ctx, (const void *) key, (int) len, EVP_sha224());
}