add 3DES fips mode

This commit is contained in:
toddouska
2014-03-24 13:37:52 -07:00
parent 8889e17489
commit 0ea10a4388
13 changed files with 202 additions and 93 deletions

View File

@@ -360,9 +360,7 @@ int CRYPT_TDES_KeySet(CRYPT_TDES_CTX* tdes, const unsigned char* key,
if (tdes == NULL || key == NULL)
return BAD_FUNC_ARG;
Des3_SetKey((Des3*)tdes, key, iv, dir);
return 0;
return Des3_SetKey((Des3*)tdes, key, iv, dir);
}
@@ -372,9 +370,7 @@ int CRYPT_TDES_IvSet(CRYPT_TDES_CTX* tdes, const unsigned char* iv)
if (tdes == NULL || iv == NULL)
return BAD_FUNC_ARG;
Des3_SetIV((Des3*)tdes, iv);
return 0;
return Des3_SetIV((Des3*)tdes, iv);
}
@@ -385,9 +381,7 @@ int CRYPT_TDES_CBC_Encrypt(CRYPT_TDES_CTX* tdes, unsigned char* out,
if (tdes == NULL || out == NULL || in == NULL)
return BAD_FUNC_ARG;
Des3_CbcEncrypt((Des3*)tdes, out, in, inSz);
return 0;
return Des3_CbcEncrypt((Des3*)tdes, out, in, inSz);
}
@@ -398,9 +392,7 @@ int CRYPT_TDES_CBC_Decrypt(CRYPT_TDES_CTX* tdes, unsigned char* out,
if (tdes == NULL || out == NULL || in == NULL)
return BAD_FUNC_ARG;
Des3_CbcDecrypt((Des3*)tdes, out, in, inSz);
return 0;
return Des3_CbcDecrypt((Des3*)tdes, out, in, inSz);
}

View File

@@ -592,14 +592,22 @@ static int check_des3(void)
printf("mcapi tdes key set failed\n");
return -1;
}
Des3_SetKey(&defDes3, key, iv, DES_ENCRYPTION);
ret = Des3_SetKey(&defDes3, key, iv, DES_ENCRYPTION);
if (ret != 0) {
printf("default des3 key set failed\n");
return -1;
}
ret = CRYPT_TDES_CBC_Encrypt(&mcDes3, out1, ourData, TDES_TEST_SIZE);
if (ret != 0) {
printf("mcapi tdes cbc encrypt failed\n");
return -1;
}
Des3_CbcEncrypt(&defDes3, out2, ourData, TDES_TEST_SIZE);
ret = Des3_CbcEncrypt(&defDes3, out2, ourData, TDES_TEST_SIZE);
if (ret != 0) {
printf("mcapi default tdes cbc encrypt failed\n");
return -1;
}
if (memcmp(out1, out2, TDES_TEST_SIZE) != 0) {
printf("mcapi tdes cbc encrypt cmp failed\n");
@@ -612,14 +620,22 @@ static int check_des3(void)
printf("mcapi tdes key set failed\n");
return -1;
}
Des3_SetKey(&defDes3, key, iv, DES_DECRYPTION);
ret = Des3_SetKey(&defDes3, key, iv, DES_DECRYPTION);
if (ret != 0) {
printf("default des3 key set failed\n");
return -1;
}
ret = CRYPT_TDES_CBC_Decrypt(&mcDes3, out2, out1, TDES_TEST_SIZE);
if (ret != 0) {
printf("mcapi tdes cbc decrypt failed\n");
return -1;
}
Des3_CbcDecrypt(&defDes3, out1, out1, TDES_TEST_SIZE);
ret = Des3_CbcDecrypt(&defDes3, out1, out1, TDES_TEST_SIZE);
if (ret != 0) {
printf("mcapi default tdes cbc decrypt failed\n");
return -1;
}
if (memcmp(out1, out2, TDES_TEST_SIZE) != 0) {
printf("mcapi tdes cbc decrypt cmp failed\n");