Fix typo in CONTRIBUTING.md
[openssl.git] / test / aesgcmtest.c
index c616438b0051c7f380dd0b315dab17605713a8a0..25e6f65fa97e4b970f8277fb0988d95df38c5314 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
  *
  * Licensed under the Apache License 2.0 (the "License").  You may not use
  * this file except in compliance with the License.  You can obtain a copy
@@ -54,10 +54,11 @@ static int do_encrypt(unsigned char *iv_gen, unsigned char *ct, int *ct_len,
           && TEST_true(EVP_EncryptUpdate(ctx, ct, ct_len, gcm_pt,
                                          sizeof(gcm_pt)) > 0)
           && TEST_true(EVP_EncryptFinal_ex(ctx, outbuf, &outlen) > 0)
+          && TEST_int_eq(EVP_CIPHER_CTX_get_tag_length(ctx), 16)
           && TEST_true(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_GET_TAG, 16,
                                            tag) > 0)
           && TEST_true(iv_gen == NULL
-                  || EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GET_IV, 12, iv_gen) > 0);
+                  || EVP_CIPHER_CTX_get_original_iv(ctx, iv_gen, 12));
     EVP_CIPHER_CTX_free(ctx);
     return ret;
 }
@@ -75,6 +76,7 @@ static int do_decrypt(const unsigned char *iv, const unsigned char *ct,
               && TEST_true(EVP_DecryptInit_ex(ctx, EVP_aes_256_gcm(), NULL,
                                               NULL, NULL) > 0)
               && TEST_true(EVP_DecryptInit_ex(ctx, NULL, NULL, gcm_key, iv) > 0)
+              && TEST_int_eq(EVP_CIPHER_CTX_get_tag_length(ctx), 16)
               && TEST_true(EVP_DecryptUpdate(ctx, NULL, &outlen, gcm_aad,
                                              sizeof(gcm_aad)) > 0)
               && TEST_true(EVP_DecryptUpdate(ctx, pt, &ptlen, ct,
@@ -100,7 +102,20 @@ static int kat_test(void)
            && do_decrypt(gcm_iv, ct, ctlen, tag, taglen);
 }
 
-#ifdef FIPS_MODE
+static int badkeylen_test(void)
+{
+    int ret;
+    EVP_CIPHER_CTX *ctx = NULL;
+    const EVP_CIPHER *cipher;
+
+    ret = TEST_ptr(cipher = EVP_aes_192_gcm())
+          && TEST_ptr(ctx = EVP_CIPHER_CTX_new())
+          && TEST_true(EVP_EncryptInit_ex(ctx, cipher, NULL, NULL, NULL))
+          && TEST_int_le(EVP_CIPHER_CTX_set_key_length(ctx, 2), 0);
+    EVP_CIPHER_CTX_free(ctx);
+    return ret;
+}
+
 static int ivgen_test(void)
 {
     unsigned char iv_gen[16];
@@ -111,13 +126,11 @@ static int ivgen_test(void)
     return do_encrypt(iv_gen, ct, &ctlen, tag, &taglen)
            && do_decrypt(iv_gen, ct, ctlen, tag, taglen);
 }
-#endif /* FIPS_MODE */
 
 int setup_tests(void)
 {
     ADD_TEST(kat_test);
-#ifdef FIPS_MODE
+    ADD_TEST(badkeylen_test);
     ADD_TEST(ivgen_test);
-#endif /* FIPS_MODE */
     return 1;
 }