diff --git a/include/sxt/ciphers.h b/include/sxt/ciphers.h new file mode 100644 index 0000000..f4f6a8c --- /dev/null +++ b/include/sxt/ciphers.h @@ -0,0 +1,74 @@ +/* + * Secure eXtended Message Passing framework + * Secure eXtended Transport layer implementation: (libsxt) + * - very similar to SSH2/TLS + * - using already proven and tested crypto algos + * - better than TLS for message passing + * + * PublicPrivateKeyPairs operation API + * + * (c) Alexander Vdolainen 2016 + * + * libsxmp 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 3 of the License, or + * (at your option) any later version. + * + * libsxmp 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 program. If not, see ."; + * + */ + +#ifndef __SXT_CIPHERS_H__ +#define __SXT_CIPHERS_H__ + +#include + +struct __cipher_stype; + +struct _cipher_ops { + int (*set_encrypt_key)(struct __cipher_stype *c, void *key, void *ivec); + int (*set_decrypt_key)(struct __cipher_stype *c, void *key, void *ivec); + void (*encrypt)(struct __cipher_stype *c, void *in, void *out, + unsigned long len); + void (*decrypt)(struct __cipher_stype *c, void *in, void *out, + unsigned long len); +}; + +typedef struct __cipher_stype { + const char *name; + /* applied to the all ciphers */ + unsigned int blksize; /* block size */ + unsigned int keylen; /* max key length */ + unsigned int keysize; /* actual used key size */ + /* since sxt will try to use different crypto libraries do that stuff now */ + union { + struct _lcrypt_cipher_priv *lcp; + void *priv; + }; + /* functions */ + struct _cipher_ops *f; +} sxt_cipher_t; + +/* API */ + +/* API for workout with table */ +sxt_cipher_t *sxt_cipher_get(const char *); +/* a little bit of internals TODO: move it out there */ +int sxt_cipher_add(const char *name, unsigned int blksize, unsigned int keylen, + struct _cipher_ops *f); + +/* API to deal with cipher */ +const char *sxt_cipher_getname(sxt_cipher_t *); +int sxt_cipher_set_encrypt_key(sxt_cipher_t *, void *, void *); +int sxt_cipher_set_decrypt_key(sxt_cipher_t *, void *, void *); +void sxt_cipher_encrypt(sxt_cipher_t *, void *, void *, unsigned long); +void sxt_cipher_decrypt(sxt_cipher_t *, void *, void *, unsigned long); + +#endif /* __SXT_CIPHERS_H__ */ + diff --git a/include/sxt/lcrypt.h b/include/sxt/lcrypt.h index ee7557a..2b66b39 100644 --- a/include/sxt/lcrypt.h +++ b/include/sxt/lcrypt.h @@ -33,6 +33,12 @@ typedef SHA512_CTX* SHA512CTX; #define SHA512_DIGEST_LEN SHA512_DIGEST_LENGTH +struct _lcrypt_cipher_priv +{ + void *key; + void *ivec; +}; + /* sxt wrapper around random numbers */ int sxt_get_random(void *data, int len, int pseudo);