2018-09-13 21:58:34 +00:00
|
|
|
/*
|
2018-12-17 00:05:33 +00:00
|
|
|
* Copyright (C) 2018 SoloKeys, Inc. <https://solokeys.com/>
|
|
|
|
*
|
|
|
|
* This file is part of Solo.
|
|
|
|
*
|
|
|
|
* Solo 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 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Solo 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 Solo. If not, see <https://www.gnu.org/licenses/>
|
|
|
|
*
|
|
|
|
* This code is available under licenses for commercial use.
|
|
|
|
* Please contact SoloKeys for more information.
|
|
|
|
*/
|
2018-05-06 18:53:43 +00:00
|
|
|
#ifndef _CRYPTO_H
|
|
|
|
#define _CRYPTO_H
|
|
|
|
|
2018-05-26 15:36:55 +00:00
|
|
|
#include <stddef.h>
|
2018-05-06 18:53:43 +00:00
|
|
|
|
|
|
|
#define USE_SOFTWARE_IMPLEMENTATION
|
|
|
|
|
|
|
|
void crypto_sha256_init();
|
|
|
|
void crypto_sha256_update(uint8_t * data, size_t len);
|
2018-05-13 03:23:03 +00:00
|
|
|
void crypto_sha256_update_secret();
|
2018-05-06 18:53:43 +00:00
|
|
|
void crypto_sha256_final(uint8_t * hash);
|
|
|
|
|
2018-05-23 00:42:34 +00:00
|
|
|
void crypto_sha256_hmac_init(uint8_t * key, uint32_t klen, uint8_t * hmac);
|
|
|
|
void crypto_sha256_hmac_final(uint8_t * key, uint32_t klen, uint8_t * hmac);
|
|
|
|
|
2018-05-07 00:15:18 +00:00
|
|
|
|
|
|
|
void crypto_ecc256_init();
|
2018-05-13 03:23:03 +00:00
|
|
|
void crypto_ecc256_derive_public_key(uint8_t * data, int len, uint8_t * x, uint8_t * y);
|
2018-05-07 00:15:18 +00:00
|
|
|
|
2018-05-26 15:36:55 +00:00
|
|
|
void crypto_ecc256_load_key(uint8_t * data, int len, uint8_t * data2, int len2);
|
2018-05-07 00:15:18 +00:00
|
|
|
void crypto_ecc256_load_attestation_key();
|
2018-07-12 01:55:20 +00:00
|
|
|
void crypto_load_external_key(uint8_t * key, int len);
|
2018-05-07 00:15:18 +00:00
|
|
|
void crypto_ecc256_sign(uint8_t * data, int len, uint8_t * sig);
|
2018-07-12 01:55:20 +00:00
|
|
|
void crypto_ecdsa_sign(uint8_t * data, int len, uint8_t * sig, int MBEDTLS_ECP_ID);
|
2018-05-07 00:15:18 +00:00
|
|
|
|
2018-05-13 03:23:03 +00:00
|
|
|
|
|
|
|
void generate_private_key(uint8_t * data, int len, uint8_t * data2, int len2, uint8_t * privkey);
|
2018-05-17 02:44:31 +00:00
|
|
|
void crypto_ecc256_make_key_pair(uint8_t * pubkey, uint8_t * privkey);
|
2018-05-18 03:11:00 +00:00
|
|
|
void crypto_ecc256_shared_secret(const uint8_t * pubkey, const uint8_t * privkey, uint8_t * shared_secret);
|
|
|
|
|
2018-10-29 00:09:12 +00:00
|
|
|
#define CRYPTO_TRANSPORT_KEY ((uint8_t*)1)
|
|
|
|
#define CRYPTO_MASTER_KEY ((uint8_t*)0)
|
2018-05-26 15:36:55 +00:00
|
|
|
|
|
|
|
void crypto_aes256_init(uint8_t * key, uint8_t * nonce);
|
|
|
|
void crypto_aes256_reset_iv(uint8_t * nonce);
|
2018-05-18 03:11:00 +00:00
|
|
|
|
|
|
|
// buf length must be multiple of 16 bytes
|
|
|
|
void crypto_aes256_decrypt(uint8_t * buf, int lenth);
|
|
|
|
void crypto_aes256_encrypt(uint8_t * buf, int lenth);
|
|
|
|
|
2018-05-23 01:25:44 +00:00
|
|
|
void crypto_reset_master_secret();
|
2018-10-26 04:52:32 +00:00
|
|
|
void crypto_load_master_secret(uint8_t * key);
|
2018-05-18 03:11:00 +00:00
|
|
|
|
2018-05-13 03:23:03 +00:00
|
|
|
|
2018-05-07 00:15:18 +00:00
|
|
|
extern const uint8_t attestation_cert_der[];
|
|
|
|
extern const uint16_t attestation_cert_der_size;
|
|
|
|
|
2018-10-29 00:09:12 +00:00
|
|
|
extern const uint8_t attestation_key[];
|
|
|
|
extern const uint16_t attestation_key_size;
|
2018-05-07 00:15:18 +00:00
|
|
|
|
2018-05-06 18:53:43 +00:00
|
|
|
#endif
|