|
Packit Service |
4684c1 |
/*
|
|
Packit Service |
4684c1 |
* Copyright (C) 2017 Red Hat, Inc.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* Authors: Nikos Mavrogiannopoulos
|
|
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 |
#include <config.h>
|
|
Packit Service |
4684c1 |
#include <stdarg.h>
|
|
Packit Service |
4684c1 |
#include <stddef.h>
|
|
Packit Service |
4684c1 |
#include <setjmp.h>
|
|
Packit Service |
4684c1 |
#include <limits.h>
|
|
Packit Service |
4684c1 |
#include <stdint.h>
|
|
Packit Service |
4684c1 |
#include <stdlib.h>
|
|
Packit Service |
4684c1 |
#include <string.h>
|
|
Packit Service |
4684c1 |
#include <gnutls/gnutls.h>
|
|
Packit Service |
4684c1 |
#include <cmocka.h>
|
|
Packit Service |
4684c1 |
#include "hex.h"
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
int
|
|
Packit Service |
4684c1 |
_gnutls_prf_raw(gnutls_mac_algorithm_t mac,
|
|
Packit Service |
4684c1 |
size_t master_size, const void *master,
|
|
Packit Service |
4684c1 |
size_t label_size, const char *label,
|
|
Packit Service |
4684c1 |
size_t seed_size, const uint8_t *seed, size_t outsize,
|
|
Packit Service |
4684c1 |
char *out);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#define MATCH_FUNC(fname, dsecret, dseed, dlabel, doutput) \
|
|
Packit Service |
4684c1 |
static void fname(void **glob_state) \
|
|
Packit Service |
4684c1 |
{ \
|
|
Packit Service |
4684c1 |
char tmp[512]; \
|
|
Packit Service |
4684c1 |
gnutls_datum_t secret = dsecret; \
|
|
Packit Service |
4684c1 |
gnutls_datum_t seed = dseed; \
|
|
Packit Service |
4684c1 |
gnutls_datum_t label = dlabel; \
|
|
Packit Service |
4684c1 |
gnutls_datum_t output = doutput; \
|
|
Packit Service |
4684c1 |
int _rval; \
|
|
Packit Service |
4684c1 |
_rval = _gnutls_prf_raw(GNUTLS_MAC_MD5_SHA1, secret.size, secret.data, \
|
|
Packit Service |
4684c1 |
label.size, (char*)label.data, seed.size, seed.data, output.size, tmp); \
|
|
Packit Service |
4684c1 |
assert_int_equal(_rval, 0); \
|
|
Packit Service |
4684c1 |
assert_int_equal(memcmp(tmp, output.data, output.size), 0); \
|
|
Packit Service |
4684c1 |
gnutls_free(secret.data); \
|
|
Packit Service |
4684c1 |
gnutls_free(label.data); \
|
|
Packit Service |
4684c1 |
gnutls_free(seed.data); \
|
|
Packit Service |
4684c1 |
gnutls_free(output.data); \
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
MATCH_FUNC(test1, SHEX("263bdbbb6f6d4c664e058d0aa9d321be"), SHEX("b920573b199601024f04d6dc61966e65"),
|
|
Packit Service |
4684c1 |
SDATA("test label"), SHEX("6617993765fa6ca703d19ec70dd5dd160ffcc07725fafb714a9f815a2a30bfb7e3bbfb7eee574b3b613eb7fe80eec9691d8c1b0e2d9b3c8b4b02b6b6d6db88e2094623ef6240607eda7abe3c846e82a3"));
|
|
Packit Service |
4684c1 |
MATCH_FUNC(test2, SHEX("bf31fe6c78ebf0ff9ce8bb5dd9d1f83d"), SHEX("7fc4583d19871d962760f358a18696c8"),
|
|
Packit Service |
4684c1 |
SDATA("test label"), SHEX("8318f382c49fd5af7d6fdb4cbb31dfef"));
|
|
Packit Service |
4684c1 |
MATCH_FUNC(test3, SHEX("0addfc84435b9ac1ef523ef44791a784bf55757dea17837c1a72beec1bdb1850"),
|
|
Packit Service |
4684c1 |
SHEX("74e849d11ad8a98d9bc2291dbceec26ff9"),
|
|
Packit Service |
4684c1 |
SDATA("test label"), SHEX("3c221520c48bcb3a0eb3734a"));
|
|
Packit Service |
4684c1 |
MATCH_FUNC(test4, SHEX("4074939b440a08a285bc7208485c531f0bbd4c101d71bdba33ec066791e4678c"),
|
|
Packit Service |
4684c1 |
SHEX("8aff0c770c1d60455ee48f220c9adb471e5fee27c88c1f33"),
|
|
Packit Service |
4684c1 |
SDATA("test label"), SHEX("3a9aee040bbf3cf7009210e64bbdad1775ccf1b46b3a965d5f15168e9ddaa7cc6a7c0c117848"));
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
int main(void)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
const struct CMUnitTest tests[] = {
|
|
Packit Service |
4684c1 |
cmocka_unit_test(test1),
|
|
Packit Service |
4684c1 |
cmocka_unit_test(test2),
|
|
Packit Service |
4684c1 |
cmocka_unit_test(test3),
|
|
Packit Service |
4684c1 |
cmocka_unit_test(test4),
|
|
Packit Service |
4684c1 |
};
|
|
Packit Service |
4684c1 |
return cmocka_run_group_tests(tests, NULL, NULL);
|
|
Packit Service |
4684c1 |
}
|