"Fossies" - the Fresh Open Source Software Archive

Member "knot-2.8.3/src/libdnssec/random.c" (16 Jul 2019, 1436 Bytes) of package /linux/misc/dns/knot-2.8.3.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "random.c" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 2.7.6_vs_2.8.0.

    1 /*  Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
    2 
    3     This program is free software: you can redistribute it and/or modify
    4     it under the terms of the GNU General Public License as published by
    5     the Free Software Foundation, either version 3 of the License, or
    6     (at your option) any later version.
    7 
    8     This program is distributed in the hope that it will be useful,
    9     but WITHOUT ANY WARRANTY; without even the implied warranty of
   10     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   11     GNU General Public License for more details.
   12 
   13     You should have received a copy of the GNU General Public License
   14     along with this program.  If not, see <https://www.gnu.org/licenses/>.
   15 */
   16 
   17 #include <assert.h>
   18 #include <gnutls/gnutls.h>
   19 #include <gnutls/crypto.h>
   20 #include <stddef.h>
   21 #include <stdint.h>
   22 
   23 #include "libdnssec/error.h"
   24 #include "libdnssec/random.h"
   25 #include "libdnssec/shared/shared.h"
   26 
   27 /* -- public API ----------------------------------------------------------- */
   28 
   29 _public_
   30 int dnssec_random_buffer(uint8_t *data, size_t size)
   31 {
   32     if (!data) {
   33         return DNSSEC_EINVAL;
   34     }
   35 
   36     int result = gnutls_rnd(GNUTLS_RND_RANDOM, data, size);
   37     if (result != 0) {
   38         assert_unreachable();
   39         return DNSSEC_ERROR;
   40     }
   41 
   42     return DNSSEC_EOK;
   43 }
   44 
   45 _public_
   46 int dnssec_random_binary(dnssec_binary_t *binary)
   47 {
   48     if (!binary) {
   49         return DNSSEC_EINVAL;
   50     }
   51 
   52     return dnssec_random_buffer(binary->data, binary->size);
   53 }