- EVP_CipherInit_ex(&ctx, NULL, NULL, key, iv, 1);
+ if (encrypt == 1)
+ {
+ static unsigned char iv_fixed[4] = {1,2,3,4};
+ if (!iv)
+ iv = OPENSSL_malloc(ivlen);
+ EVP_CipherInit_ex(&ctx, NULL, NULL, key, NULL, 1);
+ EVP_CIPHER_CTX_ctrl(&ctx,
+ EVP_CTRL_GCM_SET_IV_FIXED,
+ 4, iv_fixed);
+ if (!EVP_CIPHER_CTX_ctrl(&ctx,
+ EVP_CTRL_GCM_IV_GEN, 0, iv))
+ {
+ fprintf(stderr, "IV gen error\n");
+ exit(1);
+ }
+ OutputValue("IV", iv, ivlen, stdout, 0);
+ }
+ else
+ EVP_CipherInit_ex(&ctx, NULL, NULL, key, iv, 1);
+