X-Git-Url: https://git.openssl.org/?p=openssl.git;a=blobdiff_plain;f=fips%2Faes%2Ffips_aesavs.c;h=bbdb93aab933022c8c36ab291dd9e42b03989a24;hp=1f302a59fcc464e1f316b931a74e2605fab830ca;hb=69569dd1684ec67ccf8f0a7007872ebbb7a724d5;hpb=7c8ced94c32131f24d469d2899f3339f77c47aa1 diff --git a/fips/aes/fips_aesavs.c b/fips/aes/fips_aesavs.c index 1f302a59fc..bbdb93aab9 100644 --- a/fips/aes/fips_aesavs.c +++ b/fips/aes/fips_aesavs.c @@ -152,7 +152,7 @@ static int AESTest(EVP_CIPHER_CTX *ctx, } } - else if (strncasecmp(amode, "OFB", 3) == 0) + else if (fips_strncasecmp(amode, "OFB", 3) == 0) { switch (akeysz) { @@ -213,14 +213,14 @@ static int AESTest(EVP_CIPHER_CTX *ctx, printf("Invalid key size: %d\n", akeysz); return 0; } - if (EVP_CipherInit_ex(ctx, cipher, NULL, aKey, iVec, dir) <= 0) + if (FIPS_cipherinit(ctx, cipher, aKey, iVec, dir) <= 0) return 0; if(!strcasecmp(amode,"CFB1")) M_EVP_CIPHER_CTX_set_flags(ctx, EVP_CIPH_FLAG_LENGTH_BITS); if (dir) - EVP_Cipher(ctx, ciphertext, plaintext, len); + FIPS_cipher(ctx, ciphertext, plaintext, len); else - EVP_Cipher(ctx, plaintext, ciphertext, len); + FIPS_cipher(ctx, plaintext, ciphertext, len); return 1; } @@ -254,7 +254,7 @@ static int do_mct(char *amode, int i, j, n, n1, n2; int imode = 0, nkeysz = akeysz/8; EVP_CIPHER_CTX ctx; - EVP_CIPHER_CTX_init(&ctx); + FIPS_cipher_ctx_init(&ctx); if (len > 32) { @@ -283,7 +283,7 @@ static int do_mct(char *amode, /* printf("Iteration %d\n", i); */ if (i > 0) { - fprintf(rfp,"COUNT = %d\n",i); + fprintf(rfp,"COUNT = %d" RESP_EOL ,i); OutputValue("KEY",key[i],nkeysz,rfp,0); if (imode != ECB) /* ECB */ OutputValue("IV",iv[i],AES_BLOCK_SIZE,rfp,0); @@ -310,12 +310,12 @@ static int do_mct(char *amode, { if (dir == XENCRYPT) { - EVP_Cipher(&ctx, ctext[j], ptext[j], len); + FIPS_cipher(&ctx, ctext[j], ptext[j], len); memcpy(ptext[j+1], ctext[j], len); } else { - EVP_Cipher(&ctx, ptext[j], ctext[j], len); + FIPS_cipher(&ctx, ptext[j], ctext[j], len); memcpy(ctext[j+1], ptext[j], len); } } @@ -338,12 +338,12 @@ static int do_mct(char *amode, { if (dir == XENCRYPT) { - EVP_Cipher(&ctx, ctext[j], ptext[j], len); + FIPS_cipher(&ctx, ctext[j], ptext[j], len); memcpy(ptext[j+1], ctext[j-1], len); } else { - EVP_Cipher(&ctx, ptext[j], ctext[j], len); + FIPS_cipher(&ctx, ptext[j], ctext[j], len); memcpy(ctext[j+1], ptext[j-1], len); } } @@ -359,9 +359,9 @@ static int do_mct(char *amode, else { if (dir == XENCRYPT) - EVP_Cipher(&ctx, ctext[j], ptext[j], len); + FIPS_cipher(&ctx, ctext[j], ptext[j], len); else - EVP_Cipher(&ctx, ptext[j], ctext[j], len); + FIPS_cipher(&ctx, ptext[j], ctext[j], len); } if (dir == XENCRYPT) { @@ -393,9 +393,9 @@ static int do_mct(char *amode, else { if (dir == XENCRYPT) - EVP_Cipher(&ctx, ctext[j], ptext[j], len); + FIPS_cipher(&ctx, ctext[j], ptext[j], len); else - EVP_Cipher(&ctx, ptext[j], ctext[j], len); + FIPS_cipher(&ctx, ptext[j], ctext[j], len); } if(dir == XENCRYPT) @@ -419,7 +419,7 @@ static int do_mct(char *amode, /* Output Ciphertext | Plaintext */ OutputValue(t_tag[dir],dir ? ctext[j] : ptext[j],len,rfp, imode == CFB1); - fprintf(rfp, "\n"); /* add separator */ + fprintf(rfp, RESP_EOL); /* add separator */ /* Compute next KEY */ if (dir == XENCRYPT) @@ -535,7 +535,7 @@ static int do_mct(char *amode, } } } - + FIPS_cipher_ctx_cleanup(&ctx); return ret; } @@ -565,7 +565,7 @@ static int proc_file(char *rqfile, char *rspfile) unsigned char ciphertext[2048]; char *rp; EVP_CIPHER_CTX ctx; - EVP_CIPHER_CTX_init(&ctx); + FIPS_cipher_ctx_init(&ctx); if (!rqfile || !(*rqfile)) { @@ -622,7 +622,7 @@ static int proc_file(char *rqfile, char *rspfile) } else { - fputs(ibuf, rfp); + copy_line(ibuf, rfp); ++ step; } } @@ -638,11 +638,12 @@ static int proc_file(char *rqfile, char *rspfile) if (akeysz) { /* insert current time & date */ time_t rtim = time(0); - fprintf(rfp, "# %s", ctime(&rtim)); + fputs("# ", rfp); + copy_line(ctime(&rtim), rfp); } else { - fputs(ibuf, rfp); + copy_line(ibuf, rfp); if (strncmp(pp, "AESVS ", 6) == 0) { strcpy(algo, "AES"); @@ -661,7 +662,7 @@ static int proc_file(char *rqfile, char *rspfile) if (VERBOSE) printf("Test = %s, Mode = %s\n", atest, amode); } - else if (strncasecmp(pp, "Key Length : ", 13) == 0) + else if (fips_strncasecmp(pp, "Key Length : ", 13) == 0) { akeysz = atoi(pp+13); if (VERBOSE) @@ -674,11 +675,11 @@ static int proc_file(char *rqfile, char *rspfile) case 1: /* [ENCRYPT] | [DECRYPT] */ if (ibuf[0] == '[') { - fputs(ibuf, rfp); + copy_line(ibuf, rfp); ++step; - if (strncasecmp(ibuf, "[ENCRYPT]", 9) == 0) + if (fips_strncasecmp(ibuf, "[ENCRYPT]", 9) == 0) dir = 1; - else if (strncasecmp(ibuf, "[DECRYPT]", 9) == 0) + else if (fips_strncasecmp(ibuf, "[DECRYPT]", 9) == 0) dir = 0; else { @@ -697,13 +698,13 @@ static int proc_file(char *rqfile, char *rspfile) step = 2; case 2: /* KEY = xxxx */ - fputs(ibuf, rfp); + copy_line(ibuf, rfp); if(*ibuf == '\n') break; - if(!strncasecmp(ibuf,"COUNT = ",8)) + if(!fips_strncasecmp(ibuf,"COUNT = ",8)) break; - if (strncasecmp(ibuf, "KEY = ", 6) != 0) + if (fips_strncasecmp(ibuf, "KEY = ", 6) != 0) { printf("Missing KEY\n"); err = 1; @@ -729,8 +730,8 @@ static int proc_file(char *rqfile, char *rspfile) break; case 3: /* IV = xxxx */ - fputs(ibuf, rfp); - if (strncasecmp(ibuf, "IV = ", 5) != 0) + copy_line(ibuf, rfp); + if (fips_strncasecmp(ibuf, "IV = ", 5) != 0) { printf("Missing IV\n"); err = 1; @@ -750,8 +751,8 @@ static int proc_file(char *rqfile, char *rspfile) break; case 4: /* PLAINTEXT = xxxx */ - fputs(ibuf, rfp); - if (strncasecmp(ibuf, "PLAINTEXT = ", 12) != 0) + copy_line(ibuf, rfp); + if (fips_strncasecmp(ibuf, "PLAINTEXT = ", 12) != 0) { printf("Missing PLAINTEXT\n"); err = 1; @@ -779,7 +780,7 @@ static int proc_file(char *rqfile, char *rspfile) if(do_mct(amode, akeysz, aKey, iVec, dir, (unsigned char*)plaintext, len, rfp) < 0) - EXIT(1); + err = 1; } else { @@ -794,8 +795,8 @@ static int proc_file(char *rqfile, char *rspfile) break; case 5: /* CIPHERTEXT = xxxx */ - fputs(ibuf, rfp); - if (strncasecmp(ibuf, "CIPHERTEXT = ", 13) != 0) + copy_line(ibuf, rfp); + if (fips_strncasecmp(ibuf, "CIPHERTEXT = ", 13) != 0) { printf("Missing KEY\n"); err = 1; @@ -839,7 +840,7 @@ static int proc_file(char *rqfile, char *rspfile) } else if (strcmp(atest, "MCT") != 0) { /* MCT already added terminating nl */ - fputs(ibuf, rfp); + copy_line(ibuf, rfp); } step = 1; break; @@ -849,6 +850,7 @@ static int proc_file(char *rqfile, char *rspfile) fclose(rfp); if (afp) fclose(afp); + FIPS_cipher_ctx_cleanup(&ctx); return err; } @@ -861,18 +863,18 @@ static int proc_file(char *rqfile, char *rspfile) aes_test -d xxxxx.xxx The default is: -d req.txt --------------------------------------------------*/ +#ifdef FIPS_ALGVS +int fips_aesavs_main(int argc, char **argv) +#else int main(int argc, char **argv) +#endif { char *rqlist = "req.txt", *rspfile = NULL; FILE *fp = NULL; char fn[250] = "", rfn[256] = ""; int f_opt = 0, d_opt = 1; - fips_set_error_print(); + fips_algtest_init(); -#ifdef OPENSSL_FIPS - if(!FIPS_mode_set(1)) - EXIT(1); -#endif if (argc > 1) { if (strcasecmp(argv[1], "-d") == 0) @@ -918,7 +920,7 @@ int main(int argc, char **argv) if (proc_file(rfn, rspfile)) { printf(">>> Processing failed for: %s <<<\n", rfn); - EXIT(1); + return 1; } } fclose(fp); @@ -932,7 +934,6 @@ int main(int argc, char **argv) printf(">>> Processing failed for: %s <<<\n", fn); } } - EXIT(0); return 0; }