+ if (encdec <= 0)
+ {
+ if (mode == EVP_CIPH_GCM_MODE)
+ {
+ if(!EVP_DecryptInit_ex(ctx,c,NULL,NULL,NULL))
+ {
+ fprintf(stderr,"EncryptInit failed\n");
+ ERR_print_errors_fp(stderr);
+ test1_exit(10);
+ }
+ if(!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_IVLEN, in, NULL))
+ {
+ fprintf(stderr,"IV length set failed\n");
+ ERR_print_errors_fp(stderr);
+ test1_exit(11);
+ }
+ if(!EVP_DecryptInit_ex(ctx,NULL,NULL,key,iv))
+ {
+ fprintf(stderr,"Key/IV set failed\n");
+ ERR_print_errors_fp(stderr);
+ test1_exit(12);
+ }
+ if (!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_TAG, tn, (void *)tag))
+ {
+ fprintf(stderr,"Set tag failed\n");
+ ERR_print_errors_fp(stderr);
+ test1_exit(14);
+ }
+ if (an && !EVP_DecryptUpdate(ctx,NULL,&outl,aad,an))
+ {
+ fprintf(stderr,"AAD set failed\n");
+ ERR_print_errors_fp(stderr);
+ test1_exit(13);
+ }
+ }
+ else if (mode == EVP_CIPH_CCM_MODE)
+ {
+ if(!EVP_DecryptInit_ex(ctx,c,NULL,NULL,NULL))
+ {
+ fprintf(stderr,"DecryptInit failed\n");
+ ERR_print_errors_fp(stderr);
+ test1_exit(10);
+ }
+ if(!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_CCM_SET_IVLEN, in, NULL))
+ {
+ fprintf(stderr,"IV length set failed\n");
+ ERR_print_errors_fp(stderr);
+ test1_exit(11);
+ }
+ if(!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_CCM_SET_TAG, tn, (void *)tag))
+ {
+ fprintf(stderr,"Tag length set failed\n");
+ ERR_print_errors_fp(stderr);
+ test1_exit(11);
+ }
+ if(!EVP_DecryptInit_ex(ctx,NULL,NULL,key,iv))
+ {
+ fprintf(stderr,"Key/Nonce set failed\n");
+ ERR_print_errors_fp(stderr);
+ test1_exit(12);
+ }
+ if (!EVP_DecryptUpdate(ctx,NULL,&outl,NULL,pn))
+ {
+ fprintf(stderr,"Plaintext length set failed\n");
+ ERR_print_errors_fp(stderr);
+ test1_exit(12);
+ }
+ if (an && !EVP_EncryptUpdate(ctx,NULL,&outl,aad,an))
+ {
+ fprintf(stderr,"AAD set failed\n");
+ ERR_print_errors_fp(stderr);
+ test1_exit(13);
+ }
+ }
+ else if (mode == EVP_CIPH_WRAP_MODE)
+ {
+ if(!EVP_DecryptInit_ex(ctx,c,NULL,key,in ? iv : NULL))
+ {
+ fprintf(stderr,"EncryptInit failed\n");
+ ERR_print_errors_fp(stderr);
+ test1_exit(10);
+ }
+ }
+ else if(!EVP_DecryptInit_ex(ctx,c,NULL,key,iv))
+ {
+ fprintf(stderr,"DecryptInit failed\n");
+ ERR_print_errors_fp(stderr);
+ test1_exit(11);
+ }
+ EVP_CIPHER_CTX_set_padding(ctx,0);