2014-11-15 01:01:21 +00:00
|
|
|
/*
|
2017-11-05 16:46:34 +00:00
|
|
|
* This file is part of the TREZOR project, https://trezor.io/
|
2014-11-15 01:01:21 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2014 Pavol Rusnak <stick@satoshilabs.com>
|
|
|
|
*
|
|
|
|
* This library 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.
|
|
|
|
*
|
|
|
|
* This library 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 library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __CRYPTO_H__
|
|
|
|
#define __CRYPTO_H__
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
2015-06-03 19:21:16 +00:00
|
|
|
#include <ecdsa.h>
|
2016-04-22 15:49:00 +00:00
|
|
|
#include <bip32.h>
|
2014-12-21 18:39:20 +00:00
|
|
|
#include <sha2.h>
|
2014-11-15 01:01:21 +00:00
|
|
|
#include <pb.h>
|
2017-10-30 21:13:09 +00:00
|
|
|
#include "coins.h"
|
2017-12-09 14:38:37 +00:00
|
|
|
#include "hasher.h"
|
2018-07-10 14:58:00 +00:00
|
|
|
#include "messages-bitcoin.pb.h"
|
|
|
|
#include "messages-crypto.pb.h"
|
2014-11-15 01:01:21 +00:00
|
|
|
|
2017-11-08 00:13:21 +00:00
|
|
|
#define ser_length_size(len) ((len) < 253 ? 1 : (len) < 0x10000 ? 3 : 5)
|
|
|
|
|
2014-11-15 01:01:21 +00:00
|
|
|
uint32_t ser_length(uint32_t len, uint8_t *out);
|
|
|
|
|
2017-12-09 14:38:37 +00:00
|
|
|
uint32_t ser_length_hash(Hasher *hasher, uint32_t len);
|
2014-12-21 18:39:20 +00:00
|
|
|
|
2016-06-26 14:27:29 +00:00
|
|
|
int sshMessageSign(HDNode *node, const uint8_t *message, size_t message_len, uint8_t *signature);
|
2015-06-03 19:21:16 +00:00
|
|
|
|
2016-06-26 14:27:29 +00:00
|
|
|
int gpgMessageSign(HDNode *node, const uint8_t *message, size_t message_len, uint8_t *signature);
|
2016-04-15 19:04:45 +00:00
|
|
|
|
2017-10-30 21:13:09 +00:00
|
|
|
int cryptoMessageSign(const CoinInfo *coin, HDNode *node, InputScriptType script_type, const uint8_t *message, size_t message_len, uint8_t *signature);
|
2014-11-15 01:01:21 +00:00
|
|
|
|
2017-11-01 21:18:29 +00:00
|
|
|
int cryptoMessageVerify(const CoinInfo *coin, const uint8_t *message, size_t message_len, const char *address, const uint8_t *signature);
|
2014-11-15 01:01:21 +00:00
|
|
|
|
2016-05-12 19:09:00 +00:00
|
|
|
/* ECIES disabled
|
2014-12-27 13:32:25 +00:00
|
|
|
int cryptoMessageEncrypt(curve_point *pubkey, const uint8_t *msg, size_t msg_size, bool display_only, uint8_t *nonce, size_t *nonce_len, uint8_t *payload, size_t *payload_len, uint8_t *hmac, size_t *hmac_len, const uint8_t *privkey, const uint8_t *address_raw);
|
2014-11-15 01:01:21 +00:00
|
|
|
|
2014-12-27 13:32:25 +00:00
|
|
|
int cryptoMessageDecrypt(curve_point *nonce, uint8_t *payload, size_t payload_len, const uint8_t *hmac, size_t hmac_len, const uint8_t *privkey, uint8_t *msg, size_t *msg_len, bool *display_only, bool *signing, uint8_t *address_raw);
|
2016-05-12 19:09:00 +00:00
|
|
|
*/
|
2014-11-15 01:01:21 +00:00
|
|
|
|
2018-07-10 14:58:00 +00:00
|
|
|
uint8_t *cryptoHDNodePathToPubkey(const CoinInfo *coin, const MultisigRedeemScriptType_HDNodePathType *hdnodepath);
|
2014-12-13 19:33:49 +00:00
|
|
|
|
2017-12-20 16:25:01 +00:00
|
|
|
int cryptoMultisigPubkeyIndex(const CoinInfo *coin, const MultisigRedeemScriptType *multisig, const uint8_t *pubkey);
|
2014-12-13 19:33:49 +00:00
|
|
|
|
2014-12-16 17:56:44 +00:00
|
|
|
int cryptoMultisigFingerprint(const MultisigRedeemScriptType *multisig, uint8_t *hash);
|
2014-12-10 17:04:51 +00:00
|
|
|
|
2015-02-20 19:22:05 +00:00
|
|
|
int cryptoIdentityFingerprint(const IdentityType *identity, uint8_t *hash);
|
|
|
|
|
2014-11-15 01:01:21 +00:00
|
|
|
#endif
|