Add generic crypto headers.
authorGuus Sliepen <guus@tinc-vpn.org>
Wed, 1 May 2013 15:45:38 +0000 (17:45 +0200)
committerGuus Sliepen <guus@tinc-vpn.org>
Wed, 1 May 2013 15:58:30 +0000 (17:58 +0200)
They should have been included in commit 9b9230a.

src/Makefile.am
src/cipher.h [new file with mode: 0644]
src/crypto.h [new file with mode: 0644]
src/digest.h [new file with mode: 0644]
src/ecdh.h [new file with mode: 0644]
src/ecdsa.h [new file with mode: 0644]
src/ecdsagen.h [new file with mode: 0644]
src/prf.h [new file with mode: 0644]
src/rsa.h [new file with mode: 0644]
src/rsagen.h [new file with mode: 0644]

index 3361e3d..ea77b93 100644 (file)
@@ -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 (file)
index 0000000..a3bdc2e
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+    cipher.h -- header file cipher.c
+    Copyright (C) 2007-2013 Guus Sliepen <guus@tinc-vpn.org>
+
+    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 (file)
index 0000000..cd3654f
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+    crypto.h -- header for crypto.c
+    Copyright (C) 2007-2013 Guus Sliepen <guus@tinc-vpn.org>
+
+    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 (file)
index 0000000..848b911
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+    digest.h -- header file digest.c
+    Copyright (C) 2007-2013 Guus Sliepen <guus@tinc-vpn.org>
+
+    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 (file)
index 0000000..6d3b2f1
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+    ecdh.h -- header file for ecdh.c
+    Copyright (C) 2011-2013 Guus Sliepen <guus@tinc-vpn.org>
+
+    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 (file)
index 0000000..eac3871
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+    ecdsa.h -- ECDSA key handling
+    Copyright (C) 2011-2013 Guus Sliepen <guus@tinc-vpn.org>
+
+    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 (file)
index 0000000..2f373ab
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+    ecdsagen.h -- ECDSA key generation and export
+    Copyright (C) 2011-2013 Guus Sliepen <guus@tinc-vpn.org>
+
+    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 (file)
index 0000000..f7ecc64
--- /dev/null
+++ b/src/prf.h
@@ -0,0 +1,25 @@
+/*
+    prf.h -- header file for prf.c
+    Copyright (C) 2011-2013 Guus Sliepen <guus@tinc-vpn.org>
+
+    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 (file)
index 0000000..5b53903
--- /dev/null
+++ b/src/rsa.h
@@ -0,0 +1,36 @@
+/*
+    rsa.h -- RSA key handling
+    Copyright (C) 2007-2013 Guus Sliepen <guus@tinc-vpn.org>
+
+    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 (file)
index 0000000..3f9c824
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+    rsagen.h -- RSA key generation and export
+    Copyright (C) 2008-2013 Guus Sliepen <guus@tinc-vpn.org>
+
+    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