Commit 928e97ee authored by Shah Rinku's avatar Shah Rinku

added checksum compute offload p4 code

parent 2423393b
This diff is collapsed.
#ifndef UTILS_H
#define UTILS_H
#include <fcntl.h>
#include "utils.h"
#endif
// all the struct for messages from RAN -> Controller are defined here
struct packet_chk_t {
//uint32_t packet_in;
uint8_t msg_id;
uint16_t len;
uint16_t data[DATA_LEN/2];
uint16_t checksum;
};
struct req_starting_ip {
uint8_t msg_id;
uint16_t sep1[3];
};
struct auth_step_one_t{
uint8_t msg_id;
uint16_t sep1[3];
uint32_t imsi;
uint16_t sep2[3];
uint8_t ue_nw_capability;
uint16_t sep3[3];
uint8_t ksi_asme[32];
uint16_t sep4[3];
uint32_t sqn;
uint16_t sep5[3];
uint8_t tai[8];
};
struct auth_step_three_t{
uint8_t msg_id;
uint16_t sep1[3];
uint32_t imsi;
uint16_t sep2[3];
uint8_t res[8];
};
struct nas_step_two_t{
uint8_t msg_id;
uint16_t sep1[3];
uint32_t encrypted_hash[5];
uint16_t sep2[3];
uint32_t imsi;
};
struct send_apn_t{
uint8_t msg_id;
uint16_t sep1[3];
uint8_t apn[8];
uint16_t sep2[3];
uint32_t key;
};
struct send_ue_teid_t{
uint8_t msg_id;
uint16_t sep1[3];
uint32_t ue_teid;
uint16_t sep2[3];
uint32_t key;
};
//DETACH REQUEST
struct detach_req_t{
uint8_t msg_id;
uint16_t sep1[3];
uint32_t ue_ip;
uint16_t sep2[3];
uint32_t ue_teid;
uint16_t sep3[3];
uint32_t sgw_teid;
uint16_t sep4[3];
uint32_t ue_num;
};
// CONTEXT RELEASE
struct ue_context_rel_req_t{
uint8_t msg_id;
uint16_t sep1[3];
uint32_t ue_ip;
uint16_t sep2[3];
uint32_t ue_teid;
uint16_t sep3[3];
uint32_t sgw_teid;
uint16_t sep4[3];
uint32_t ue_num;
};
// SERVICE REQUEST
struct ue_service_req_t{
uint8_t msg_id;
uint16_t sep1[3];
uint32_t ue_num;
uint16_t sep2[3];
int32_t ksi_asme;
uint16_t sep3[3];
uint32_t ue_ip;
};
struct initial_ctxt_setup_resp_t{
uint8_t msg_id;
uint16_t sep1[3];
uint32_t ue_teid;
uint16_t sep2[3];
uint32_t ue_key;
uint16_t sep3[3];
uint32_t ue_ip;
};
class Client{
public:
int tID;
int client_socket;
char client_buffer[BUFFER_SIZE];
unsigned char my_client_byte_buffer[BUFFER_SIZE];
unsigned char my_client_byte_buffer_3[BUFFER_SIZE];
char write_client_buffer[BUFFER_SIZE];
char write_client_byte_buffer[BUFFER_SIZE];
int sock_raw; //To receive raw packets
int saddr_size , data_size;
struct sockaddr saddr;
// Byte array in C++
unsigned char client_byte_buffer[BUFFER_SIZE];
int server_port;
const char *server_address;
struct sockaddr_in server_sock_addr;
struct sockaddr_in source,dest;
//bool flag=false; //flag to test the right dest IP for rcv data
bool tflag=false; //flag to test dest UDP port for demux of packets
time_t cT;
time_t eT;
clock_t begin, beginOff; //for timeout in us
clock_t end, endOff;
clock_t curr, currOff;
double elapsed_secs, elapsed_secsOff;
double timeout = 5000; //500000; //timeout value in us
bool timeoutFlag=false; // Flag =true if read timedout for non-offloadable messages
double timeoutOff = 2000; //timeout value in us
bool timeoutFlagOff=false; // Flag =true if read timedout for offloadable messages
// Constructor
Client(int);
// Socket methods
void input_server_details(int,const char*);
void read_data();
void read_data2();
void read_data3();
void write_data(string);
// void write_data2(char *);
void write_data2(int);
void read_byte();
void write_byte();
int sendUEData(int, string, string, int, int, int, string, size_t);
// Utility functions
string GetStdoutFromCommand(string cmd);
string runIperfCommand(string cmd,string srcIp);
//Raw packet functions
int ProcessPacket(unsigned char* , int);
int ProcessPacket2(unsigned char* , int);
int ProcessPacket3(unsigned char* , int);
void print_ip_header(unsigned char* , int);
void print_ip_header2(unsigned char* , int);
void print_ip_header3(unsigned char* , int);
//void print_tcp_packet(unsigned char * , int );
void print_udp_packet(unsigned char * , int );
void print_udp_packet2(unsigned char * , int );
void print_udp_packet3(unsigned char * , int );
//void print_icmp_packet(unsigned char* , int );
//void PrintData (unsigned char* , int);
//void PrintDataPayload (unsigned char* , int);
//void print_ethernet_header(unsigned char*, int);
// Destructor
~Client();
};
all: ran
RAN_P = ran.cpp ran.h client.cpp client.h ue.cpp ue.h utils.cpp utils.h
RAN_R = g++ ran.cpp -std=c++11 -w -o ran client.cpp ue.cpp utils.cpp -lpthread -lcrypto
ran: $(RAN_P)
$(RAN_R)
clean:
rm -f ran *~
/* aes.h
*
* The aes/rijndael block cipher.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2001 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_AES_H_INCLUDED
#define NETTLE_AES_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define aes_set_encrypt_key nettle_aes_set_encrypt_key
#define aes_set_decrypt_key nettle_aes_set_decrypt_key
#define aes_invert_key nettle_aes_invert_key
#define aes_encrypt nettle_aes_encrypt
#define aes_decrypt nettle_aes_decrypt
#define AES_BLOCK_SIZE 16
/* Variable key size between 128 and 256 bits. But the only valid
* values are 16 (128 bits), 24 (192 bits) and 32 (256 bits). */
#define AES_MIN_KEY_SIZE 16
#define AES_MAX_KEY_SIZE 32
#define AES_KEY_SIZE 32
/* FIXME: Change to put nrounds first, to make it possible to use a
truncated ctx struct, with less subkeys, for the shorter key
sizes? */
struct aes_ctx
{
uint32_t keys[60]; /* maximum size of key schedule */
unsigned nrounds; /* number of rounds to use for our key size */
};
void
aes_set_encrypt_key(struct aes_ctx *ctx,
unsigned length, const uint8_t *key);
void
aes_set_decrypt_key(struct aes_ctx *ctx,
unsigned length, const uint8_t *key);
void
aes_invert_key(struct aes_ctx *dst,
const struct aes_ctx *src);
void
aes_encrypt(const struct aes_ctx *ctx,
unsigned length, uint8_t *dst,
const uint8_t *src);
void
aes_decrypt(const struct aes_ctx *ctx,
unsigned length, uint8_t *dst,
const uint8_t *src);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_AES_H_INCLUDED */
/* arcfour.h
*
* The arcfour/rc4 stream cipher.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2001 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_ARCFOUR_H_INCLUDED
#define NETTLE_ARCFOUR_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define arcfour_set_key nettle_arcfour_set_key
#define arcfour_crypt nettle_arcfour_crypt
/* Minimum and maximum keysizes, and a reasonable default. In
* octets.*/
#define ARCFOUR_MIN_KEY_SIZE 1
#define ARCFOUR_MAX_KEY_SIZE 256
#define ARCFOUR_KEY_SIZE 16
struct arcfour_ctx
{
uint8_t S[256];
uint8_t i;
uint8_t j;
};
void
arcfour_set_key(struct arcfour_ctx *ctx,
unsigned length, const uint8_t *key);
void
arcfour_crypt(struct arcfour_ctx *ctx,
unsigned length, uint8_t *dst,
const uint8_t *src);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_ARCFOUR_H_INCLUDED */
/* arctwo.h
*
* The arctwo/rfc2268 block cipher.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2004 Simon Josefsson
* Copyright (C) 2002, 2004 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_ARCTWO_H_INCLUDED
#define NETTLE_ARCTWO_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define arctwo_set_key nettle_arctwo_set_key
#define arctwo_set_key_ekb nettle_arctwo_set_key_ekb
#define arctwo_encrypt nettle_arctwo_encrypt
#define arctwo_decrypt nettle_arctwo_decrypt
#define arctwo_set_key_gutmann nettle_arctwo_set_key_gutmann
#define ARCTWO_BLOCK_SIZE 8
/* Variable key size from 1 byte to 128 bytes. */
#define ARCTWO_MIN_KEY_SIZE 1
#define ARCTWO_MAX_KEY_SIZE 128
#define ARCTWO_KEY_SIZE 8
struct arctwo_ctx
{
uint16_t S[64];
};
/* Key expansion function that takes the "effective key bits", 1-1024,
as an explicit argument. 0 means maximum key bits. */
void
arctwo_set_key_ekb (struct arctwo_ctx *ctx,
unsigned length, const uint8_t * key, unsigned ekb);
/* Equvivalent to arctwo_set_key_ekb, with ekb = 8 * length */
void
arctwo_set_key (struct arctwo_ctx *ctx, unsigned length, const uint8_t *key);
/* Equvivalent to arctwo_set_key_ekb, with ekb = 1024 */
void
arctwo_set_key_gutmann (struct arctwo_ctx *ctx,
unsigned length, const uint8_t *key);
void
arctwo_encrypt (struct arctwo_ctx *ctx,
unsigned length, uint8_t *dst, const uint8_t *src);
void
arctwo_decrypt (struct arctwo_ctx *ctx,
unsigned length, uint8_t *dst, const uint8_t *src);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_ARCTWO_H_INCLUDED */
/* asn1.h
*
* Some very limited asn.1 support.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2005 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_ASN1_H_INCLUDED
#define NETTLE_ASN1_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define asn1_der_iterator_first nettle_asn1_der_iterator_first
#define asn1_der_iterator_next nettle_asn1_der_iterator_next
#define asn1_der_decode_constructed nettle_asn1_der_decode_constructed
#define asn1_der_decode_constructed_last nettle_asn1_der_decode_constructed_last
#define asn1_der_decode_bitstring nettle_asn1_der_decode_bitstring
#define asn1_der_decode_bitstring_last nettle_asn1_der_decode_bitstring_last
#define asn1_der_get_uint32 nettle_asn1_der_get_uint32
#define asn1_der_get_bignum nettle_asn1_der_get_bignum
/* enum asn1_type keeps the class number and the constructive in bits
13-14, and the constructive flag in bit 12. The remaining 14 bits
are the tag (although currently, only tags in the range 0-30 are
supported). */
enum
{
ASN1_TYPE_CONSTRUCTED = 1 << 12,
ASN1_CLASS_UNIVERSAL = 0,
ASN1_CLASS_APPLICATION = 1 << 13,
ASN1_CLASS_CONTEXT_SPECIFIC = 2 << 13,
ASN1_CLASS_PRIVATE = 3 << 13,
ASN1_CLASS_MASK = 3 << 13,
ASN1_CLASS_SHIFT = 13,
};
enum asn1_type
{
ASN1_BOOLEAN = 1,
ASN1_INTEGER = 2,
ASN1_BITSTRING = 3,
ASN1_OCTETSTRING = 4,
ASN1_NULL = 5,
ASN1_IDENTIFIER = 6,
ASN1_REAL = 9,
ASN1_ENUMERATED = 10,
ASN1_UTF8STRING = 12,
ASN1_SEQUENCE = 16 | ASN1_TYPE_CONSTRUCTED,
ASN1_SET = 17 | ASN1_TYPE_CONSTRUCTED,
ASN1_PRINTABLESTRING = 19,
ASN1_TELETEXSTRING = 20,
ASN1_IA5STRING = 22,
ASN1_UTC = 23,
ASN1_UNIVERSALSTRING = 28,
ASN1_BMPSTRING = 30,
};
enum asn1_iterator_result
{
ASN1_ITERATOR_ERROR,
ASN1_ITERATOR_PRIMITIVE,
ASN1_ITERATOR_CONSTRUCTED,
ASN1_ITERATOR_END,
};
/* Parsing DER objects. */
struct asn1_der_iterator
{
unsigned buffer_length;
const uint8_t *buffer;
/* Next object to parse. */
unsigned pos;
enum asn1_type type;
/* Pointer to the current object */
unsigned length;
const uint8_t *data;
};
/* Initializes the iterator. */
enum asn1_iterator_result
asn1_der_iterator_first(struct asn1_der_iterator *iterator,
unsigned length, const uint8_t *input);
enum asn1_iterator_result
asn1_der_iterator_next(struct asn1_der_iterator *iterator);
/* Starts parsing of a constructed object. */
enum asn1_iterator_result
asn1_der_decode_constructed(struct asn1_der_iterator *i,
struct asn1_der_iterator *contents);
/* For the common case that we have a sequence at the end of the
object. Checks that the current object is the final one, and then
reinitializes the iterator to parse its ontents. */
enum asn1_iterator_result
asn1_der_decode_constructed_last(struct asn1_der_iterator *i);
enum asn1_iterator_result
asn1_der_decode_bitstring(struct asn1_der_iterator *i,
struct asn1_der_iterator *contents);
enum asn1_iterator_result
asn1_der_decode_bitstring_last(struct asn1_der_iterator *i);
/* All these functions return 1 on success, 0 on failure */
int
asn1_der_get_uint32(struct asn1_der_iterator *i,
uint32_t *x);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_ASN1_H_INCLUDED */
/* base16.h
*
* Hex encoding and decoding, following spki conventions (i.e.
* allowing whitespace between digits).
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2002 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_BASE16_H_INCLUDED
#define NETTLE_BASE16_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define base16_encode_single nettle_base16_encode_single
#define base16_encode_update nettle_base16_encode_update
#define base16_decode_init nettle_base16_decode_init
#define base16_decode_single nettle_base16_decode_single
#define base16_decode_update nettle_base16_decode_update
#define base16_decode_final nettle_base16_decode_final
/* Base16 encoding */
/* Maximum length of output for base16_encode_update. */
#define BASE16_ENCODE_LENGTH(length) ((length) * 2)
/* Encodes a single byte. Always stores two digits in dst[0] and dst[1]. */
void
base16_encode_single(uint8_t *dst,
uint8_t src);
/* Always stores BASE16_ENCODE_LENGTH(length) digits in dst. */
void
base16_encode_update(uint8_t *dst,
unsigned length,
const uint8_t *src);
/* Base16 decoding */
/* Maximum length of output for base16_decode_update. */
/* We have at most 4 buffered bits, and a total of (length + 1) * 4 bits. */
#define BASE16_DECODE_LENGTH(length) (((length) + 1) / 2)
struct base16_decode_ctx
{
unsigned word; /* Leftover bits */
unsigned bits; /* Number buffered bits */
};
void
base16_decode_init(struct base16_decode_ctx *ctx);
/* Decodes a single byte. Returns amount of output (0 or 1), or -1 on
* errors. */
int
base16_decode_single(struct base16_decode_ctx *ctx,
uint8_t *dst,
uint8_t src);
/* Returns 1 on success, 0 on error. DST should point to an area of
* size at least BASE16_DECODE_LENGTH(length), and for sanity
* checking, *DST_LENGTH should be initialized to the size of that
* area before the call. *DST_LENGTH is updated to the amount of
* decoded output. */
/* Currently results in an assertion failure if *DST_LENGTH is
* too small. FIXME: Return some error instead? */
int
base16_decode_update(struct base16_decode_ctx *ctx,
unsigned *dst_length,
uint8_t *dst,
unsigned src_length,
const uint8_t *src);
/* Returns 1 on success. */
int
base16_decode_final(struct base16_decode_ctx *ctx);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_BASE16_H_INCLUDED */
/* base64.h
*
* "ASCII armor" codecs.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2002 Niels Möller, Dan Egnor
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_BASE64_H_INCLUDED
#define NETTLE_BASE64_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define base64_encode_init nettle_base64_encode_init
#define base64_encode_single nettle_base64_encode_single
#define base64_encode_update nettle_base64_encode_update
#define base64_encode_final nettle_base64_encode_final
#define base64_encode_raw nettle_base64_encode_raw
#define base64_encode_group nettle_base64_encode_group
#define base64_decode_init nettle_base64_decode_init
#define base64_decode_single nettle_base64_decode_single
#define base64_decode_update nettle_base64_decode_update
#define base64_decode_final nettle_base64_decode_final
#define BASE64_BINARY_BLOCK_SIZE 3
#define BASE64_TEXT_BLOCK_SIZE 4
/* Base64 encoding */
/* Maximum length of output for base64_encode_update. NOTE: Doesn't
* include any padding that base64_encode_final may add. */
/* We have at most 4 buffered bits, and a total of (4 + length * 8) bits. */
#define BASE64_ENCODE_LENGTH(length) (((length) * 8 + 4)/6)
/* Maximum length of output generated by base64_encode_final. */
#define BASE64_ENCODE_FINAL_LENGTH 3
/* Exact length of output generated by base64_encode_raw, including
* padding. */
#define BASE64_ENCODE_RAW_LENGTH(length) ((((length) + 2)/3)*4)
struct base64_encode_ctx
{
unsigned word; /* Leftover bits */
unsigned bits; /* Number of bits, always 0, 2, or 4. */
};
void
base64_encode_init(struct base64_encode_ctx *ctx);
/* Encodes a single byte. Returns amount of output (always 1 or 2). */
unsigned
base64_encode_single(struct base64_encode_ctx *ctx,
uint8_t *dst,
uint8_t src);
/* Returns the number of output characters. DST should point to an
* area of size at least BASE64_ENCODE_LENGTH(length). */
unsigned
base64_encode_update(struct base64_encode_ctx *ctx,
uint8_t *dst,
unsigned length,
const uint8_t *src);
/* DST should point to an area of size at least
* BASE64_ENCODE_FINAL_LENGTH */
unsigned
base64_encode_final(struct base64_encode_ctx *ctx,
uint8_t *dst);
/* Lower level functions */
/* Encodes a string in one go, including any padding at the end.
* Generates exactly BASE64_ENCODE_RAW_LENGTH(length) bytes of output.
* Supports overlapped operation, if src <= dst. */
void
base64_encode_raw(uint8_t *dst, unsigned length, const uint8_t *src);
void
base64_encode_group(uint8_t *dst, uint32_t group);
/* Base64 decoding */
/* Maximum length of output for base64_decode_update. */
/* We have at most 6 buffered bits, and a total of (length + 1) * 6 bits. */
#define BASE64_DECODE_LENGTH(length) ((((length) + 1) * 6) / 8)
struct base64_decode_ctx
{
unsigned word; /* Leftover bits */
unsigned bits; /* Number buffered bits */
/* Number of padding characters encountered */
unsigned padding;
};
void
base64_decode_init(struct base64_decode_ctx *ctx);
/* Decodes a single byte. Returns amount of output (0 or 1), or -1 on
* errors. */
int
base64_decode_single(struct base64_decode_ctx *ctx,
uint8_t *dst,
uint8_t src);
/* Returns 1 on success, 0 on error. DST should point to an area of
* size at least BASE64_DECODE_LENGTH(length), and for sanity
* checking, *DST_LENGTH should be initialized to the size of that
* area before the call. *DST_LENGTH is updated to the amount of
* decoded output. */
/* Currently results in an assertion failure if *DST_LENGTH is
* too small. FIXME: Return some error instead? */
int
base64_decode_update(struct base64_decode_ctx *ctx,
unsigned *dst_length,
uint8_t *dst,
unsigned src_length,
const uint8_t *src);
/* Returns 1 on success. */
int
base64_decode_final(struct base64_decode_ctx *ctx);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_BASE64_H_INCLUDED */
/* bignum.h
*
* bignum operations that are missing from gmp.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2001 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_BIGNUM_H_INCLUDED
#define NETTLE_BIGNUM_H_INCLUDED
#include "nettle-meta.h"
#include <gmp.h>
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Size needed for signed encoding, including extra sign byte if
* necessary. */
unsigned
nettle_mpz_sizeinbase_256_s(const mpz_t x);
/* Size needed for unsigned encoding */
unsigned
nettle_mpz_sizeinbase_256_u(const mpz_t x);
/* Writes an integer as length octets, using big endian byte order,
* and two's complement for negative numbers. */
void
nettle_mpz_get_str_256(unsigned length, uint8_t *s, const mpz_t x);
/* Reads a big endian, two's complement, integer. */
void
nettle_mpz_set_str_256_s(mpz_t x,
unsigned length, const uint8_t *s);
void
nettle_mpz_init_set_str_256_s(mpz_t x,
unsigned length, const uint8_t *s);
/* Similar, but for unsigned format. These function don't interpret
* the most significant bit as the sign. */
void
nettle_mpz_set_str_256_u(mpz_t x,
unsigned length, const uint8_t *s);
void
nettle_mpz_init_set_str_256_u(mpz_t x,
unsigned length, const uint8_t *s);
/* Returns a uniformly distributed random number 0 <= x < 2^n */
void
nettle_mpz_random_size(mpz_t x,
void *ctx, nettle_random_func *random,
unsigned bits);
/* Returns a number x, almost uniformly random in the range
* 0 <= x < n. */
void
nettle_mpz_random(mpz_t x,
void *ctx, nettle_random_func *random,
const mpz_t n);
void
nettle_next_prime(mpz_t p, mpz_t n, unsigned count, unsigned prime_limit,
void *progress_ctx, nettle_progress_func *progress);
void
nettle_random_prime(mpz_t p, unsigned bits, int top_bits_set,
void *ctx, nettle_random_func *random,
void *progress_ctx, nettle_progress_func *progress);
void
_nettle_generate_pocklington_prime (mpz_t p, mpz_t r,
unsigned bits, int top_bits_set,
void *ctx, nettle_random_func *random,
const mpz_t p0,
const mpz_t q,
const mpz_t p0q);
/* sexp parsing */
struct sexp_iterator;
/* If LIMIT is non-zero, the number must be at most LIMIT bits.
* Implies sexp_iterator_next. */
int
nettle_mpz_set_sexp(mpz_t x, unsigned limit, struct sexp_iterator *i);
/* der parsing */
struct asn1_der_iterator;
int
nettle_asn1_der_get_bignum(struct asn1_der_iterator *iterator,
mpz_t x, unsigned max_bits);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_BIGNUM_H_INCLUDED */
/* blowfish.h
*
* Blowfish block cipher.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 1998, 2001 FSF, Ray Dassen, Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_BLOWFISH_H_INCLUDED
#define NETTLE_BLOWFISH_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define blowfish_set_key nettle_blowfish_set_key
#define blowfish_encrypt nettle_blowfish_encrypt
#define blowfish_decrypt nettle_blowfish_decrypt
#define BLOWFISH_BLOCK_SIZE 8
/* Variable key size between 64 and 448 bits. */
#define BLOWFISH_MIN_KEY_SIZE 8
#define BLOWFISH_MAX_KEY_SIZE 56
/* Default to 128 bits */
#define BLOWFISH_KEY_SIZE 16
#define _BLOWFISH_ROUNDS 16
struct blowfish_ctx
{
uint32_t s[4][256];
uint32_t p[_BLOWFISH_ROUNDS+2];
};
/* On success, returns 1 and sets ctx->status to BLOWFISH_OK (zero).
* On error, returns 0 and sets ctx->status to BLOWFISH_WEAK_KEY. */
int
blowfish_set_key(struct blowfish_ctx *ctx,
unsigned length, const uint8_t *key);
void
blowfish_encrypt(const struct blowfish_ctx *ctx,
unsigned length, uint8_t *dst,
const uint8_t *src);
void
blowfish_decrypt(const struct blowfish_ctx *ctx,
unsigned length, uint8_t *dst,
const uint8_t *src);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_BLOWFISH_H_INCLUDED */
/* buffer.h
*
* A bare-bones string stream.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2002 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_BUFFER_H_INCLUDED
#define NETTLE_BUFFER_H_INCLUDED
#include "realloc.h"
#ifdef __cplusplus
extern "C" {
#endif
struct nettle_buffer
{
uint8_t *contents;
/* Allocated size */
unsigned alloc;
void *realloc_ctx;
nettle_realloc_func *realloc;
/* Current size */
unsigned size;
};
/* Initializes a buffer that uses plain realloc */
void
nettle_buffer_init(struct nettle_buffer *buffer);
void
nettle_buffer_init_realloc(struct nettle_buffer *buffer,
void *realloc_ctx,
nettle_realloc_func *realloc);
/* Initializes a buffer of fix size */
void
nettle_buffer_init_size(struct nettle_buffer *buffer,
unsigned length, uint8_t *space);
void
nettle_buffer_clear(struct nettle_buffer *buffer);
/* Resets the buffer, without freeing the buffer space. */
void
nettle_buffer_reset(struct nettle_buffer *buffer);
int
nettle_buffer_grow(struct nettle_buffer *buffer,
unsigned length);
#define NETTLE_BUFFER_PUTC(buffer, c) \
( (((buffer)->size < (buffer)->alloc) || nettle_buffer_grow((buffer), 1)) \
&& ((buffer)->contents[(buffer)->size++] = (c), 1) )
int
nettle_buffer_write(struct nettle_buffer *buffer,
unsigned length, const uint8_t *data);
/* Like nettle_buffer_write, but instead of copying data to the
* buffer, it returns a pointer to the area where the caller can copy
* the data. The pointer is valid only until the next call that can
* reallocate the buffer. */
uint8_t *
nettle_buffer_space(struct nettle_buffer *buffer,
unsigned length);
/* Copy the contents of SRC to the end of DST. */
int
nettle_buffer_copy(struct nettle_buffer *dst,
const struct nettle_buffer *src);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_BUFFER_H_INCLUDED */
/* camellia.h
*
* Copyright (C) 2006,2007
* NTT (Nippon Telegraph and Telephone Corporation).
*
* Copyright (C) 2010 Niels Möller
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef NETTLE_CAMELLIA_H_INCLUDED
#define NETTLE_CAMELLIA_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define camellia_set_encrypt_key nettle_camellia_set_encrypt_key
#define camellia_set_decrypt_key nettle_camellia_set_decrypt_key
#define camellia_invert_key nettle_camellia_invert_key
#define camellia_crypt nettle_camellia_crypt
#define camellia_crypt nettle_camellia_crypt
#define CAMELLIA_BLOCK_SIZE 16
/* Valid key sizes are 128, 192 or 256 bits (16, 24 or 32 bytes) */
#define CAMELLIA_MIN_KEY_SIZE 16
#define CAMELLIA_MAX_KEY_SIZE 32
#define CAMELLIA_KEY_SIZE 32
struct camellia_ctx
{
/* Number of subkeys. */
unsigned nkeys;
/* For 128-bit keys, there are 18 regular rounds, pre- and
post-whitening, and two FL and FLINV rounds, using a total of 26
subkeys, each of 64 bit. For 192- and 256-bit keys, there are 6
additional regular rounds and one additional FL and FLINV, using
a total of 34 subkeys. */
/* The clever combination of subkeys imply one of the pre- and
post-whitening keys is folded with the round keys, so that subkey
#1 and the last one (#25 or #33) is not used. The result is that
we have only 24 or 32 subkeys at the end of key setup. */
uint64_t keys[32];
};
void
camellia_set_encrypt_key(struct camellia_ctx *ctx,
unsigned length, const uint8_t *key);
void
camellia_set_decrypt_key(struct camellia_ctx *ctx,
unsigned length, const uint8_t *key);
void
camellia_invert_key(struct camellia_ctx *dst,
const struct camellia_ctx *src);
void
camellia_crypt(const struct camellia_ctx *ctx,
unsigned length, uint8_t *dst,
const uint8_t *src);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_CAMELLIA_H_INCLUDED */
/* cast128.h
*
* The CAST-128 block cipher.
*/
/* CAST-128 in C
* Written by Steve Reid <sreid@sea-to-sky.net>
* 100% Public Domain - no warranty
* Released 1997.10.11
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2001 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_CAST128_H_INCLUDED
#define NETTLE_CAST128_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define cast128_set_key nettle_cast128_set_key
#define cast128_encrypt nettle_cast128_encrypt
#define cast128_decrypt nettle_cast128_decrypt
#define CAST128_BLOCK_SIZE 8
/* Variable key size between 40 and 128. */
#define CAST128_MIN_KEY_SIZE 5
#define CAST128_MAX_KEY_SIZE 16
#define CAST128_KEY_SIZE 16
struct cast128_ctx
{
uint32_t keys[32]; /* Key, after expansion */
unsigned rounds; /* Number of rounds to use, 12 or 16 */
};
void
cast128_set_key(struct cast128_ctx *ctx,
unsigned length, const uint8_t *key);
void
cast128_encrypt(const struct cast128_ctx *ctx,
unsigned length, uint8_t *dst,
const uint8_t *src);
void
cast128_decrypt(const struct cast128_ctx *ctx,
unsigned length, uint8_t *dst,
const uint8_t *src);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_CAST128_H_INCLUDED */
/* cbc.h
*
* Cipher block chaining mode.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2001 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_CBC_H_INCLUDED
#define NETTLE_CBC_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define cbc_encrypt nettle_cbc_encrypt
#define cbc_decrypt nettle_cbc_decrypt
void
cbc_encrypt(void *ctx, nettle_crypt_func *f,
unsigned block_size, uint8_t *iv,
unsigned length, uint8_t *dst,
const uint8_t *src);
void
cbc_decrypt(void *ctx, nettle_crypt_func *f,
unsigned block_size, uint8_t *iv,
unsigned length, uint8_t *dst,
const uint8_t *src);
#define CBC_CTX(type, size) \
{ type ctx; uint8_t iv[size]; }
#define CBC_SET_IV(ctx, data) \
memcpy((ctx)->iv, (data), sizeof((ctx)->iv))
/* NOTE: Avoid using NULL, as we don't include anything defining it. */
#define CBC_ENCRYPT(self, f, length, dst, src) \
(0 ? ((f)(&(self)->ctx, 0, (void *)0, (void *)0)) \
: cbc_encrypt((void *) &(self)->ctx, \
(nettle_crypt_func *) (f), \
sizeof((self)->iv), (self)->iv, \
(length), (dst), (src)))
#define CBC_DECRYPT(self, f, length, dst, src) \
(0 ? ((f)(&(self)->ctx, 0, (void *)0, (void *)0)) \
: cbc_decrypt((void *) &(self)->ctx, \
(nettle_crypt_func *) (f), \
sizeof((self)->iv), (self)->iv, \
(length), (dst), (src)))
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_CBC_H_INCLUDED */
/* ctr.h
*
* Counter mode, using an network byte order incremented counter,
* matching the testcases of NIST 800-38A.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2005 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_CTR_H_INCLUDED
#define NETTLE_CTR_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define ctr_crypt nettle_ctr_crypt
void
ctr_crypt(void *ctx, nettle_crypt_func *f,
unsigned block_size, uint8_t *ctr,
unsigned length, uint8_t *dst,
const uint8_t *src);
#define CTR_CTX(type, size) \
{ type ctx; uint8_t ctr[size]; }
#define CTR_SET_COUNTER(ctx, data) \
memcpy((ctx)->ctr, (data), sizeof((ctx)->ctr))
#define CTR_CRYPT(self, f, length, dst, src) \
(0 ? ((f)(&(self)->ctx, 0, NULL, NULL)) \
: ctr_crypt((void *) &(self)->ctx, \
(nettle_crypt_func *) (f), \
sizeof((self)->ctr), (self)->ctr, \
(length), (dst), (src)))
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_CTR_H_INCLUDED */
/* des-compat.h
*
* The des block cipher, libdes/openssl-style interface.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2001 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_DES_COMPAT_H_INCLUDED
#define NETTLE_DES_COMPAT_H_INCLUDED
/* According to Assar, des_set_key, des_set_key_odd_parity,
* des_is_weak_key, plus the encryption functions (des_*_encrypt and
* des_cbc_cksum) would be a pretty useful subset. */
/* NOTE: This is quite experimental, and not all functions are
* implemented. Contributions, in particular test cases are welcome. */
#include "des.h"
#ifdef __cplusplus
extern "C" {
#endif
/* We use some name mangling, to avoid collisions with either other
* nettle functions or with libcrypto. */
#define des_ecb3_encrypt nettle_openssl_des_ecb3_encrypt
#define des_cbc_cksum nettle_openssl_des_cbc_cksum
#define des_ncbc_encrypt nettle_openssl_des_ncbc_encrypt
#define des_cbc_encrypt nettle_openssl_des_cbc_encrypt
#define des_ecb_encrypt nettle_openssl_des_ecb_encrypt
#define des_ede3_cbc_encrypt nettle_openssl_des_ede3_cbc_encrypt
#define des_set_odd_parity nettle_openssl_des_set_odd_parity
#define des_check_key nettle_openssl_des_check_key
#define des_key_sched nettle_openssl_des_key_sched
#define des_is_weak_key nettle_openssl_des_is_weak_key
/* An extra alias */
#undef des_set_key
#define des_set_key nettle_openssl_des_key_sched
enum { DES_DECRYPT = 0, DES_ENCRYPT = 1 };
/* Types */
typedef uint32_t DES_LONG;
/* Note: Typedef:ed arrays should be avoided, but they're used here
* for compatibility. */
typedef struct des_ctx des_key_schedule[1];
typedef uint8_t des_cblock[DES_BLOCK_SIZE];
/* Note: The proper definition,
typedef const uint8_t const_des_cblock[DES_BLOCK_SIZE];
would have worked, *if* all the prototypes had used arguments like
foo(const_des_cblock src, des_cblock dst), letting argument arrays
"decay" into pointers of type uint8_t * and const uint8_t *.
But since openssl's prototypes use *pointers* const_des_cblock *src,
des_cblock *dst, this ends up in type conflicts, and the workaround
is to not use const at all.
*/
#define const_des_cblock des_cblock
/* Aliases */
#define des_ecb2_encrypt(i,o,k1,k2,e) \
des_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e))
#define des_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \
des_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e))
/* Global flag */
extern int des_check_key;
/* Prototypes */
/* Typing is a little confusing. Since both des_cblock and
des_key_schedule are typedef:ed arrays, it automatically decay to
a pointers.
But the functions are declared taking pointers to des_cblock, i.e.
pointers to arrays. And on the other hand, they take plain
des_key_schedule arguments, which is equivalent to pointers to
struct des_ctx. */
void
des_ecb3_encrypt(const_des_cblock *src, des_cblock *dst,
des_key_schedule k1,
des_key_schedule k2,
des_key_schedule k3, int enc);
/* des_cbc_cksum in libdes returns a 32 bit integer, representing the
* latter half of the output block, using little endian byte order. */
uint32_t
des_cbc_cksum(const uint8_t *src, des_cblock *dst,
long length, des_key_schedule ctx,
const_des_cblock *iv);
/* NOTE: Doesn't update iv. */
void
des_cbc_encrypt(const_des_cblock *src, des_cblock *dst, long length,
des_key_schedule ctx, const_des_cblock *iv,
int enc);
/* Similar, but updates iv. */
void
des_ncbc_encrypt(const_des_cblock *src, des_cblock *dst, long length,
des_key_schedule ctx, des_cblock *iv,
int enc);
void
des_ecb_encrypt(const_des_cblock *src, des_cblock *dst,
des_key_schedule ctx, int enc);
void
des_ede3_cbc_encrypt(const_des_cblock *src, des_cblock *dst, long length,
des_key_schedule k1,
des_key_schedule k2,
des_key_schedule k3,
des_cblock *iv,
int enc);
int
des_set_odd_parity(des_cblock *key);
int
des_key_sched(const_des_cblock *key, des_key_schedule ctx);
int
des_is_weak_key(const_des_cblock *key);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_DES_COMPAT_H_INCLUDED */
/* des.h
*
* The des block cipher. And triple des.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 1992, 2001, Dana L. How, Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
/*
* des - fast & portable DES encryption & decryption.
* Copyright (C) 1992 Dana L. How
* Please see the file `../lib/descore.README' for the complete copyright
* notice.
*
* Slightly edited by Niels Möller, 1997
*/
#ifndef NETTLE_DES_H_INCLUDED
#define NETTLE_DES_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Namespace mangling */
#define des_set_key nettle_des_set_key
#define des_encrypt nettle_des_encrypt
#define des_decrypt nettle_des_decrypt
#define des_check_parity nettle_des_check_parity
#define des_fix_parity nettle_des_fix_parity
#define des3_set_key nettle_des3_set_key
#define des3_encrypt nettle_des3_encrypt
#define des3_decrypt nettle_des3_decrypt
#define DES_KEY_SIZE 8
#define DES_BLOCK_SIZE 8
/* Expanded key length */
#define _DES_KEY_LENGTH 32
struct des_ctx
{
uint32_t key[_DES_KEY_LENGTH];
};
/* Returns 1 for good keys and 0 for weak keys. */
int
des_set_key(struct des_ctx *ctx, const uint8_t *key);
void
des_encrypt(const struct des_ctx *ctx,
unsigned length, uint8_t *dst,
const uint8_t *src);
void
des_decrypt(const struct des_ctx *ctx,
unsigned length, uint8_t *dst,
const uint8_t *src);
int
des_check_parity(unsigned length, const uint8_t *key);
void
des_fix_parity(unsigned length, uint8_t *dst,
const uint8_t *src);
#define DES3_KEY_SIZE 24
#define DES3_BLOCK_SIZE DES_BLOCK_SIZE
struct des3_ctx
{
struct des_ctx des[3];
};
/* Returns 1 for good keys and 0 for weak keys. */
int
des3_set_key(struct des3_ctx *ctx, const uint8_t *key);
void
des3_encrypt(const struct des3_ctx *ctx,
unsigned length, uint8_t *dst,
const uint8_t *src);
void
des3_decrypt(const struct des3_ctx *ctx,
unsigned length, uint8_t *dst,
const uint8_t *src);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_DES_H_INCLUDED */
/* dsa.h
*
* The DSA publickey algorithm.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2002 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_DSA_H_INCLUDED
#define NETTLE_DSA_H_INCLUDED
#include <gmp.h>
#include "nettle-types.h"
#include "sha1.h"
#include "sha2.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define dsa_public_key_init nettle_dsa_public_key_init
#define dsa_public_key_clear nettle_dsa_public_key_clear
#define dsa_private_key_init nettle_dsa_private_key_init
#define dsa_private_key_clear nettle_dsa_private_key_clear
#define dsa_signature_init nettle_dsa_signature_init
#define dsa_signature_clear nettle_dsa_signature_clear
#define dsa_sha1_sign nettle_dsa_sha1_sign
#define dsa_sha1_verify nettle_dsa_sha1_verify
#define dsa_sha256_sign nettle_dsa_sha256_sign
#define dsa_sha256_verify nettle_dsa_sha256_verify
#define dsa_sha1_sign_digest nettle_dsa_sha1_sign_digest
#define dsa_sha1_verify_digest nettle_dsa_sha1_verify_digest
#define dsa_sha256_sign_digest nettle_dsa_sha256_sign_digest
#define dsa_sha256_verify_digest nettle_dsa_sha256_verify_digest
#define dsa_generate_keypair nettle_dsa_generate_keypair
#define dsa_signature_from_sexp nettle_dsa_signature_from_sexp
#define dsa_keypair_to_sexp nettle_dsa_keypair_to_sexp
#define dsa_keypair_from_sexp_alist nettle_dsa_keypair_from_sexp_alist
#define dsa_sha1_keypair_from_sexp nettle_dsa_sha1_keypair_from_sexp
#define dsa_sha256_keypair_from_sexp nettle_dsa_sha256_keypair_from_sexp
#define dsa_params_from_der_iterator nettle_dsa_params_from_der_iterator
#define dsa_public_key_from_der_iterator nettle_dsa_public_key_from_der_iterator
#define dsa_openssl_private_key_from_der_iterator nettle_dsa_openssl_private_key_from_der_iterator
#define dsa_openssl_private_key_from_der nettle_openssl_provate_key_from_der
#define _dsa_sign _nettle_dsa_sign
#define _dsa_verify _nettle_dsa_verify
#define DSA_SHA1_MIN_P_BITS 512
#define DSA_SHA1_Q_OCTETS 20
#define DSA_SHA1_Q_BITS 160
#define DSA_SHA256_MIN_P_BITS 1024
#define DSA_SHA256_Q_OCTETS 32
#define DSA_SHA256_Q_BITS 256
struct dsa_public_key
{
/* Modulo */
mpz_t p;
/* Group order */
mpz_t q;
/* Generator */
mpz_t g;
/* Public value */
mpz_t y;
};
struct dsa_private_key
{
/* Unlike an rsa public key, private key operations will need both
* the private and the public information. */
mpz_t x;
};
struct dsa_signature
{
mpz_t r;
mpz_t s;
};
/* Signing a message works as follows:
*
* Store the private key in a dsa_private_key struct.
*
* Initialize a hashing context, by callling
* sha1_init
*
* Hash the message by calling
* sha1_update
*
* Create the signature by calling
* dsa_sha1_sign
*
* The signature is represented as a struct dsa_signature. This call also
* resets the hashing context.
*
* When done with the key and signature, don't forget to call
* dsa_signature_clear.
*/
/* Calls mpz_init to initialize bignum storage. */
void
dsa_public_key_init(struct dsa_public_key *key);
/* Calls mpz_clear to deallocate bignum storage. */
void
dsa_public_key_clear(struct dsa_public_key *key);
/* Calls mpz_init to initialize bignum storage. */
void
dsa_private_key_init(struct dsa_private_key *key);
/* Calls mpz_clear to deallocate bignum storage. */
void
dsa_private_key_clear(struct dsa_private_key *key);
/* Calls mpz_init to initialize bignum storage. */
void
dsa_signature_init(struct dsa_signature *signature);
/* Calls mpz_clear to deallocate bignum storage. */
void
dsa_signature_clear(struct dsa_signature *signature);
int
dsa_sha1_sign(const struct dsa_public_key *pub,
const struct dsa_private_key *key,
void *random_ctx, nettle_random_func *random,
struct sha1_ctx *hash,
struct dsa_signature *signature);
int
dsa_sha256_sign(const struct dsa_public_key *pub,
const struct dsa_private_key *key,
void *random_ctx, nettle_random_func *random,
struct sha256_ctx *hash,
struct dsa_signature *signature);
int
dsa_sha1_verify(const struct dsa_public_key *key,
struct sha1_ctx *hash,
const struct dsa_signature *signature);
int
dsa_sha256_verify(const struct dsa_public_key *key,
struct sha256_ctx *hash,
const struct dsa_signature *signature);
int
dsa_sha1_sign_digest(const struct dsa_public_key *pub,
const struct dsa_private_key *key,
void *random_ctx, nettle_random_func *random,
const uint8_t *digest,
struct dsa_signature *signature);
int
dsa_sha256_sign_digest(const struct dsa_public_key *pub,
const struct dsa_private_key *key,
void *random_ctx, nettle_random_func *random,
const uint8_t *digest,
struct dsa_signature *signature);
int
dsa_sha1_verify_digest(const struct dsa_public_key *key,
const uint8_t *digest,
const struct dsa_signature *signature);
int
dsa_sha256_verify_digest(const struct dsa_public_key *key,
const uint8_t *digest,
const struct dsa_signature *signature);
/* Key generation */
int
dsa_generate_keypair(struct dsa_public_key *pub,
struct dsa_private_key *key,
void *random_ctx, nettle_random_func *random,
void *progress_ctx, nettle_progress_func *progress,
unsigned p_bits, unsigned q_bits);
/* Keys in sexp form. */
struct nettle_buffer;
/* Generates a public-key expression if PRIV is NULL .*/
int
dsa_keypair_to_sexp(struct nettle_buffer *buffer,
const char *algorithm_name, /* NULL means "dsa" */
const struct dsa_public_key *pub,
const struct dsa_private_key *priv);
struct sexp_iterator;
int
dsa_signature_from_sexp(struct dsa_signature *rs,
struct sexp_iterator *i,
unsigned q_bits);
int
dsa_keypair_from_sexp_alist(struct dsa_public_key *pub,
struct dsa_private_key *priv,
unsigned p_max_bits,
unsigned q_bits,
struct sexp_iterator *i);
/* If PRIV is NULL, expect a public-key expression. If PUB is NULL,
* expect a private key expression and ignore the parts not needed for
* the public key. */
/* Keys must be initialized before calling this function, as usual. */
int
dsa_sha1_keypair_from_sexp(struct dsa_public_key *pub,
struct dsa_private_key *priv,
unsigned p_max_bits,
unsigned length, const uint8_t *expr);
int
dsa_sha256_keypair_from_sexp(struct dsa_public_key *pub,
struct dsa_private_key *priv,
unsigned p_max_bits,
unsigned length, const uint8_t *expr);
/* Keys in X.509 andd OpenSSL format. */
struct asn1_der_iterator;
int
dsa_params_from_der_iterator(struct dsa_public_key *pub,
unsigned p_max_bits,
struct asn1_der_iterator *i);
int
dsa_public_key_from_der_iterator(struct dsa_public_key *pub,
unsigned p_max_bits,
struct asn1_der_iterator *i);
int
dsa_openssl_private_key_from_der_iterator(struct dsa_public_key *pub,
struct dsa_private_key *priv,
unsigned p_max_bits,
struct asn1_der_iterator *i);
int
dsa_openssl_private_key_from_der(struct dsa_public_key *pub,
struct dsa_private_key *priv,
unsigned p_max_bits,
unsigned length, const uint8_t *data);
/* Internal functions. */
int
_dsa_sign(const struct dsa_public_key *pub,
const struct dsa_private_key *key,
void *random_ctx, nettle_random_func *random,
unsigned digest_size,
const uint8_t *digest,
struct dsa_signature *signature);
int
_dsa_verify(const struct dsa_public_key *key,
unsigned digest_size,
const uint8_t *digest,
const struct dsa_signature *signature);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_DSA_H_INCLUDED */
/* ecc-curve.h */
/* nettle, low-level cryptographics library
*
* Copyright (C) 2013 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
/* Development of Nettle's ECC support was funded by the .SE Internet Fund. */
#ifndef NETTLE_ECC_CURVE_H_INCLUDED
#define NETTLE_ECC_CURVE_H_INCLUDED
#ifdef __cplusplus
extern "C" {
#endif
/* The contets of this struct is internal. */
struct ecc_curve;
extern const struct ecc_curve nettle_secp_192r1;
extern const struct ecc_curve nettle_secp_224r1;
extern const struct ecc_curve nettle_secp_256r1;
extern const struct ecc_curve nettle_secp_384r1;
extern const struct ecc_curve nettle_secp_521r1;
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_ECC_CURVE_H_INCLUDED */
/* ecc.h */
/* nettle, low-level cryptographics library
*
* Copyright (C) 2013 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
/* Development of Nettle's ECC support was funded by the .SE Internet Fund. */
#ifndef NETTLE_ECC_H_INCLUDED
#define NETTLE_ECC_H_INCLUDED
#include <gmp.h>
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define ecc_point_init nettle_ecc_point_init
#define ecc_point_clear nettle_ecc_point_clear
#define ecc_point_set nettle_ecc_point_set
#define ecc_point_get nettle_ecc_point_get
#define ecc_point_mul nettle_ecc_point_mul
#define ecc_point_mul_g nettle_ecc_point_mul_g
#define ecc_scalar_init nettle_ecc_scalar_init
#define ecc_scalar_clear nettle_ecc_scalar_clear
#define ecc_scalar_set nettle_ecc_scalar_set
#define ecc_scalar_get nettle_ecc_scalar_get
#define ecc_scalar_random nettle_ecc_scalar_random
#define ecc_point_mul nettle_ecc_point_mul
#define ecc_size nettle_ecc_size
#define ecc_size_a nettle_ecc_size_a
#define ecc_size_j nettle_ecc_size_j
#define ecc_a_to_a_itch nettle_ecc_a_to_a_itch
#define ecc_a_to_a nettle_ecc_a_to_a
#define ecc_a_to_j nettle_ecc_a_to_j
#define ecc_j_to_a_itch nettle_ecc_j_to_a_itch
#define ecc_j_to_a nettle_ecc_j_to_a
#define ecc_dup_ja_itch nettle_ecc_dup_ja_itch
#define ecc_dup_ja nettle_ecc_dup_ja
#define ecc_dup_jj_itch nettle_ecc_dup_jj_itch
#define ecc_dup_jj nettle_ecc_dup_jj
#define ecc_add_jja_itch nettle_ecc_add_jja_itch
#define ecc_add_jja nettle_ecc_add_jja
#define ecc_add_jjj_itch nettle_ecc_add_jjj_itch
#define ecc_add_jjj nettle_ecc_add_jjj
#define ecc_mul_g_itch nettle_ecc_mul_g_itch
#define ecc_mul_g nettle_ecc_mul_g
#define ecc_mul_a_itch nettle_ecc_mul_a_itch
#define ecc_mul_a nettle_ecc_mul_a
struct ecc_curve;
/* High level interface, for ECDSA, DH, etc */
/* Represents a point on the ECC curve */
struct ecc_point
{
const struct ecc_curve *ecc;
/* Allocated using the same allocation function as GMP. */
mp_limb_t *p;
};
/* Represents a non-zero scalar, an element of Z_q^*, where q is the
group order of the curve. */
struct ecc_scalar
{
const struct ecc_curve *ecc;
/* Allocated using the same allocation function as GMP. */
mp_limb_t *p;
};
void
ecc_point_init (struct ecc_point *p, const struct ecc_curve *ecc);
void
ecc_point_clear (struct ecc_point *p);
/* Fails and returns zero if the point is not on the curve. */
int
ecc_point_set (struct ecc_point *p, const mpz_t x, const mpz_t y);
void
ecc_point_get (const struct ecc_point *p, mpz_t x, mpz_t y);
void
ecc_scalar_init (struct ecc_scalar *s, const struct ecc_curve *ecc);
void
ecc_scalar_clear (struct ecc_scalar *s);
/* Fails and returns zero if the scalar is not in the proper range. */
int
ecc_scalar_set (struct ecc_scalar *s, const mpz_t z);
void
ecc_scalar_get (const struct ecc_scalar *s, mpz_t z);
/* Generates a random scalar, suitable as an ECDSA private key or a
ECDH exponent. */
void
ecc_scalar_random (struct ecc_scalar *s,
void *random_ctx, nettle_random_func *random);
/* Computes r = n p */
void
ecc_point_mul (struct ecc_point *r, const struct ecc_scalar *n,
const struct ecc_point *p);
/* Computes r = n g */
void
ecc_point_mul_g (struct ecc_point *r, const struct ecc_scalar *n);
/* Low-level interface */
/* Points on a curve are represented as arrays of mp_limb_t. For some
curves, point coordinates are represented in montgomery form. We
use either affine coordinates x,y, or Jacobian coordinates X, Y, Z,
where x = X/Z^2 and y = X/Z^2.
Since we use additive notation for the groups, the infinity point
on the curve is denoted 0. The infinity point can be represented
with x = y = 0 in affine coordinates, and Z = 0 in Jacobian
coordinates. However, note that most of the ECC functions do *not*
support infinity as an input or output.
*/
/* FIXME: Also provided some compile time constants? */
/* Returns the size of a single coordinate. */
mp_size_t
ecc_size (const struct ecc_curve *ecc);
/* Size of a point, using affine coordinates x, y. */
mp_size_t
ecc_size_a (const struct ecc_curve *ecc);
/* Size of a point, using jacobian coordinates X, Y and Z. */
mp_size_t
ecc_size_j (const struct ecc_curve *ecc);
/* FIXME: Rename the low-level (and side-channel silent) functions to
_ecc_*, and provide public ecc_* functions which handle the
infinity points properly? */
/* Converts the affine coordinates of a point into montgomery form, if
used for this curve. */
mp_size_t
ecc_a_to_a_itch (const struct ecc_curve *ecc);
void
ecc_a_to_a (const struct ecc_curve *ecc,
mp_limb_t *r, const mp_limb_t *p,
mp_limb_t *scratch);
/* Converts a point P in affine coordinates into a point R in jacobian
coordinates. If INITIAL is non-zero, and the curve uses montgomery
coordinates, also convert coordinates to montgomery form. */
void
ecc_a_to_j (const struct ecc_curve *ecc,
int initial,
mp_limb_t *r, const mp_limb_t *p);
/* Converts a point P in jacobian coordinates into a point R in affine
coordinates. If FLAGS has bit 0 set, and the curve uses montgomery
coordinates, also undo the montgomery conversion. If flags has bit
1 set, produce x coordinate only. */
mp_size_t
ecc_j_to_a_itch (const struct ecc_curve *ecc);
void
ecc_j_to_a (const struct ecc_curve *ecc,
int flags,
mp_limb_t *r, const mp_limb_t *p,
mp_limb_t *scratch);
/* Group operations */
/* Point doubling, with jacobian output and affine input. Corner
cases: Correctly sets R = 0 (r_Z = 0) if p = 0 or 2p = 0. */
mp_size_t
ecc_dup_ja_itch (const struct ecc_curve *ecc);
void
ecc_dup_ja (const struct ecc_curve *ecc,
mp_limb_t *r, const mp_limb_t *p,
mp_limb_t *scratch);
/* Point doubling, with jacobian input and output. Corner cases:
Correctly sets R = 0 (r_Z = 0) if p = 0 or 2p = 0. */
mp_size_t
ecc_dup_jj_itch (const struct ecc_curve *ecc);
void
ecc_dup_jj (const struct ecc_curve *ecc,
mp_limb_t *r, const mp_limb_t *p,
mp_limb_t *scratch);
/* Point addition, with jacobian output, one jacobian input and one
affine input. Corner cases: Fails for the cases
P = Q != 0 Duplication of non-zero point
P = 0, Q != 0 or P != 0, Q = 0 One input zero
Correctly gives R = 0 if P = Q = 0 or P = -Q. */
mp_size_t
ecc_add_jja_itch (const struct ecc_curve *ecc);
void
ecc_add_jja (const struct ecc_curve *ecc,
mp_limb_t *r, const mp_limb_t *p, const mp_limb_t *q,
mp_limb_t *scratch);
/* Point addition with Jacobian input and output. */
mp_size_t
ecc_add_jjj_itch (const struct ecc_curve *ecc);
void
ecc_add_jjj (const struct ecc_curve *ecc,
mp_limb_t *r, const mp_limb_t *p, const mp_limb_t *q,
mp_limb_t *scratch);
/* Computes N * the group generator. N is an array of ecc_size()
limbs. It must be in the range 0 < N < group order, then R != 0,
and the algorithm can work without any intermediate values getting
to zero. */
mp_size_t
ecc_mul_g_itch (const struct ecc_curve *ecc);
void
ecc_mul_g (const struct ecc_curve *ecc, mp_limb_t *r,
const mp_limb_t *np, mp_limb_t *scratch);
/* Computes N * P. The scalar N is the same as for ecc_mul_g. P is a
non-zero point on the curve, in affine coordinates. Pass a non-zero
INITIAL if the point coordinates have not previously been converted
to Montgomery representation. Output R is a non-zero point, in
Jacobian coordinates. */
mp_size_t
ecc_mul_a_itch (const struct ecc_curve *ecc);
void
ecc_mul_a (const struct ecc_curve *ecc,
int initial, mp_limb_t *r,
const mp_limb_t *np, const mp_limb_t *p,
mp_limb_t *scratch);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_ECC_H_INCLUDED */
/* ecdsa.h */
/* nettle, low-level cryptographics library
*
* Copyright (C) 2013 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
/* Development of Nettle's ECC support was funded by the .SE Internet Fund. */
#ifndef NETTLE_ECDSA_H_INCLUDED
#define NETTLE_ECDSA_H_INCLUDED
#include "ecc.h"
#include "dsa.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define ecdsa_sign nettle_ecdsa_sign
#define ecdsa_verify nettle_ecdsa_verify
#define ecdsa_generate_keypair nettle_ecdsa_generate_keypair
#define ecc_ecdsa_sign nettle_ecc_ecdsa_sign
#define ecc_ecdsa_sign_itch nettle_ecc_ecdsa_sign_itch
#define ecc_ecdsa_verify nettle_ecc_ecdsa_verify
#define ecc_ecdsa_verify_itch nettle_ecc_ecdsa_verify_itch
/* High level ECDSA functions.
*
* A public key is represented as a struct ecc_point, and a private
* key as a struct ecc_scalar. FIXME: Introduce some aliases? */
void
ecdsa_sign (const struct ecc_scalar *key,
void *random_ctx, nettle_random_func *random,
unsigned digest_length,
const uint8_t *digest,
struct dsa_signature *signature);
int
ecdsa_verify (const struct ecc_point *pub,
unsigned length, const uint8_t *digest,
const struct dsa_signature *signature);
void
ecdsa_generate_keypair (struct ecc_point *pub,
struct ecc_scalar *key,
void *random_ctx, nettle_random_func *random);
/* Low-level ECDSA functions. */
mp_size_t
ecc_ecdsa_sign_itch (const struct ecc_curve *ecc);
void
ecc_ecdsa_sign (const struct ecc_curve *ecc,
const mp_limb_t *zp,
/* Random nonce, must be invertible mod ecc group
order. */
const mp_limb_t *kp,
unsigned length, const uint8_t *digest,
mp_limb_t *rp, mp_limb_t *sp,
mp_limb_t *scratch);
mp_size_t
ecc_ecdsa_verify_itch (const struct ecc_curve *ecc);
int
ecc_ecdsa_verify (const struct ecc_curve *ecc,
const mp_limb_t *pp, /* Public key */
unsigned length, const uint8_t *digest,
const mp_limb_t *rp, const mp_limb_t *sp,
mp_limb_t *scratch);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_ECDSA_H_INCLUDED */
/* gcm.h
*
* Galois counter mode, specified by NIST,
* http://csrc.nist.gov/publications/nistpubs/800-38D/SP-800-38D.pdf
*
*/
/* NOTE: Tentative interface, subject to change. No effort will be
made to avoid incompatible changes. */
/* nettle, low-level cryptographics library
*
* Copyright (C) 2011 Niels Möller
* Copyright (C) 2011 Katholieke Universiteit Leuven
*
* Contributed by Nikos Mavrogiannopoulos
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_GCM_H_INCLUDED
#define NETTLE_GCM_H_INCLUDED
#include "aes.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define gcm_set_key nettle_gcm_set_key
#define gcm_set_iv nettle_gcm_set_iv
#define gcm_update nettle_gcm_update
#define gcm_encrypt nettle_gcm_encrypt
#define gcm_decrypt nettle_gcm_decrypt
#define gcm_digest nettle_gcm_digest
#define gcm_aes_set_key nettle_gcm_aes_set_key
#define gcm_aes_set_iv nettle_gcm_aes_set_iv
#define gcm_aes_update nettle_gcm_aes_update
#define gcm_aes_encrypt nettle_gcm_aes_encrypt
#define gcm_aes_decrypt nettle_gcm_aes_decrypt
#define gcm_aes_digest nettle_gcm_aes_digest
#define GCM_BLOCK_SIZE 16
#define GCM_IV_SIZE (GCM_BLOCK_SIZE - 4)
#define GCM_TABLE_BITS 8
/* To make sure that we have proper alignment. */
union gcm_block
{
uint8_t b[GCM_BLOCK_SIZE];
unsigned long w[GCM_BLOCK_SIZE / sizeof(unsigned long)];
};
/* Hashing subkey */
struct gcm_key
{
union gcm_block h[1 << GCM_TABLE_BITS];
};
/* Per-message state, depending on the iv */
struct gcm_ctx {
/* Original counter block */
union gcm_block iv;
/* Updated for each block. */
union gcm_block ctr;
/* Hashing state */
union gcm_block x;
uint64_t auth_size;
uint64_t data_size;
};
/* FIXME: Should use const for the cipher context. Then needs const for
nettle_crypt_func, which also rules out using that abstraction for
arcfour. */
void
gcm_set_key(struct gcm_key *key,
void *cipher, nettle_crypt_func *f);
void
gcm_set_iv(struct gcm_ctx *ctx, const struct gcm_key *key,
unsigned length, const uint8_t *iv);
void
gcm_update(struct gcm_ctx *ctx, const struct gcm_key *key,
unsigned length, const uint8_t *data);
void
gcm_encrypt(struct gcm_ctx *ctx, const struct gcm_key *key,
void *cipher, nettle_crypt_func *f,
unsigned length, uint8_t *dst, const uint8_t *src);
void
gcm_decrypt(struct gcm_ctx *ctx, const struct gcm_key *key,
void *cipher, nettle_crypt_func *f,
unsigned length, uint8_t *dst, const uint8_t *src);
void
gcm_digest(struct gcm_ctx *ctx, const struct gcm_key *key,
void *cipher, nettle_crypt_func *f,
unsigned length, uint8_t *digest);
/* Convenience macrology (not sure how useful it is) */
/* All-in-one context, with cipher, hash subkey, and message state. */
#define GCM_CTX(type) \
{ type cipher; struct gcm_key key; struct gcm_ctx gcm; }
/* NOTE: Avoid using NULL, as we don't include anything defining it. */
#define GCM_SET_KEY(ctx, set_key, encrypt, length, data) \
do { \
(set_key)(&(ctx)->cipher, (length), (data)); \
if (0) (encrypt)(&(ctx)->cipher, 0, (void *)0, (void *)0); \
gcm_set_key(&(ctx)->key, &(ctx)->cipher, \
(nettle_crypt_func *) (encrypt)); \
} while (0)
#define GCM_SET_IV(ctx, length, data) \
gcm_set_iv(&(ctx)->gcm, &(ctx)->key, (length), (data))
#define GCM_UPDATE(ctx, length, data) \
gcm_update(&(ctx)->gcm, &(ctx)->key, (length), (data))
#define GCM_ENCRYPT(ctx, encrypt, length, dst, src) \
(0 ? (encrypt)(&(ctx)->cipher, 0, (void *)0, (void *)0) \
: gcm_encrypt(&(ctx)->gcm, &(ctx)->key, &(ctx)->cipher, \
(nettle_crypt_func *) (encrypt), \
(length), (dst), (src)))
#define GCM_DECRYPT(ctx, encrypt, length, dst, src) \
(0 ? (encrypt)(&(ctx)->cipher, 0, (void *)0, (void *)0) \
: gcm_decrypt(&(ctx)->gcm, &(ctx)->key, &(ctx)->cipher, \
(nettle_crypt_func *) (encrypt), \
(length), (dst), (src)))
#define GCM_DIGEST(ctx, encrypt, length, digest) \
(0 ? (encrypt)(&(ctx)->cipher, 0, (void *)0, (void *)0) \
: gcm_digest(&(ctx)->gcm, &(ctx)->key, &(ctx)->cipher, \
(nettle_crypt_func *) (encrypt), \
(length), (digest)))
struct gcm_aes_ctx GCM_CTX(struct aes_ctx);
void
gcm_aes_set_key(struct gcm_aes_ctx *ctx,
unsigned length, const uint8_t *key);
void
gcm_aes_set_iv(struct gcm_aes_ctx *ctx,
unsigned length, const uint8_t *iv);
void
gcm_aes_update(struct gcm_aes_ctx *ctx,
unsigned length, const uint8_t *data);
void
gcm_aes_encrypt(struct gcm_aes_ctx *ctx,
unsigned length, uint8_t *dst, const uint8_t *src);
void
gcm_aes_decrypt(struct gcm_aes_ctx *ctx,
unsigned length, uint8_t *dst, const uint8_t *src);
void
gcm_aes_digest(struct gcm_aes_ctx *ctx, unsigned length, uint8_t *digest);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_GCM_H_INCLUDED */
/* gosthash94.h
*
* The GOST R 34.11-94 hash function, described in RFC 5831.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2012 Nikos Mavrogiannopoulos, Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
/* Interface based on rhash gost.h. */
/* Copyright: 2009-2012 Aleksey Kravchenko <rhash.admin@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* Ported to nettle by Nikos Mavrogiannopoulos.
*/
#ifndef NETTLE_GOSTHASH94_H_INCLUDED
#define NETTLE_GOSTHASH94_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
#define gosthash94_init nettle_gosthash94_init
#define gosthash94_update nettle_gosthash94_update
#define gosthash94_digest nettle_gosthash94_digest
#define GOSTHASH94_DATA_SIZE 32
#define GOSTHASH94_DIGEST_SIZE 32
struct gosthash94_ctx
{
uint32_t hash[8]; /* algorithm 256-bit state */
uint32_t sum[8]; /* sum of processed message blocks */
uint8_t message[GOSTHASH94_DATA_SIZE]; /* 256-bit buffer for leftovers */
uint64_t length; /* number of processed bytes */
};
void gosthash94_init(struct gosthash94_ctx *ctx);
void gosthash94_update(struct gosthash94_ctx *ctx,
unsigned length, const uint8_t *msg);
void gosthash94_digest(struct gosthash94_ctx *ctx,
unsigned length, uint8_t *result);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_GOSTHASH94_H_INCLUDED */
/* hmac.h
*
* HMAC message authentication code (RFC-2104).
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2001, 2002 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_HMAC_H_INCLUDED
#define NETTLE_HMAC_H_INCLUDED
#include "nettle-meta.h"
#include "md5.h"
#include "ripemd160.h"
#include "sha1.h"
#include "sha2.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Namespace mangling */
#define hmac_set_key nettle_hmac_set_key
#define hmac_update nettle_hmac_update
#define hmac_digest nettle_hmac_digest
#define hmac_md5_set_key nettle_hmac_md5_set_key
#define hmac_md5_update nettle_hmac_md5_update
#define hmac_md5_digest nettle_hmac_md5_digest
#define hmac_ripemd160_set_key nettle_hmac_ripemd160_set_key
#define hmac_ripemd160_update nettle_hmac_ripemd160_update
#define hmac_ripemd160_digest nettle_hmac_ripemd160_digest
#define hmac_sha1_set_key nettle_hmac_sha1_set_key
#define hmac_sha1_update nettle_hmac_sha1_update
#define hmac_sha1_digest nettle_hmac_sha1_digest
#define hmac_sha224_set_key nettle_hmac_sha224_set_key
#define hmac_sha224_digest nettle_hmac_sha224_digest
#define hmac_sha256_set_key nettle_hmac_sha256_set_key
#define hmac_sha256_update nettle_hmac_sha256_update
#define hmac_sha256_digest nettle_hmac_sha256_digest
#define hmac_sha384_set_key nettle_hmac_sha384_set_key
#define hmac_sha384_digest nettle_hmac_sha384_digest
#define hmac_sha512_set_key nettle_hmac_sha512_set_key
#define hmac_sha512_update nettle_hmac_sha512_update
#define hmac_sha512_digest nettle_hmac_sha512_digest
void
hmac_set_key(void *outer, void *inner, void *state,
const struct nettle_hash *hash,
unsigned length, const uint8_t *key);
/* This function is not strictly needed, it's s just the same as the
* hash update function. */
void
hmac_update(void *state,
const struct nettle_hash *hash,
unsigned length, const uint8_t *data);
void
hmac_digest(const void *outer, const void *inner, void *state,
const struct nettle_hash *hash,
unsigned length, uint8_t *digest);
#define HMAC_CTX(type) \
{ type outer; type inner; type state; }
#define HMAC_SET_KEY(ctx, hash, length, key) \
hmac_set_key( &(ctx)->outer, &(ctx)->inner, &(ctx)->state, \
(hash), (length), (key) )
#define HMAC_DIGEST(ctx, hash, length, digest) \
hmac_digest( &(ctx)->outer, &(ctx)->inner, &(ctx)->state, \
(hash), (length), (digest) )
/* HMAC using specific hash functions */
/* hmac-md5 */
struct hmac_md5_ctx HMAC_CTX(struct md5_ctx);
void
hmac_md5_set_key(struct hmac_md5_ctx *ctx,
unsigned key_length, const uint8_t *key);
void
hmac_md5_update(struct hmac_md5_ctx *ctx,
unsigned length, const uint8_t *data);
void
hmac_md5_digest(struct hmac_md5_ctx *ctx,
unsigned length, uint8_t *digest);
/* hmac-ripemd160 */
struct hmac_ripemd160_ctx HMAC_CTX(struct ripemd160_ctx);
void
hmac_ripemd160_set_key(struct hmac_ripemd160_ctx *ctx,
unsigned key_length, const uint8_t *key);
void
hmac_ripemd160_update(struct hmac_ripemd160_ctx *ctx,
unsigned length, const uint8_t *data);
void
hmac_ripemd160_digest(struct hmac_ripemd160_ctx *ctx,
unsigned length, uint8_t *digest);
/* hmac-sha1 */
struct hmac_sha1_ctx HMAC_CTX(struct sha1_ctx);
void
hmac_sha1_set_key(struct hmac_sha1_ctx *ctx,
unsigned key_length, const uint8_t *key);
void
hmac_sha1_update(struct hmac_sha1_ctx *ctx,
unsigned length, const uint8_t *data);
void
hmac_sha1_digest(struct hmac_sha1_ctx *ctx,
unsigned length, uint8_t *digest);
/* hmac-sha256 */
struct hmac_sha256_ctx HMAC_CTX(struct sha256_ctx);
void
hmac_sha256_set_key(struct hmac_sha256_ctx *ctx,
unsigned key_length, const uint8_t *key);
void
hmac_sha256_update(struct hmac_sha256_ctx *ctx,
unsigned length, const uint8_t *data);
void
hmac_sha256_digest(struct hmac_sha256_ctx *ctx,
unsigned length, uint8_t *digest);
/* hmac-sha224 */
#define hmac_sha224_ctx hmac_sha256_ctx
void
hmac_sha224_set_key(struct hmac_sha224_ctx *ctx,
unsigned key_length, const uint8_t *key);
#define hmac_sha224_update nettle_hmac_sha256_update
void
hmac_sha224_digest(struct hmac_sha224_ctx *ctx,
unsigned length, uint8_t *digest);
/* hmac-sha512 */
struct hmac_sha512_ctx HMAC_CTX(struct sha512_ctx);
void
hmac_sha512_set_key(struct hmac_sha512_ctx *ctx,
unsigned key_length, const uint8_t *key);
void
hmac_sha512_update(struct hmac_sha512_ctx *ctx,
unsigned length, const uint8_t *data);
void
hmac_sha512_digest(struct hmac_sha512_ctx *ctx,
unsigned length, uint8_t *digest);
/* hmac-sha384 */
#define hmac_sha384_ctx hmac_sha512_ctx
void
hmac_sha384_set_key(struct hmac_sha512_ctx *ctx,
unsigned key_length, const uint8_t *key);
#define hmac_sha384_update nettle_hmac_sha512_update
void
hmac_sha384_digest(struct hmac_sha512_ctx *ctx,
unsigned length, uint8_t *digest);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_HMAC_H_INCLUDED */
/* knuth-lfib.h
*
* A "lagged fibonacci" pseudorandomness generator.
*
* Described in Knuth, TAOCP, 3.6
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2002 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
/* NOTE: This generator is totally inappropriate for cryptographic
* applications. It is useful for generating deterministic but
* random-looking test data, and is used by the Nettle testsuite. */
#ifndef NETTLE_KNUTH_LFIB_H_INCLUDED
#define NETTLE_KNUTH_LFIB_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Namespace mangling */
#define knuth_lfib_init nettle_knuth_lfib_init
#define knuth_lfib_get nettle_knuth_lfib_get
#define knuth_lfib_get_array nettle_knuth_lfib_get_array
#define knuth_lfib_random nettle_knuth_lfib_random
#define _KNUTH_LFIB_KK 100
struct knuth_lfib_ctx
{
uint32_t x[_KNUTH_LFIB_KK];
unsigned index;
};
void
knuth_lfib_init(struct knuth_lfib_ctx *ctx, uint32_t seed);
/* Get's a single number in the range 0 ... 2^30-1 */
uint32_t
knuth_lfib_get(struct knuth_lfib_ctx *ctx);
/* Get an array of numbers */
void
knuth_lfib_get_array(struct knuth_lfib_ctx *ctx,
unsigned n, uint32_t *a);
/* Get an array of octets. */
void
knuth_lfib_random(struct knuth_lfib_ctx *ctx,
unsigned n, uint8_t *dst);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_KNUTH_LFIB_H_INCLUDED */
/* macros.h
*
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2001, 2010 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_MACROS_H_INCLUDED
#define NETTLE_MACROS_H_INCLUDED
/* Reads a 64-bit integer, in network, big-endian, byte order */
#define READ_UINT64(p) \
( (((uint64_t) (p)[0]) << 56) \
| (((uint64_t) (p)[1]) << 48) \
| (((uint64_t) (p)[2]) << 40) \
| (((uint64_t) (p)[3]) << 32) \
| (((uint64_t) (p)[4]) << 24) \
| (((uint64_t) (p)[5]) << 16) \
| (((uint64_t) (p)[6]) << 8) \
| ((uint64_t) (p)[7]))
#define WRITE_UINT64(p, i) \
do { \
(p)[0] = ((i) >> 56) & 0xff; \
(p)[1] = ((i) >> 48) & 0xff; \
(p)[2] = ((i) >> 40) & 0xff; \
(p)[3] = ((i) >> 32) & 0xff; \
(p)[4] = ((i) >> 24) & 0xff; \
(p)[5] = ((i) >> 16) & 0xff; \
(p)[6] = ((i) >> 8) & 0xff; \
(p)[7] = (i) & 0xff; \
} while(0)
/* Reads a 32-bit integer, in network, big-endian, byte order */
#define READ_UINT32(p) \
( (((uint32_t) (p)[0]) << 24) \
| (((uint32_t) (p)[1]) << 16) \
| (((uint32_t) (p)[2]) << 8) \
| ((uint32_t) (p)[3]))
#define WRITE_UINT32(p, i) \
do { \
(p)[0] = ((i) >> 24) & 0xff; \
(p)[1] = ((i) >> 16) & 0xff; \
(p)[2] = ((i) >> 8) & 0xff; \
(p)[3] = (i) & 0xff; \
} while(0)
/* Analogous macros, for 24 and 16 bit numbers */
#define READ_UINT24(p) \
( (((uint32_t) (p)[0]) << 16) \
| (((uint32_t) (p)[1]) << 8) \
| ((uint32_t) (p)[2]))
#define WRITE_UINT24(p, i) \
do { \
(p)[0] = ((i) >> 16) & 0xff; \
(p)[1] = ((i) >> 8) & 0xff; \
(p)[2] = (i) & 0xff; \
} while(0)
#define READ_UINT16(p) \
( (((uint32_t) (p)[0]) << 8) \
| ((uint32_t) (p)[1]))
#define WRITE_UINT16(p, i) \
do { \
(p)[0] = ((i) >> 8) & 0xff; \
(p)[1] = (i) & 0xff; \
} while(0)
/* And the other, little-endian, byteorder */
#define LE_READ_UINT64(p) \
( (((uint64_t) (p)[7]) << 56) \
| (((uint64_t) (p)[6]) << 48) \
| (((uint64_t) (p)[5]) << 40) \
| (((uint64_t) (p)[4]) << 32) \
| (((uint64_t) (p)[3]) << 24) \
| (((uint64_t) (p)[2]) << 16) \
| (((uint64_t) (p)[1]) << 8) \
| ((uint64_t) (p)[0]))
#define LE_WRITE_UINT64(p, i) \
do { \
(p)[7] = ((i) >> 56) & 0xff; \
(p)[6] = ((i) >> 48) & 0xff; \
(p)[5] = ((i) >> 40) & 0xff; \
(p)[4] = ((i) >> 32) & 0xff; \
(p)[3] = ((i) >> 24) & 0xff; \
(p)[2] = ((i) >> 16) & 0xff; \
(p)[1] = ((i) >> 8) & 0xff; \
(p)[0] = (i) & 0xff; \
} while (0)
#define LE_READ_UINT32(p) \
( (((uint32_t) (p)[3]) << 24) \
| (((uint32_t) (p)[2]) << 16) \
| (((uint32_t) (p)[1]) << 8) \
| ((uint32_t) (p)[0]))
#define LE_WRITE_UINT32(p, i) \
do { \
(p)[3] = ((i) >> 24) & 0xff; \
(p)[2] = ((i) >> 16) & 0xff; \
(p)[1] = ((i) >> 8) & 0xff; \
(p)[0] = (i) & 0xff; \
} while(0)
/* Analogous macros, for 16 bit numbers */
#define LE_READ_UINT16(p) \
( (((uint32_t) (p)[1]) << 8) \
| ((uint32_t) (p)[0]))
#define LE_WRITE_UINT16(p, i) \
do { \
(p)[1] = ((i) >> 8) & 0xff; \
(p)[0] = (i) & 0xff; \
} while(0)
/* Macro to make it easier to loop over several blocks. */
#define FOR_BLOCKS(length, dst, src, blocksize) \
assert( !((length) % (blocksize))); \
for (; (length); ((length) -= (blocksize), \
(dst) += (blocksize), \
(src) += (blocksize)) )
#define ROTL32(n,x) (((x)<<(n)) | ((x)>>(32-(n))))
#define ROTL64(n,x) (((x)<<(n)) | ((x)>>(64-(n))))
/* Requires that size > 0 */
#define INCREMENT(size, ctr) \
do { \
unsigned increment_i = (size) - 1; \
if (++(ctr)[increment_i] == 0) \
while (increment_i > 0 \
&& ++(ctr)[--increment_i] == 0 ) \
; \
} while (0)
/* Helper macro for Merkle-Damgård hash functions. Assumes the context
structs includes the following fields:
xxx count_low, count_high; // Two word block count
uint8_t block[...]; // Buffer holding one block
unsigned int index; // Index into block
*/
/* FIXME: Should probably switch to using uint64_t for the count, but
due to alignment and byte order that may be an ABI change. */
#define MD_INCR(ctx) ((ctx)->count_high += !++(ctx)->count_low)
/* Takes the compression function f as argument. NOTE: also clobbers
length and data. */
#define MD_UPDATE(ctx, length, data, f, incr) \
do { \
if ((ctx)->index) \
{ \
/* Try to fill partial block */ \
unsigned __md_left = sizeof((ctx)->block) - (ctx)->index; \
if ((length) < __md_left) \
{ \
memcpy((ctx)->block + (ctx)->index, (data), (length)); \
(ctx)->index += (length); \
goto __md_done; /* Finished */ \
} \
else \
{ \
memcpy((ctx)->block + (ctx)->index, (data), __md_left); \
\
f((ctx), (ctx)->block); \
(incr); \
\
(data) += __md_left; \
(length) -= __md_left; \
} \
} \
while ((length) >= sizeof((ctx)->block)) \
{ \
f((ctx), (data)); \
(incr); \
\
(data) += sizeof((ctx)->block); \
(length) -= sizeof((ctx)->block); \
} \
memcpy ((ctx)->block, (data), (length)); \
(ctx)->index = (length); \
__md_done: \
; \
} while (0)
/* Pads the block to a block boundary with the bit pattern 1 0*,
leaving size octets for the length field at the end. If needed,
compresses the block and starts a new one. */
#define MD_PAD(ctx, size, f) \
do { \
unsigned __md_i; \
__md_i = (ctx)->index; \
\
/* Set the first char of padding to 0x80. This is safe since there \
is always at least one byte free */ \
\
assert(__md_i < sizeof((ctx)->block)); \
(ctx)->block[__md_i++] = 0x80; \
\
if (__md_i > (sizeof((ctx)->block) - 2*sizeof((ctx)->count_low))) \
{ /* No room for length in this block. Process it and \
pad with another one */ \
memset((ctx)->block + __md_i, 0, sizeof((ctx)->block) - __md_i); \
\
f((ctx), (ctx)->block); \
__md_i = 0; \
} \
memset((ctx)->block + __md_i, 0, \
sizeof((ctx)->block) - (size) - __md_i); \
\
} while (0)
#endif /* NETTLE_MACROS_H_INCLUDED */
/* md2.h
*
* The MD2 hash function, described in RFC 1319.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2003 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_MD2_H_INCLUDED
#define NETTLE_MD2_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define md2_init nettle_md2_init
#define md2_update nettle_md2_update
#define md2_digest nettle_md2_digest
#define MD2_DIGEST_SIZE 16
#define MD2_DATA_SIZE 16
struct md2_ctx
{
uint8_t C[MD2_DATA_SIZE];
uint8_t X[3 * MD2_DATA_SIZE];
uint8_t block[MD2_DATA_SIZE]; /* Block buffer */
unsigned index; /* Into buffer */
};
void
md2_init(struct md2_ctx *ctx);
void
md2_update(struct md2_ctx *ctx,
unsigned length,
const uint8_t *data);
void
md2_digest(struct md2_ctx *ctx,
unsigned length,
uint8_t *digest);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_MD2_H_INCLUDED */
/* md4.h
*
* The MD4 hash function, described in RFC 1320.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2003 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_MD4_H_INCLUDED
#define NETTLE_MD4_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define md4_init nettle_md4_init
#define md4_update nettle_md4_update
#define md4_digest nettle_md4_digest
#define MD4_DIGEST_SIZE 16
#define MD4_DATA_SIZE 64
/* Digest is kept internally as 4 32-bit words. */
#define _MD4_DIGEST_LENGTH 4
/* FIXME: Identical to md5_ctx */
struct md4_ctx
{
uint32_t state[_MD4_DIGEST_LENGTH];
uint32_t count_low, count_high; /* Block count */
uint8_t block[MD4_DATA_SIZE]; /* Block buffer */
unsigned index; /* Into buffer */
};
void
md4_init(struct md4_ctx *ctx);
void
md4_update(struct md4_ctx *ctx,
unsigned length,
const uint8_t *data);
void
md4_digest(struct md4_ctx *ctx,
unsigned length,
uint8_t *digest);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_MD4_H_INCLUDED */
/* md5-compat.h
*
* The md5 hash function, RFC 1321-style interface.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2001 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_MD5_COMPAT_H_INCLUDED
#define NETTLE_MD5_COMPAT_H_INCLUDED
#include "md5.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define MD5Init nettle_MD5Init
#define MD5Update nettle_MD5Update
#define MD5Final nettle_MD5Final
typedef struct md5_ctx MD5_CTX;
void MD5Init(MD5_CTX *ctx);
void MD5Update(MD5_CTX *ctx, const unsigned char *data, unsigned int length);
void MD5Final(unsigned char *out, MD5_CTX *ctx);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_MD5_COMPAT_H_INCLUDED */
/* md5.h
*
* The MD5 hash function, described in RFC 1321.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2001 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_MD5_H_INCLUDED
#define NETTLE_MD5_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define md5_init nettle_md5_init
#define md5_update nettle_md5_update
#define md5_digest nettle_md5_digest
#define MD5_DIGEST_SIZE 16
#define MD5_DATA_SIZE 64
/* Digest is kept internally as 4 32-bit words. */
#define _MD5_DIGEST_LENGTH 4
struct md5_ctx
{
uint32_t state[_MD5_DIGEST_LENGTH];
uint32_t count_low, count_high; /* Block count */
uint8_t block[MD5_DATA_SIZE]; /* Block buffer */
unsigned index; /* Into buffer */
};
void
md5_init(struct md5_ctx *ctx);
void
md5_update(struct md5_ctx *ctx,
unsigned length,
const uint8_t *data);
void
md5_digest(struct md5_ctx *ctx,
unsigned length,
uint8_t *digest);
/* Internal compression function. STATE points to 4 uint32_t words,
and DATA points to 64 bytes of input data, possibly unaligned. */
void
_nettle_md5_compress(uint32_t *state, const uint8_t *data);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_MD5_H_INCLUDED */
/* memxor.h
*
*/
#ifndef NETTLE_MEMXOR_H_INCLUDED
#define NETTLE_MEMXOR_H_INCLUDED
#include <stdlib.h>
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
uint8_t *memxor(uint8_t *dst, const uint8_t *src, size_t n);
uint8_t *memxor3(uint8_t *dst, const uint8_t *a, const uint8_t *b, size_t n);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_MEMXOR_H_INCLUDED */
/* nettle-meta.h
*
* Information about algorithms.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2002 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_META_H_INCLUDED
#define NETTLE_META_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
struct nettle_cipher
{
const char *name;
unsigned context_size;
/* Zero for stream ciphers */
unsigned block_size;
/* Suggested key size; other sizes are sometimes possible. */
unsigned key_size;
nettle_set_key_func *set_encrypt_key;
nettle_set_key_func *set_decrypt_key;
nettle_crypt_func *encrypt;
nettle_crypt_func *decrypt;
};
#define _NETTLE_CIPHER(name, NAME, key_size) { \
#name #key_size, \
sizeof(struct name##_ctx), \
NAME##_BLOCK_SIZE, \
key_size / 8, \
(nettle_set_key_func *) name##_set_key, \
(nettle_set_key_func *) name##_set_key, \
(nettle_crypt_func *) name##_encrypt, \
(nettle_crypt_func *) name##_decrypt, \
}
#define _NETTLE_CIPHER_SEP(name, NAME, key_size) { \
#name #key_size, \
sizeof(struct name##_ctx), \
NAME##_BLOCK_SIZE, \
key_size / 8, \
(nettle_set_key_func *) name##_set_encrypt_key, \
(nettle_set_key_func *) name##_set_decrypt_key, \
(nettle_crypt_func *) name##_encrypt, \
(nettle_crypt_func *) name##_decrypt, \
}
#define _NETTLE_CIPHER_SEP_SET_KEY(name, NAME, key_size) {\
#name #key_size, \
sizeof(struct name##_ctx), \
NAME##_BLOCK_SIZE, \
key_size / 8, \
(nettle_set_key_func *) name##_set_encrypt_key, \
(nettle_set_key_func *) name##_set_decrypt_key, \
(nettle_crypt_func *) name##_crypt, \
(nettle_crypt_func *) name##_crypt, \
}
#define _NETTLE_CIPHER_FIX(name, NAME) { \
#name, \
sizeof(struct name##_ctx), \
NAME##_BLOCK_SIZE, \
NAME##_KEY_SIZE, \
(nettle_set_key_func *) name##_set_key, \
(nettle_set_key_func *) name##_set_key, \
(nettle_crypt_func *) name##_encrypt, \
(nettle_crypt_func *) name##_decrypt, \
}
/* null-terminated list of ciphers implemented by this version of nettle */
extern const struct nettle_cipher * const nettle_ciphers[];
extern const struct nettle_cipher nettle_aes128;
extern const struct nettle_cipher nettle_aes192;
extern const struct nettle_cipher nettle_aes256;
extern const struct nettle_cipher nettle_arcfour128;
extern const struct nettle_cipher nettle_camellia128;
extern const struct nettle_cipher nettle_camellia192;
extern const struct nettle_cipher nettle_camellia256;
extern const struct nettle_cipher nettle_cast128;
extern const struct nettle_cipher nettle_serpent128;
extern const struct nettle_cipher nettle_serpent192;
extern const struct nettle_cipher nettle_serpent256;
extern const struct nettle_cipher nettle_twofish128;
extern const struct nettle_cipher nettle_twofish192;
extern const struct nettle_cipher nettle_twofish256;
extern const struct nettle_cipher nettle_arctwo40;
extern const struct nettle_cipher nettle_arctwo64;
extern const struct nettle_cipher nettle_arctwo128;
extern const struct nettle_cipher nettle_arctwo_gutmann128;
struct nettle_hash
{
const char *name;
/* Size of the context struct */
unsigned context_size;
/* Size of digests */
unsigned digest_size;
/* Internal block size */
unsigned block_size;
nettle_hash_init_func *init;
nettle_hash_update_func *update;
nettle_hash_digest_func *digest;
};
#define _NETTLE_HASH(name, NAME) { \
#name, \
sizeof(struct name##_ctx), \
NAME##_DIGEST_SIZE, \
NAME##_DATA_SIZE, \
(nettle_hash_init_func *) name##_init, \
(nettle_hash_update_func *) name##_update, \
(nettle_hash_digest_func *) name##_digest \
}
/* null-terminated list of digests implemented by this version of nettle */
extern const struct nettle_hash * const nettle_hashes[];
extern const struct nettle_hash nettle_md2;
extern const struct nettle_hash nettle_md4;
extern const struct nettle_hash nettle_md5;
extern const struct nettle_hash nettle_gosthash94;
extern const struct nettle_hash nettle_ripemd160;
extern const struct nettle_hash nettle_sha1;
extern const struct nettle_hash nettle_sha224;
extern const struct nettle_hash nettle_sha256;
extern const struct nettle_hash nettle_sha384;
extern const struct nettle_hash nettle_sha512;
extern const struct nettle_hash nettle_sha3_224;
extern const struct nettle_hash nettle_sha3_256;
extern const struct nettle_hash nettle_sha3_384;
extern const struct nettle_hash nettle_sha3_512;
struct nettle_armor
{
const char *name;
unsigned encode_context_size;
unsigned decode_context_size;
unsigned encode_final_length;
nettle_armor_init_func *encode_init;
nettle_armor_length_func *encode_length;
nettle_armor_encode_update_func *encode_update;
nettle_armor_encode_final_func *encode_final;
nettle_armor_init_func *decode_init;
nettle_armor_length_func *decode_length;
nettle_armor_decode_update_func *decode_update;
nettle_armor_decode_final_func *decode_final;
};
#define _NETTLE_ARMOR(name, NAME) { \
#name, \
sizeof(struct name##_encode_ctx), \
sizeof(struct name##_decode_ctx), \
NAME##_ENCODE_FINAL_LENGTH, \
(nettle_armor_init_func *) name##_encode_init, \
(nettle_armor_length_func *) name##_encode_length, \
(nettle_armor_encode_update_func *) name##_encode_update, \
(nettle_armor_encode_final_func *) name##_encode_final, \
(nettle_armor_init_func *) name##_decode_init, \
(nettle_armor_length_func *) name##_decode_length, \
(nettle_armor_decode_update_func *) name##_decode_update, \
(nettle_armor_decode_final_func *) name##_decode_final, \
}
#define _NETTLE_ARMOR_0(name, NAME) { \
#name, \
0, \
sizeof(struct name##_decode_ctx), \
NAME##_ENCODE_FINAL_LENGTH, \
(nettle_armor_init_func *) name##_encode_init, \
(nettle_armor_length_func *) name##_encode_length, \
(nettle_armor_encode_update_func *) name##_encode_update, \
(nettle_armor_encode_final_func *) name##_encode_final, \
(nettle_armor_init_func *) name##_decode_init, \
(nettle_armor_length_func *) name##_decode_length, \
(nettle_armor_decode_update_func *) name##_decode_update, \
(nettle_armor_decode_final_func *) name##_decode_final, \
}
/* null-terminated list of armor schemes implemented by this version of nettle */
extern const struct nettle_armor * const nettle_armors[];
extern const struct nettle_armor nettle_base64;
extern const struct nettle_armor nettle_base16;
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_META_H_INCLUDED */
This diff is collapsed.
/* nettle-types.h */
/* nettle, low-level cryptographics library
*
* Copyright (C) 2005 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_TYPES_H
#define NETTLE_TYPES_H
/* Pretend these types always exists. Nettle doesn't use them. */
#define _STDINT_HAVE_INT_FAST32_T 1
#include "nettle-stdint.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Randomness. Used by key generation and dsa signature creation. */
typedef void nettle_random_func(void *ctx,
unsigned length, uint8_t *dst);
/* Progress report function, mainly for key generation. */
typedef void nettle_progress_func(void *ctx, int c);
/* Realloc function, used by struct nettle_buffer. */
typedef void *nettle_realloc_func(void *ctx, void *p, unsigned length);
/* Ciphers */
typedef void nettle_set_key_func(void *ctx,
unsigned length,
const uint8_t *key);
/* Uses a void * for cipher contexts.
For block ciphers it would make sense with a const void * for the
context, but we use the same typedef for stream ciphers where the
internal state changes during the encryption. */
typedef void nettle_crypt_func(void *ctx,
unsigned length, uint8_t *dst,
const uint8_t *src);
/* Hash algorithms */
typedef void nettle_hash_init_func(void *ctx);
typedef void nettle_hash_update_func(void *ctx,
unsigned length,
const uint8_t *src);
typedef void nettle_hash_digest_func(void *ctx,
unsigned length, uint8_t *dst);
/* ASCII armor codecs. NOTE: Experimental and subject to change. */
typedef unsigned nettle_armor_length_func(unsigned length);
typedef void nettle_armor_init_func(void *ctx);
typedef unsigned nettle_armor_encode_update_func(void *ctx,
uint8_t *dst,
unsigned src_length,
const uint8_t *src);
typedef unsigned nettle_armor_encode_final_func(void *ctx, uint8_t *dst);
typedef int nettle_armor_decode_update_func(void *ctx,
unsigned *dst_length,
uint8_t *dst,
unsigned src_length,
const uint8_t *src);
typedef int nettle_armor_decode_final_func(void *ctx);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_TYPES_H */
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/* sha.h
*
* This file is deprecated, and provided only for backwards
* compatibility with earlier versions of Nettle. Please use sha1.h
* and/or sha2.h instead.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2001 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#ifndef NETTLE_SHA_H_INCLUDED
#define NETTLE_SHA_H_INCLUDED
#include "sha1.h"
#include "sha2.h"
#endif /* NETTLE_SHA_H_INCLUDED */
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment