]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
tests: mini-alignment moved to modern nettle API
authorNikos Mavrogiannopoulos <nmav@redhat.com>
Mon, 23 Sep 2019 19:11:53 +0000 (21:11 +0200)
committerNikos Mavrogiannopoulos <nmav@redhat.com>
Mon, 23 Sep 2019 19:35:31 +0000 (21:35 +0200)
That is, it no longer uses the deprecated API, and it is also
removed to cipher-alignment for clarity.

Resolves: #835

Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
tests/Makefile.am
tests/cipher-alignment.c [moved from tests/mini-alignment.c with 96% similarity]

index 075c2728f392f10b54cf3d99149f2180cf92b4b6..f08f76d0dd439591be5d6b67533eba26cbfd0389 100644 (file)
@@ -174,7 +174,7 @@ ctests += mini-record-2 simple gnutls_hmac_fast set_pkcs12_cred cert certuniquei
         tls13-cert-key-exchange x509-cert-callback-ocsp gnutls_ocsp_resp_list_import2 \
         server-sign-md5-rep privkey-keygen mini-tls-nonblock no-signal pkcs7-gen dtls-etm \
         x509sign-verify-rsa x509sign-verify-ecdsa x509sign-verify-gost \
-        mini-alignment oids atfork prf psk-file priority-init2 post-client-hello-change-prio \
+        cipher-alignment oids atfork prf psk-file priority-init2 post-client-hello-change-prio \
         status-request status-request-ok rfc7633-missing sign-verify-ext \
         fallback-scsv pkcs8-key-decode urls dtls-rehandshake-cert rfc7633-ok \
         key-usage-rsa key-usage-ecdhe-rsa mini-session-verify-function auto-verify \
similarity index 96%
rename from tests/mini-alignment.c
rename to tests/cipher-alignment.c
index 96f3d5b93a59d490086c5a5e0739fd7883caad16..bc5239281ad4f12c4a3fd9e49097a6eb553134dc 100644 (file)
@@ -68,10 +68,6 @@ static void tls_log_func(int level, const char *str)
                str);
 }
 
-/* A very basic TLS client, with anonymous authentication.
- */
-
-
 #define MAX_BUF 1024
 #define MSG "Hello TLS"
 
@@ -125,7 +121,7 @@ static unsigned char key_pem[] =
 const gnutls_datum_t key = { key_pem, sizeof(key_pem) };
 
 struct myaes_ctx {
-       struct aes_ctx aes;
+       struct aes128_ctx aes;
        unsigned char iv[16];
        int enc;
 };
@@ -133,10 +129,7 @@ struct myaes_ctx {
 static int
 myaes_init(gnutls_cipher_algorithm_t algorithm, void **_ctx, int enc)
 {
-       /* we use key size to distinguish */
-       if (algorithm != GNUTLS_CIPHER_AES_128_CBC
-           && algorithm != GNUTLS_CIPHER_AES_192_CBC
-           && algorithm != GNUTLS_CIPHER_AES_256_CBC)
+       if (algorithm != GNUTLS_CIPHER_AES_128_CBC)
                return GNUTLS_E_INVALID_REQUEST;
 
        *_ctx = calloc(1, sizeof(struct myaes_ctx));
@@ -154,10 +147,12 @@ myaes_setkey(void *_ctx, const void *userkey, size_t keysize)
 {
        struct myaes_ctx *ctx = _ctx;
 
+       assert(keysize == 16);
+
        if (ctx->enc)
-               aes_set_encrypt_key(&ctx->aes, keysize, userkey);
+               aes128_set_encrypt_key(&ctx->aes, userkey);
        else
-               aes_set_decrypt_key(&ctx->aes, keysize, userkey);
+               aes128_set_decrypt_key(&ctx->aes, userkey);
 
        return 0;
 }
@@ -186,7 +181,7 @@ myaes_encrypt(void *_ctx, const void *src, size_t src_size,
                fail("encrypt: dest is not 16-byte aligned: %lu\n", ((unsigned long)dst)%16);
        }
 
-       cbc_encrypt(&ctx->aes, (nettle_cipher_func*)aes_encrypt, 16, ctx->iv, src_size, dst, src);
+       cbc_encrypt(&ctx->aes, (nettle_cipher_func*)aes128_encrypt, 16, ctx->iv, src_size, dst, src);
        return 0;
 }
 
@@ -206,7 +201,7 @@ myaes_decrypt(void *_ctx, const void *src, size_t src_size,
        }
 #endif
 
-       cbc_decrypt(&ctx->aes, (nettle_cipher_func*)aes_decrypt, 16, ctx->iv, src_size, dst, src);
+       cbc_decrypt(&ctx->aes, (nettle_cipher_func*)aes128_decrypt, 16, ctx->iv, src_size, dst, src);
 
        return 0;
 }