-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #229 from keepkey/pub640
Pub640
- Loading branch information
Showing
60 changed files
with
1,916 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule python-keepkey
updated
5 files
+17 −0 | keepkeylib/client.py | |
+31 −0 | keepkeylib/ripple.py | |
+35 −0 | keepkeylib/tools.py | |
+55 −0 | tests/test_msg_ripple_get_address.py | |
+124 −0 | tests/test_msg_ripple_sign_tx.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
set(sources aes128_cbc.c) | ||
|
||
if(NOT ${KK_EMULATOR}) | ||
set(sources ${sources} | ||
SecAESSTM32/src/aes/affine_aes.S | ||
SecAESSTM32/src/aes/aes.c) | ||
endif() | ||
|
||
include_directories( | ||
${CMAKE_CURRENT_SOURCE_DIR}/SecAESSTM32/src/aes) | ||
|
||
add_library(SecAESSTM32 ${sources}) |
Submodule SecAESSTM32
added at
71d356
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#include "aes_sca/aes.h" | ||
#include "trezor/crypto/aes/aes.h" | ||
#include "trezor/crypto/memzero.h" | ||
|
||
#include <string.h> | ||
|
||
AES_RETURN aes128_cbc_sca_encrypt(const unsigned char *key, const unsigned char *ibuf, unsigned char *obuf, | ||
int len, unsigned char *iv) | ||
{ | ||
#ifdef EMULATOR | ||
# warning "aes128 encryption is not SCA-hardened in this build." | ||
aes_encrypt_ctx ctx; | ||
aes_encrypt_key128(key, &ctx); | ||
aes_cbc_encrypt(ibuf, obuf, len, iv, &ctx); | ||
memzero(&ctx, sizeof(ctx)); | ||
return EXIT_SUCCESS; | ||
#else | ||
int nb = len >> AES_BLOCK_SIZE_P2; | ||
STRUCT_AES fctx; | ||
unsigned char out[16]; | ||
|
||
if(len & (AES_BLOCK_SIZE - 1)) | ||
return EXIT_FAILURE; | ||
|
||
while(nb--) | ||
{ | ||
iv[ 0] ^= ibuf[ 0]; iv[ 1] ^= ibuf[ 1]; | ||
iv[ 2] ^= ibuf[ 2]; iv[ 3] ^= ibuf[ 3]; | ||
iv[ 4] ^= ibuf[ 4]; iv[ 5] ^= ibuf[ 5]; | ||
iv[ 6] ^= ibuf[ 6]; iv[ 7] ^= ibuf[ 7]; | ||
iv[ 8] ^= ibuf[ 8]; iv[ 9] ^= ibuf[ 9]; | ||
iv[10] ^= ibuf[10]; iv[11] ^= ibuf[11]; | ||
iv[12] ^= ibuf[12]; iv[13] ^= ibuf[13]; | ||
iv[14] ^= ibuf[14]; iv[15] ^= ibuf[15]; | ||
|
||
// if(aes_encrypt(iv, iv, ctx) != EXIT_SUCCESS) | ||
if(aes(MODE_KEYINIT|MODE_AESINIT_ENC|MODE_ENC, &fctx, key, iv, out, NULL, NULL) != NO_ERROR) | ||
return EXIT_FAILURE; | ||
memcpy(iv, out, AES_BLOCK_SIZE); | ||
|
||
memcpy(obuf, iv, AES_BLOCK_SIZE); | ||
ibuf += AES_BLOCK_SIZE; | ||
obuf += AES_BLOCK_SIZE; | ||
} | ||
|
||
return EXIT_SUCCESS; | ||
#endif | ||
} | ||
|
||
AES_RETURN aes128_cbc_sca_decrypt(const unsigned char *key, const unsigned char *ibuf, unsigned char *obuf, | ||
int len, unsigned char *iv) | ||
{ | ||
#ifdef EMULATOR | ||
# warning "aes128 decryption is not SCA-hardened in this build." | ||
aes_decrypt_ctx ctx; | ||
aes_decrypt_key128(key, &ctx); | ||
aes_cbc_decrypt(ibuf, obuf, len, iv, &ctx); | ||
memzero(&ctx, sizeof(ctx)); | ||
return EXIT_SUCCESS; | ||
#else | ||
unsigned char tmp[AES_BLOCK_SIZE]; | ||
int nb = len >> AES_BLOCK_SIZE_P2; | ||
STRUCT_AES fctx; | ||
|
||
|
||
if(len & (AES_BLOCK_SIZE - 1)) | ||
return EXIT_FAILURE; | ||
|
||
while(nb--) | ||
{ | ||
memcpy(tmp, ibuf, AES_BLOCK_SIZE); | ||
|
||
// if(aes_decrypt(ibuf, obuf, ctx) != EXIT_SUCCESS) | ||
if(aes(MODE_KEYINIT|MODE_AESINIT_DEC|MODE_DEC, &fctx, key, ibuf, obuf, NULL, NULL) != NO_ERROR) | ||
return EXIT_FAILURE; | ||
|
||
obuf[ 0] ^= iv[ 0]; obuf[ 1] ^= iv[ 1]; | ||
obuf[ 2] ^= iv[ 2]; obuf[ 3] ^= iv[ 3]; | ||
obuf[ 4] ^= iv[ 4]; obuf[ 5] ^= iv[ 5]; | ||
obuf[ 6] ^= iv[ 6]; obuf[ 7] ^= iv[ 7]; | ||
obuf[ 8] ^= iv[ 8]; obuf[ 9] ^= iv[ 9]; | ||
obuf[10] ^= iv[10]; obuf[11] ^= iv[11]; | ||
obuf[12] ^= iv[12]; obuf[13] ^= iv[13]; | ||
obuf[14] ^= iv[14]; obuf[15] ^= iv[15]; | ||
memcpy(iv, tmp, AES_BLOCK_SIZE); | ||
ibuf += AES_BLOCK_SIZE; | ||
obuf += AES_BLOCK_SIZE; | ||
} | ||
|
||
return EXIT_SUCCESS; | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../SecAESSTM32/src/aes/aes.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#ifndef AES128_CBC_H | ||
#define AES128_CBC_H | ||
|
||
#include "trezor/crypto/aes/aes.h" | ||
|
||
AES_RETURN aes128_cbc_sca_encrypt( | ||
const unsigned char *key, | ||
const unsigned char *ibuf, | ||
unsigned char *obuf, | ||
int len, | ||
unsigned char *iv); | ||
|
||
AES_RETURN aes128_cbc_sca_decrypt( | ||
const unsigned char *key, | ||
const unsigned char *ibuf, | ||
unsigned char *obuf, | ||
int len, | ||
unsigned char *iv); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../SecAESSTM32/src/aes/affine_aes.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../SecAESSTM32/src/aes/compiler_abstraction.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
extern "C" { | ||
#include "keepkey/firmware/coins.h" | ||
#include "keepkey/firmware/ripple.h" | ||
#include "keepkey/firmware/ripple_base58.h" | ||
#include "trezor/crypto/hasher.h" | ||
} | ||
|
||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { | ||
if (size != 33) | ||
return 0; | ||
|
||
uint8_t buff[64]; | ||
memset(buff, 0, sizeof(buff)); | ||
|
||
Hasher hasher; | ||
hasher_Init(&hasher, HASHER_SHA2_RIPEMD); | ||
hasher_Update(&hasher, data, 33); | ||
hasher_Final(&hasher, buff + 1); | ||
|
||
char address[56]; | ||
if (!ripple_encode_check(buff, 21, HASHER_SHA2D, | ||
address, MAX_ADDR_SIZE)) | ||
return 1; | ||
|
||
uint8_t addr_raw[MAX_ADDR_RAW_SIZE]; | ||
memset(addr_raw, 0, sizeof(addr_raw)); | ||
uint32_t addr_raw_len = ripple_decode_check(address, HASHER_SHA2D, | ||
addr_raw, MAX_ADDR_RAW_SIZE); | ||
if (addr_raw_len != 21) | ||
return 2; | ||
|
||
if (memcmp(buff, addr_raw, 21) != 0) | ||
return 3; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../deps/sca-hardening/include/aes_sca |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#ifndef KEEPKEY_BOARD_MEMCMPS_H | ||
#define KEEPKEY_BOARD_MEMCMPS_H | ||
|
||
#include <stddef.h> | ||
|
||
/// Compare two memory regions for equality in constant time. | ||
/// \param lhs must be an array of at least `len` bytes | ||
/// \param rhs must be an array of at least `len` bytes | ||
/// \param len must be in [32, 255), otherwise behavior is undefined. | ||
int memcmp_s(const void *lhs, const void *rhs, size_t len); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* This file is part of the Trezor project, https://trezor.io/ | ||
* | ||
* Copyright (C) 2019 Pavol Rusnak <[email protected]> | ||
* | ||
* 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 __OTP_H__ | ||
#define __OTP_H__ | ||
|
||
#include <stdbool.h> | ||
#include <stdint.h> | ||
|
||
#define FLASH_OTP_NUM_BLOCKS 16 | ||
#define FLASH_OTP_BLOCK_SIZE 32 | ||
|
||
#define FLASH_OTP_BLOCK_RANDOMNESS 3 | ||
|
||
bool flash_otp_is_locked(uint8_t block); | ||
bool flash_otp_lock(uint8_t block); | ||
bool flash_otp_read(uint8_t block, uint8_t offset, uint8_t *data, | ||
uint8_t datalen); | ||
bool flash_otp_write(uint8_t block, uint8_t offset, const uint8_t *data, | ||
uint8_t datalen); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.