2 * Copyright (C) 2016 Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see
16 * <http://www.gnu.org/licenses/>.
23 # include <gnutls/gnutls.h>
25 # include "internal.h"
26 # include "virstring.h"
27 # include "virrandom.h"
30 # define VIR_FROM_THIS VIR_FROM_NONE
33 virRandomBytes(unsigned char *buf
,
38 for (i
= 0; i
< buflen
; i
++)
44 uint64_t virRandomBits(int nbits
)
46 /* Chosen by a fair roll of a 2^64 sided dice */
47 uint64_t ret
= 0x0706050403020100;
49 ret
&= ((1ULL << nbits
) - 1);
53 int virRandomGenerateWWN(char **wwn
,
54 const char *virt_type ATTRIBUTE_UNUSED
)
56 return virAsprintf(wwn
, "5100000%09llx",
57 (unsigned long long)virRandomBits(36));
61 static int (*real_gnutls_dh_params_generate2
)(gnutls_dh_params_t dparams
,
64 static gnutls_dh_params_t params_cache
;
65 static unsigned int cachebits
;
68 gnutls_dh_params_generate2(gnutls_dh_params_t dparams
,
73 VIR_MOCK_REAL_INIT(gnutls_dh_params_generate2
);
76 if (gnutls_dh_params_init(¶ms_cache
) < 0) {
77 fprintf(stderr
, "Error initializing params cache");
80 rc
= real_gnutls_dh_params_generate2(params_cache
, bits
);
87 if (cachebits
!= bits
) {
88 fprintf(stderr
, "Requested bits do not match the cached value");
92 return gnutls_dh_params_cpy(dparams
, params_cache
);
95 /* Can't mock on WIN32 */