2 * This file is part of PowerDNS or dnsdist.
3 * Copyright -- PowerDNS.COM B.V. and its contributors
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * In addition, for the avoidance of any doubt, permission is granted to
10 * link this program with OpenSSL and to (re)distribute the binaries
11 * produced as the result of such linking.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include <arpa/inet.h>
29 #ifndef HAVE_LIBSODIUM
33 void merge(const SodiumNonce& lower, const SodiumNonce& higher) {};
35 unsigned char value[1];
44 randombytes_buf(value, sizeof value);
47 void merge(const SodiumNonce& lower, const SodiumNonce& higher)
49 static const size_t halfSize = (sizeof value) / 2;
50 memcpy(value, lower.value, halfSize);
51 memcpy(value + halfSize, higher.value + halfSize, halfSize);
56 uint32_t* p = (uint32_t*)value;
57 uint32_t count=htonl(*p);
61 string toString() const
63 return string((const char*)value, crypto_secretbox_NONCEBYTES);
66 unsigned char value[crypto_secretbox_NONCEBYTES];
69 std::string newKeypair();
70 std::string sodEncryptSym(const std::string& msg, const std::string& key, SodiumNonce&);
71 std::string sodDecryptSym(const std::string& msg, const std::string& key, SodiumNonce&);
73 bool sodIsValidKey(const std::string& key);