Exemplo n.º 1
0
const EVP_CIPHER *evp_get_fips_cipher(const EVP_CIPHER *cipher)
{
    int nid = cipher->nid;
    if (nid == NID_undef)
        return FIPS_evp_enc_null();
    else
        return FIPS_get_cipherbynid(nid);
}
Exemplo n.º 2
0
int FIPS_selftest_cmac()
{
    size_t n, outlen;
    unsigned char out[32];
    const EVP_CIPHER *cipher;
    CMAC_CTX *ctx = CMAC_CTX_new();
    const CMAC_KAT *t;
    int rv = 1;

    for (n = 0, t = vector; n < sizeof(vector) / sizeof(vector[0]); n++, t++) {
        cipher = FIPS_get_cipherbynid(t->nid);
        if (!cipher) {
            rv = -1;
            goto err;
        }
        if (!CMAC_Init(ctx, t->key, t->keysize / 8, cipher, 0)) {
            rv = -1;
            goto err;
        }
        if (!CMAC_Update(ctx, t->msg, t->msgsize / 8)) {
            rv = -1;
            goto err;
        }

        if (!CMAC_Final(ctx, out, &outlen)) {
            rv = -1;
            goto err;
        }
        CMAC_CTX_cleanup(ctx);

        if (outlen < t->macsize / 8 || memcmp(out, t->mac, t->macsize / 8)) {
            rv = 0;
        }
    }

 err:
    CMAC_CTX_free(ctx);

    if (rv == -1) {
        rv = 0;
    }
    if (!rv)
        FIPSerr(FIPS_F_FIPS_SELFTEST_CMAC, FIPS_R_SELFTEST_FAILED);

    return rv;
}
Exemplo n.º 3
0
int FIPS_selftest_cmac()
	{
	size_t n, outlen;
	unsigned char    out[32];
	const EVP_CIPHER *cipher;
	CMAC_CTX *ctx = CMAC_CTX_new();
	const CMAC_KAT *t;
	int subid = -1, rv = 1;

	for(n=0,t=vector; n<sizeof(vector)/sizeof(vector[0]); n++,t++)
		{
		cipher = FIPS_get_cipherbynid(t->nid);
		if (!cipher)
			{
			rv = -1;
			goto err;
			}
		subid = M_EVP_CIPHER_nid(cipher);
		if (!fips_post_started(FIPS_TEST_CMAC, subid, 0))
			continue;
		if (!CMAC_Init(ctx, t->key, t->keysize/8, cipher, 0))
			{
			rv = -1;
			goto err;
			}
		if (!CMAC_Update(ctx, t->msg, t->msgsize/8))
			{
			rv = -1;
			goto err;
			}
			
		if (!fips_post_corrupt(FIPS_TEST_CMAC, subid, NULL))
			{
			if (!CMAC_Update(ctx, t->msg, 1))
				{
				rv = -1;
				goto err;
				}
			}
		if (!CMAC_Final(ctx, out, &outlen))
			{
			rv = -1;
			goto err;
			}
		CMAC_CTX_cleanup(ctx);

		if(outlen < t->macsize/8 || memcmp(out,t->mac,t->macsize/8))
			{
			fips_post_failed(FIPS_TEST_CMAC, subid, NULL);
		    	rv = 0;
		    	}
		else if (!fips_post_success(FIPS_TEST_CMAC, subid, NULL))
			{
			rv = 0;
			goto err;
			}
		}

	err:
	CMAC_CTX_free(ctx);

	if (rv == -1)
		{
		fips_post_failed(FIPS_TEST_CMAC, subid, NULL);
		rv = 0;
		}
	if (!rv)
		   FIPSerr(FIPS_F_FIPS_SELFTEST_CMAC,FIPS_R_SELFTEST_FAILED);

	return rv;
	}