Basic API design (initial commit)

This commit is contained in:
Daan Sprenkels
2017-04-05 14:21:52 +02:00
commit 4129408d8b
5 changed files with 177 additions and 0 deletions

3
.editorconfig Normal file
View File

@@ -0,0 +1,3 @@
[*.{c,h}]
indent_style = tab
indent_size = 8

52
.gitignore vendored Normal file
View File

@@ -0,0 +1,52 @@
# Prerequisites
*.d
# Object files
*.o
*.ko
*.obj
*.elf
# Linker output
*.ilk
*.map
*.exp
# Precompiled Headers
*.gch
*.pch
# Libraries
*.lib
*.a
*.la
*.lo
# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib
# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex
# Debug files
*.dSYM/
*.su
*.idb
*.pdb
# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf

21
LICENSE Normal file
View File

@@ -0,0 +1,21 @@
The MIT License
Copyright (c) 2017 Daan Sprenkels <hello@dsprenkels.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.

34
hazmat.h Normal file
View File

@@ -0,0 +1,34 @@
/*
* Low level API for Daan Sprenkels' Shamir secret sharing library
* Copyright (c) 2017 Daan Sprenkels <hello@dsprenkels.com>
*
* Usage of this API is hazardous and is only reserved for beings with a
* good understanding of the Shamir secret sharing scheme and who know how
* crypto code is implemented. If you are unsure about this, use the
* intermediate level API. You have been warned!
*/
#ifndef SSS_HAZMAT_H_
#define SSS_HAZMAT_H_
#include <inttypes.h>
typedef struct {
const uint8_t x;
const uint8_t y[32];
} SSS_Keyshare;
void SSS_create_keyshares(SSS_Keyshare *out,
const uint8_t key[32],
uint8_t n,
uint8_t k);
void SSS_combine_keyshares(uint8_t key[32],
const SSS_Keyshare *shares,
uint8_t k);
#endif /* SSS_HAZMAT_H_ */

67
sss.h Normal file
View File

@@ -0,0 +1,67 @@
/*
* Intermediate level API for Daan Sprenkels' Shamir secret sharing library
* Copyright (c) 2017 Daan Sprenkels <hello@dsprenkels.com>
*/
#ifndef SSS_SSS_H_
#define SSS_SSS_H_
#include "hazmat.h"
#include <inttypes.h>
#ifndef SSS_MSGLEN
/*
Length of the message (must be known at compile-time)
*/
#define SSS_MSGLEN sizeof(uint8_t[64])
#endif
/*
* Length of the message authentication code
*/
#define SSS_MACLEN sizeof(uint8_t[16])
/*
* One share of a secret which is shared using Shamir's
* the `SSS_CreateShares` function.
*/
typedef struct {
SSS_Keyshare keyshare;
uint8_t ciphertext[SSS_MSGLEN];
uint8_t mac[SSS_MACLEN];
} SSS_Share;
/*
* Create `n` shares of the secret data `data`. Share such that `k` or more
* shares will be able to restore the secret.
*
* This function will put the resulting shares in the array pointed to by
* `out`. The caller has to guarantee that this array will fit at least `n`
* instances of `SSS_Share`.
*/
void SSS_create_shares(SSS_Share *out,
const uint8_t *data,
uint8_t n,
uint8_t k);
/*
* Combine the `k` shares pointed to by `shares` and put the resulting secret
* data in `data`. The caller has to ensure that the `data` array will fit
* at least `SSS_MSGLEN` (default: 64) bytes.
*
* On success, this function will return 0. If combining the secret fails,
* this function will return a nonzero return code. On failure, the value
* in `data` may have been altered, but must still be considered secret.
*/
int SSS_combine_shares(uint8_t *data,
const SSS_Share *shares,
uint8_t k);
#endif /* SSS_SSS_H_ */