|
Packit Service |
4684c1 |
/*
|
|
Packit Service |
4684c1 |
* Copyright (C) 2019 Red Hat, Inc.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* Author: Daiki Ueno
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* This file is part of GnuTLS.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* GnuTLS is free software; you can redistribute it and/or modify it
|
|
Packit Service |
4684c1 |
* under the terms of the GNU General Public License as published by
|
|
Packit Service |
4684c1 |
* the Free Software Foundation; either version 3 of the License, or
|
|
Packit Service |
4684c1 |
* (at your option) any later version.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* GnuTLS is distributed in the hope that it will be useful, but
|
|
Packit Service |
4684c1 |
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
4684c1 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
4684c1 |
* General Public License for more details.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* You should have received a copy of the GNU Lesser General Public License
|
|
Packit Service |
4684c1 |
* along with this program. If not, see <https://www.gnu.org/licenses/>
|
|
Packit Service |
4684c1 |
*/
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#ifdef HAVE_CONFIG_H
|
|
Packit Service |
4684c1 |
#include <config.h>
|
|
Packit Service |
4684c1 |
#endif
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#include <gnutls/crypto.h>
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#include <assert.h>
|
|
Packit Service |
4684c1 |
#include <stdint.h>
|
|
Packit Service |
4684c1 |
#include <string.h>
|
|
Packit Service |
4684c1 |
#include "utils.h"
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static void tls_log_func(int level, const char *str)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
fprintf(stderr, "<%d>| %s", level, str);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* Test whether gnutls_aead_cipher_{en,de}crypt_vec works */
|
|
Packit Service |
4684c1 |
static void start(const char *name, int algo)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
int ret;
|
|
Packit Service |
4684c1 |
gnutls_aead_cipher_hd_t ch;
|
|
Packit Service |
4684c1 |
uint8_t key16[64];
|
|
Packit Service |
4684c1 |
uint8_t iv16[32];
|
|
Packit Service |
4684c1 |
uint8_t auth[128];
|
|
Packit Service |
4684c1 |
uint8_t data[64+56+36];
|
|
Packit Service |
4684c1 |
gnutls_datum_t key, iv;
|
|
Packit Service |
4684c1 |
giovec_t iov[3];
|
|
Packit Service |
4684c1 |
giovec_t auth_iov[2];
|
|
Packit Service |
4684c1 |
uint8_t tag[64];
|
|
Packit Service |
4684c1 |
size_t tag_size = 0;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
key.data = key16;
|
|
Packit Service |
4684c1 |
key.size = gnutls_cipher_get_key_size(algo);
|
|
Packit Service |
4684c1 |
assert(key.size <= sizeof(key16));
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
iv.data = iv16;
|
|
Packit Service |
4684c1 |
iv.size = gnutls_cipher_get_iv_size(algo);
|
|
Packit Service |
4684c1 |
assert(iv.size <= sizeof(iv16));
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
memset(iv.data, 0xff, iv.size);
|
|
Packit Service |
4684c1 |
memset(key.data, 0xfe, key.size);
|
|
Packit Service |
4684c1 |
memset(data, 0xfa, sizeof(data));
|
|
Packit Service |
4684c1 |
memset(auth, 0xaa, sizeof(auth));
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
iov[0].iov_base = data;
|
|
Packit Service |
4684c1 |
iov[0].iov_len = 64;
|
|
Packit Service |
4684c1 |
iov[1].iov_base = data + 64;
|
|
Packit Service |
4684c1 |
iov[1].iov_len = 56;
|
|
Packit Service |
4684c1 |
iov[2].iov_base = data + 64 + 56;
|
|
Packit Service |
4684c1 |
iov[2].iov_len = 36;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
auth_iov[0].iov_base = auth;
|
|
Packit Service |
4684c1 |
auth_iov[0].iov_len = 64;
|
|
Packit Service |
4684c1 |
auth_iov[1].iov_base = auth + 64;
|
|
Packit Service |
4684c1 |
auth_iov[1].iov_len = 64;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
success("trying %s\n", name);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
ret =
|
|
Packit Service |
4684c1 |
gnutls_aead_cipher_init(&ch, algo, &key);
|
|
Packit Service |
4684c1 |
if (ret < 0)
|
|
Packit Service |
4684c1 |
fail("gnutls_cipher_init: %s\n", gnutls_strerror(ret));
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
ret = gnutls_aead_cipher_encryptv2(ch,
|
|
Packit Service |
4684c1 |
iv.data, iv.size,
|
|
Packit Service |
4684c1 |
auth_iov, 2,
|
|
Packit Service |
4684c1 |
iov, 3,
|
|
Packit Service |
4684c1 |
tag, &tag_size);
|
|
Packit Service |
4684c1 |
if (ret < 0)
|
|
Packit Service |
4684c1 |
fail("could not encrypt data: %s\n", gnutls_strerror(ret));
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
ret = gnutls_aead_cipher_decryptv2(ch,
|
|
Packit Service |
4684c1 |
iv.data, iv.size,
|
|
Packit Service |
4684c1 |
auth_iov, 2,
|
|
Packit Service |
4684c1 |
iov, 3,
|
|
Packit Service |
4684c1 |
tag, tag_size);
|
|
Packit Service |
4684c1 |
if (ret < 0)
|
|
Packit Service |
4684c1 |
fail("could not decrypt data: %s\n", gnutls_strerror(ret));
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
gnutls_aead_cipher_deinit(ch);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
void
|
|
Packit Service |
4684c1 |
doit(void)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
int ret;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
gnutls_global_set_log_function(tls_log_func);
|
|
Packit Service |
4684c1 |
if (debug)
|
|
Packit Service |
4684c1 |
gnutls_global_set_log_level(4711);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
ret = global_init();
|
|
Packit Service |
4684c1 |
if (ret < 0) {
|
|
Packit Service |
4684c1 |
fail("Cannot initialize library\n"); /*errcode 1 */
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
start("aes-128-gcm", GNUTLS_CIPHER_AES_128_GCM);
|
|
Packit Service |
4684c1 |
start("aes-192-gcm", GNUTLS_CIPHER_AES_192_GCM);
|
|
Packit Service |
4684c1 |
start("aes-256-gcm", GNUTLS_CIPHER_AES_256_GCM);
|
|
Packit Service |
4684c1 |
start("aes-128-ccm", GNUTLS_CIPHER_AES_128_CCM);
|
|
Packit Service |
4684c1 |
if (!gnutls_fips140_mode_enabled())
|
|
Packit Service |
4684c1 |
start("chacha20-poly1305", GNUTLS_CIPHER_CHACHA20_POLY1305);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
gnutls_global_deinit();
|
|
Packit Service |
4684c1 |
}
|