libsxmp/include/sxt/sxtkey.h

89 lines
2.4 KiB
C
Raw Normal View History

2016-05-31 01:51:07 +03:00
/*
* 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 <avdolainen@zoho.com>
*
* 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 <http://www.gnu.org/licenses/>.";
*
*/
#ifndef __SXT_SXTKEY_H__
#define __SXT_SXTKEY_H__
/* some taken code , copyright left in the header */
#define ED25519_PK_LEN 32
#define ED25519_SK_LEN 64
#define ED25519_SIG_LEN 64
typedef uint8_t ed25519_pubkey[ED25519_PK_LEN];
typedef uint8_t ed25519_privkey[ED25519_SK_LEN];
typedef uint8_t ed25519_signature[ED25519_SIG_LEN];
2016-06-06 00:12:06 +03:00
/* flags */
#define SXT_PPKP_PRIVATE (1 << 2)
#define SXT_PPKP_PUBLIC (1 << 1)
#define SXT_PPKP_IHASH (1 << 1)
#define SXT_PPKP_ENCRYPT (1 << 2)
/* magic values */
#define PPKP_MAGIC "0xbeef0101"
2016-05-31 01:51:07 +03:00
/* here the supported types in SXT */
#define PPKP_ED25519 0xa
typedef struct sxtkey_type {
uint8_t type;
uint8_t flags;
2016-06-02 01:38:50 +03:00
ed25519_pubkey *pubkey;
ed25519_privkey *privkey;
2016-06-16 05:09:59 +03:00
uint64_t hash;
2016-06-02 01:38:50 +03:00
void *priv;
2016-05-31 01:51:07 +03:00
} sxtkey_t;
2016-06-02 01:38:50 +03:00
typedef struct sxtsignature_type {
uint8_t type;
ed25519_signature *sig;
} sxtsignature_t;
/* API */
/* allocate a key */
sxtkey_t *sxt_key_alloc(void);
2016-05-31 05:18:52 +03:00
/* burn i.e. zero all stuff within key structure to be
* hidden in core dump
2016-05-31 05:18:52 +03:00
*/
void sxt_key_burn(sxtkey_t *);
2016-05-31 05:18:52 +03:00
/* free sxt key structure */
void sxt_key_free(sxtkey_t *);
/* generate a keypair, depends on type and optional parameter given
* the last one leaved for stable API, current ed25519 keys doesn't
* need them
2016-05-31 05:18:52 +03:00
*/
int sxt_key_generate(sxtkey_t *, int , int );
2016-06-22 04:51:21 +03:00
/* key custom hash ops */
2016-06-22 05:11:04 +03:00
int sxt_key_assign_hash(sxtkey_t *, uint64_t);
2016-06-22 04:51:21 +03:00
uint64_t sxt_key_hash(const sxtkey_t *);
2016-05-31 05:18:52 +03:00
2016-05-31 01:51:07 +03:00
#endif /* __SXT_SXTKEY_H__ */