From 0acdce222ff21c84cafc82c137e3d1e107a66fd9 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Wed, 1 May 2013 17:45:38 +0200 Subject: [PATCH] Add generic crypto headers. They should have been included in commit 9b9230a. --- src/Makefile.am | 3 ++- src/cipher.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ src/crypto.h | 27 +++++++++++++++++++++++++++ src/digest.h | 39 +++++++++++++++++++++++++++++++++++++++ src/ecdh.h | 34 ++++++++++++++++++++++++++++++++++ src/ecdsa.h | 37 +++++++++++++++++++++++++++++++++++++ src/ecdsagen.h | 29 +++++++++++++++++++++++++++++ src/prf.h | 25 +++++++++++++++++++++++++ src/rsa.h | 36 ++++++++++++++++++++++++++++++++++++ src/rsagen.h | 29 +++++++++++++++++++++++++++++ 10 files changed, 304 insertions(+), 1 deletion(-) create mode 100644 src/cipher.h create mode 100644 src/crypto.h create mode 100644 src/digest.h create mode 100644 src/ecdh.h create mode 100644 src/ecdsa.h create mode 100644 src/ecdsagen.h create mode 100644 src/prf.h create mode 100644 src/rsa.h create mode 100644 src/rsagen.h diff --git a/src/Makefile.am b/src/Makefile.am index 3361e3dd..ea77b93e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -106,7 +106,8 @@ INCLUDES = @INCLUDES@ noinst_HEADERS = \ xalloc.h utils.h getopt.h list.h splay_tree.h dropin.h fake-getaddrinfo.h fake-getnameinfo.h fake-gai-errnos.h ipv6.h ipv4.h ethernet.h \ buffer.h conf.h connection.h control.h control_common.h device.h edge.h graph.h info.h logger.h meta.h net.h netutl.h node.h process.h \ - protocol.h route.h subnet.h sptps.h tincctl.h top.h hash.h event.h names.h have.h system.h + protocol.h route.h subnet.h sptps.h tincctl.h top.h hash.h event.h names.h have.h system.h \ + cipher.h crypto.h digest.h ecdh.h ecdsa.h ecdsagen.h prf.h rsa.h rsagen.h LIBS = @LIBS@ @LIBGCRYPT_LIBS@ diff --git a/src/cipher.h b/src/cipher.h new file mode 100644 index 00000000..a3bdc2e7 --- /dev/null +++ b/src/cipher.h @@ -0,0 +1,46 @@ +/* + cipher.h -- header file cipher.c + Copyright (C) 2007-2013 Guus Sliepen + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#ifndef __TINC_CIPHER_H__ +#define __TINC_CIPHER_H__ + +#define CIPHER_MAX_BLOCK_SIZE 32 +#define CIPHER_MAX_IV_SIZE 16 +#define CIPHER_MAX_KEY_SIZE 32 + +typedef struct cipher cipher_t; + +extern cipher_t *cipher_open_by_name(const char *); +extern cipher_t *cipher_open_by_nid(int); +extern cipher_t *cipher_open_blowfish_ofb(void); +extern void cipher_close(cipher_t *); +extern size_t cipher_keylength(const cipher_t *); +extern void cipher_get_key(const cipher_t *, void *); +extern bool cipher_set_key(cipher_t *, void *, bool); +extern bool cipher_set_key_from_rsa(cipher_t *, void *, size_t, bool); +extern bool cipher_set_counter(cipher_t *, const void *, size_t); +extern bool cipher_set_counter_key(cipher_t *, void *); +extern bool cipher_encrypt(cipher_t *, const void *indata, size_t inlen, void *outdata, size_t *outlen, bool oneshot); +extern bool cipher_decrypt(cipher_t *, const void *indata, size_t inlen, void *outdata, size_t *outlen, bool oneshot); +extern bool cipher_counter_xor(cipher_t *, const void *indata, size_t inlen, void *outdata); +extern int cipher_get_nid(const cipher_t *); +extern bool cipher_active(const cipher_t *); + + +#endif diff --git a/src/crypto.h b/src/crypto.h new file mode 100644 index 00000000..cd3654fe --- /dev/null +++ b/src/crypto.h @@ -0,0 +1,27 @@ +/* + crypto.h -- header for crypto.c + Copyright (C) 2007-2013 Guus Sliepen + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#ifndef __TINC_CRYPTO_H__ +#define __TINC_CRYPTO_H__ + +extern void crypto_init(); +extern void crypto_exit(); +extern void randomize(void *, size_t); + +#endif diff --git a/src/digest.h b/src/digest.h new file mode 100644 index 00000000..848b9110 --- /dev/null +++ b/src/digest.h @@ -0,0 +1,39 @@ +/* + digest.h -- header file digest.c + Copyright (C) 2007-2013 Guus Sliepen + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#ifndef __TINC_DIGEST_H__ +#define __TINC_DIGEST_H__ + +#define DIGEST_MAX_SIZE 64 + +typedef struct digest digest_t; + +extern digest_t *digest_open_by_name(const char *name, int maclength); +extern digest_t *digest_open_by_nid(int nid, int maclength); +extern digest_t *digest_open_sha1(int maclength); +extern void digest_close(digest_t *); +extern bool digest_create(digest_t *, const void *indata, size_t inlen, void *outdata); +extern bool digest_verify(digest_t *, const void *indata, size_t inlen, const void *digestdata); +extern bool digest_set_key(digest_t *, const void *key, size_t len); +extern int digest_get_nid(const digest_t *); +extern size_t digest_keylength(const digest_t *); +extern size_t digest_length(const digest_t *); +extern bool digest_active(const digest_t *); + +#endif diff --git a/src/ecdh.h b/src/ecdh.h new file mode 100644 index 00000000..6d3b2f10 --- /dev/null +++ b/src/ecdh.h @@ -0,0 +1,34 @@ +/* + ecdh.h -- header file for ecdh.c + Copyright (C) 2011-2013 Guus Sliepen + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#ifndef __TINC_ECDH_H__ +#define __TINC_ECDH_H__ + +#define ECDH_SIZE 67 +#define ECDH_SHARED_SIZE 66 + +#ifndef __TINC_ECDH_INTERNAL__ +typedef struct ecdh ecdh_t; +#endif + +extern ecdh_t *ecdh_generate_public(void *pubkey); +extern bool ecdh_compute_shared(ecdh_t *ecdh, const void *pubkey, void *shared); +extern void ecdh_free(ecdh_t *ecdh); + +#endif diff --git a/src/ecdsa.h b/src/ecdsa.h new file mode 100644 index 00000000..eac3871c --- /dev/null +++ b/src/ecdsa.h @@ -0,0 +1,37 @@ +/* + ecdsa.h -- ECDSA key handling + Copyright (C) 2011-2013 Guus Sliepen + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#ifndef __TINC_ECDSA_H__ +#define __TINC_ECDSA_H__ + +#ifndef __TINC_ECDSA_INTERNAL__ +typedef struct ecdsa ecdsa_t; +#endif + +extern ecdsa_t *ecdsa_set_base64_public_key(const char *p); +extern char *ecdsa_get_base64_public_key(ecdsa_t *ecdsa); +extern ecdsa_t *ecdsa_read_pem_public_key(FILE *fp); +extern ecdsa_t *ecdsa_read_pem_private_key(FILE *fp); +extern size_t ecdsa_size(ecdsa_t *ecdsa); +extern bool ecdsa_sign(ecdsa_t *ecdsa, const void *in, size_t inlen, void *out); +extern bool ecdsa_verify(ecdsa_t *ecdsa, const void *in, size_t inlen, const void *out); +extern bool ecdsa_active(ecdsa_t *ecdsa); +extern void ecdsa_free(ecdsa_t *ecdsa); + +#endif diff --git a/src/ecdsagen.h b/src/ecdsagen.h new file mode 100644 index 00000000..2f373ab4 --- /dev/null +++ b/src/ecdsagen.h @@ -0,0 +1,29 @@ +/* + ecdsagen.h -- ECDSA key generation and export + Copyright (C) 2011-2013 Guus Sliepen + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#ifndef __TINC_ECDSAGEN_H__ +#define __TINC_ECDSAGEN_H__ + +#include "ecdsa.h" + +extern ecdsa_t *ecdsa_generate(void); +extern bool ecdsa_write_pem_public_key(ecdsa_t *ecdsa, FILE *fp); +extern bool ecdsa_write_pem_private_key(ecdsa_t *ecdsa, FILE *fp); + +#endif diff --git a/src/prf.h b/src/prf.h new file mode 100644 index 00000000..f7ecc644 --- /dev/null +++ b/src/prf.h @@ -0,0 +1,25 @@ +/* + prf.h -- header file for prf.c + Copyright (C) 2011-2013 Guus Sliepen + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#ifndef __TINC_PRF_H__ +#define __TINC_PRF_H__ + +extern bool prf(const char *secret, size_t secretlen, char *seed, size_t seedlen, char *out, size_t outlen); + +#endif diff --git a/src/rsa.h b/src/rsa.h new file mode 100644 index 00000000..5b539038 --- /dev/null +++ b/src/rsa.h @@ -0,0 +1,36 @@ +/* + rsa.h -- RSA key handling + Copyright (C) 2007-2013 Guus Sliepen + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#ifndef __TINC_RSA_H__ +#define __TINC_RSA_H__ + +#ifndef __TINC_RSA_INTERNAL__ +typedef struct rsa rsa_t; +#endif + +extern void rsa_free(rsa_t *rsa); +extern rsa_t *rsa_set_hex_public_key(char *n, char *e); +extern rsa_t *rsa_set_hex_private_key(char *n, char *e, char *d); +extern rsa_t *rsa_read_pem_public_key(FILE *fp); +extern rsa_t *rsa_read_pem_private_key(FILE *fp); +extern size_t rsa_size(rsa_t *rsa); +extern bool rsa_public_encrypt(rsa_t *rsa, void *in, size_t len, void *out); +extern bool rsa_private_decrypt(rsa_t *rsa, void *in, size_t len, void *out); + +#endif diff --git a/src/rsagen.h b/src/rsagen.h new file mode 100644 index 00000000..3f9c8248 --- /dev/null +++ b/src/rsagen.h @@ -0,0 +1,29 @@ +/* + rsagen.h -- RSA key generation and export + Copyright (C) 2008-2013 Guus Sliepen + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#ifndef __TINC_RSAGEN_H__ +#define __TINC_RSAGEN_H__ + +#include "rsa.h" + +extern rsa_t *rsa_generate(size_t bits, unsigned long exponent); +extern bool rsa_write_pem_public_key(rsa_t *rsa, FILE *fp); +extern bool rsa_write_pem_private_key(rsa_t *rsa, FILE *fp); + +#endif -- 2.20.1