Fix 3ds build
This commit is contained in:
parent
7e0c827703
commit
cb3fe622ae
6 changed files with 132 additions and 131 deletions
|
@ -9,15 +9,15 @@
|
||||||
# ifndef OLM_EXPORT
|
# ifndef OLM_EXPORT
|
||||||
# ifdef olm_EXPORTS
|
# ifdef olm_EXPORTS
|
||||||
/* We are building this library */
|
/* We are building this library */
|
||||||
# define OLM_EXPORT __attribute__((visibility("default")))
|
# define OLM_EXPORT
|
||||||
# else
|
# else
|
||||||
/* We are using this library */
|
/* We are using this library */
|
||||||
# define OLM_EXPORT __attribute__((visibility("default")))
|
# define OLM_EXPORT
|
||||||
# endif
|
# endif
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
# ifndef OLM_NO_EXPORT
|
# ifndef OLM_NO_EXPORT
|
||||||
# define OLM_NO_EXPORT __attribute__((visibility("hidden")))
|
# define OLM_NO_EXPORT
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -1,123 +1,123 @@
|
||||||
/*********************************************************************
|
/*********************************************************************
|
||||||
* Filename: aes.h
|
* Filename: aes.h
|
||||||
* Author: Brad Conte (brad AT bradconte.com)
|
* Author: Brad Conte (brad AT bradconte.com)
|
||||||
* Copyright:
|
* Copyright:
|
||||||
* Disclaimer: This code is presented "as is" without any guarantees.
|
* Disclaimer: This code is presented "as is" without any guarantees.
|
||||||
* Details: Defines the API for the corresponding AES implementation.
|
* Details: Defines the API for the corresponding AES implementation.
|
||||||
*********************************************************************/
|
*********************************************************************/
|
||||||
|
|
||||||
#ifndef AES_H
|
#ifndef AES_H
|
||||||
#define AES_H
|
#define AES_H
|
||||||
|
|
||||||
/*************************** HEADER FILES ***************************/
|
/*************************** HEADER FILES ***************************/
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
/****************************** MACROS ******************************/
|
/****************************** MACROS ******************************/
|
||||||
#define AES_BLOCK_SIZE 16 // AES operates on 16 bytes at a time
|
#define AES_BLOCK_SIZE 16 // AES operates on 16 bytes at a time
|
||||||
|
|
||||||
/**************************** DATA TYPES ****************************/
|
/**************************** DATA TYPES ****************************/
|
||||||
typedef unsigned char BYTE; // 8-bit byte
|
typedef uint8_t BYTE; // 8-bit byte
|
||||||
typedef unsigned int WORD; // 32-bit word, change to "long" for 16-bit machines
|
typedef uint32_t WORD; // 32-bit word, change to "long" for 16-bit machines
|
||||||
|
|
||||||
/*********************** FUNCTION DECLARATIONS **********************/
|
/*********************** FUNCTION DECLARATIONS **********************/
|
||||||
///////////////////
|
///////////////////
|
||||||
// AES
|
// AES
|
||||||
///////////////////
|
///////////////////
|
||||||
// Key setup must be done before any AES en/de-cryption functions can be used.
|
// Key setup must be done before any AES en/de-cryption functions can be used.
|
||||||
void aes_key_setup(const BYTE key[], // The key, must be 128, 192, or 256 bits
|
void aes_key_setup(const BYTE key[], // The key, must be 128, 192, or 256 bits
|
||||||
WORD w[], // Output key schedule to be used later
|
WORD w[], // Output key schedule to be used later
|
||||||
int keysize); // Bit length of the key, 128, 192, or 256
|
int keysize); // Bit length of the key, 128, 192, or 256
|
||||||
|
|
||||||
void aes_encrypt(const BYTE in[], // 16 bytes of plaintext
|
void aes_encrypt(const BYTE in[], // 16 bytes of plaintext
|
||||||
BYTE out[], // 16 bytes of ciphertext
|
BYTE out[], // 16 bytes of ciphertext
|
||||||
const WORD key[], // From the key setup
|
const WORD key[], // From the key setup
|
||||||
int keysize); // Bit length of the key, 128, 192, or 256
|
int keysize); // Bit length of the key, 128, 192, or 256
|
||||||
|
|
||||||
void aes_decrypt(const BYTE in[], // 16 bytes of ciphertext
|
void aes_decrypt(const BYTE in[], // 16 bytes of ciphertext
|
||||||
BYTE out[], // 16 bytes of plaintext
|
BYTE out[], // 16 bytes of plaintext
|
||||||
const WORD key[], // From the key setup
|
const WORD key[], // From the key setup
|
||||||
int keysize); // Bit length of the key, 128, 192, or 256
|
int keysize); // Bit length of the key, 128, 192, or 256
|
||||||
|
|
||||||
///////////////////
|
///////////////////
|
||||||
// AES - CBC
|
// AES - CBC
|
||||||
///////////////////
|
///////////////////
|
||||||
int aes_encrypt_cbc(const BYTE in[], // Plaintext
|
int aes_encrypt_cbc(const BYTE in[], // Plaintext
|
||||||
size_t in_len, // Must be a multiple of AES_BLOCK_SIZE
|
size_t in_len, // Must be a multiple of AES_BLOCK_SIZE
|
||||||
BYTE out[], // Ciphertext, same length as plaintext
|
BYTE out[], // Ciphertext, same length as plaintext
|
||||||
const WORD key[], // From the key setup
|
const WORD key[], // From the key setup
|
||||||
int keysize, // Bit length of the key, 128, 192, or 256
|
int keysize, // Bit length of the key, 128, 192, or 256
|
||||||
const BYTE iv[]); // IV, must be AES_BLOCK_SIZE bytes long
|
const BYTE iv[]); // IV, must be AES_BLOCK_SIZE bytes long
|
||||||
|
|
||||||
// Only output the CBC-MAC of the input.
|
// Only output the CBC-MAC of the input.
|
||||||
int aes_encrypt_cbc_mac(const BYTE in[], // plaintext
|
int aes_encrypt_cbc_mac(const BYTE in[], // plaintext
|
||||||
size_t in_len, // Must be a multiple of AES_BLOCK_SIZE
|
size_t in_len, // Must be a multiple of AES_BLOCK_SIZE
|
||||||
BYTE out[], // Output MAC
|
BYTE out[], // Output MAC
|
||||||
const WORD key[], // From the key setup
|
const WORD key[], // From the key setup
|
||||||
int keysize, // Bit length of the key, 128, 192, or 256
|
int keysize, // Bit length of the key, 128, 192, or 256
|
||||||
const BYTE iv[]); // IV, must be AES_BLOCK_SIZE bytes long
|
const BYTE iv[]); // IV, must be AES_BLOCK_SIZE bytes long
|
||||||
|
|
||||||
///////////////////
|
///////////////////
|
||||||
// AES - CTR
|
// AES - CTR
|
||||||
///////////////////
|
///////////////////
|
||||||
void increment_iv(BYTE iv[], // Must be a multiple of AES_BLOCK_SIZE
|
void increment_iv(BYTE iv[], // Must be a multiple of AES_BLOCK_SIZE
|
||||||
int counter_size); // Bytes of the IV used for counting (low end)
|
int counter_size); // Bytes of the IV used for counting (low end)
|
||||||
|
|
||||||
void aes_encrypt_ctr(const BYTE in[], // Plaintext
|
void aes_encrypt_ctr(const BYTE in[], // Plaintext
|
||||||
size_t in_len, // Any byte length
|
size_t in_len, // Any byte length
|
||||||
BYTE out[], // Ciphertext, same length as plaintext
|
BYTE out[], // Ciphertext, same length as plaintext
|
||||||
const WORD key[], // From the key setup
|
const WORD key[], // From the key setup
|
||||||
int keysize, // Bit length of the key, 128, 192, or 256
|
int keysize, // Bit length of the key, 128, 192, or 256
|
||||||
const BYTE iv[]); // IV, must be AES_BLOCK_SIZE bytes long
|
const BYTE iv[]); // IV, must be AES_BLOCK_SIZE bytes long
|
||||||
|
|
||||||
void aes_decrypt_ctr(const BYTE in[], // Ciphertext
|
void aes_decrypt_ctr(const BYTE in[], // Ciphertext
|
||||||
size_t in_len, // Any byte length
|
size_t in_len, // Any byte length
|
||||||
BYTE out[], // Plaintext, same length as ciphertext
|
BYTE out[], // Plaintext, same length as ciphertext
|
||||||
const WORD key[], // From the key setup
|
const WORD key[], // From the key setup
|
||||||
int keysize, // Bit length of the key, 128, 192, or 256
|
int keysize, // Bit length of the key, 128, 192, or 256
|
||||||
const BYTE iv[]); // IV, must be AES_BLOCK_SIZE bytes long
|
const BYTE iv[]); // IV, must be AES_BLOCK_SIZE bytes long
|
||||||
|
|
||||||
///////////////////
|
///////////////////
|
||||||
// AES - CCM
|
// AES - CCM
|
||||||
///////////////////
|
///////////////////
|
||||||
// Returns True if the input parameters do not violate any constraint.
|
// Returns True if the input parameters do not violate any constraint.
|
||||||
int aes_encrypt_ccm(const BYTE plaintext[], // IN - Plaintext.
|
int aes_encrypt_ccm(const BYTE plaintext[], // IN - Plaintext.
|
||||||
WORD plaintext_len, // IN - Plaintext length.
|
WORD plaintext_len, // IN - Plaintext length.
|
||||||
const BYTE associated_data[], // IN - Associated Data included in authentication, but not encryption.
|
const BYTE associated_data[], // IN - Associated Data included in authentication, but not encryption.
|
||||||
unsigned short associated_data_len, // IN - Associated Data length in bytes.
|
unsigned short associated_data_len, // IN - Associated Data length in bytes.
|
||||||
const BYTE nonce[], // IN - The Nonce to be used for encryption.
|
const BYTE nonce[], // IN - The Nonce to be used for encryption.
|
||||||
unsigned short nonce_len, // IN - Nonce length in bytes.
|
unsigned short nonce_len, // IN - Nonce length in bytes.
|
||||||
BYTE ciphertext[], // OUT - Ciphertext, a concatination of the plaintext and the MAC.
|
BYTE ciphertext[], // OUT - Ciphertext, a concatination of the plaintext and the MAC.
|
||||||
WORD *ciphertext_len, // OUT - The length of the ciphertext, always plaintext_len + mac_len.
|
WORD *ciphertext_len, // OUT - The length of the ciphertext, always plaintext_len + mac_len.
|
||||||
WORD mac_len, // IN - The desired length of the MAC, must be 4, 6, 8, 10, 12, 14, or 16.
|
WORD mac_len, // IN - The desired length of the MAC, must be 4, 6, 8, 10, 12, 14, or 16.
|
||||||
const BYTE key[], // IN - The AES key for encryption.
|
const BYTE key[], // IN - The AES key for encryption.
|
||||||
int keysize); // IN - The length of the key in bits. Valid values are 128, 192, 256.
|
int keysize); // IN - The length of the key in bits. Valid values are 128, 192, 256.
|
||||||
|
|
||||||
// Returns True if the input parameters do not violate any constraint.
|
// Returns True if the input parameters do not violate any constraint.
|
||||||
// Use mac_auth to ensure decryption/validation was preformed correctly.
|
// Use mac_auth to ensure decryption/validation was preformed correctly.
|
||||||
// If authentication does not succeed, the plaintext is zeroed out. To overwride
|
// If authentication does not succeed, the plaintext is zeroed out. To overwride
|
||||||
// this, call with mac_auth = NULL. The proper proceedure is to decrypt with
|
// this, call with mac_auth = NULL. The proper proceedure is to decrypt with
|
||||||
// authentication enabled (mac_auth != NULL) and make a second call to that
|
// authentication enabled (mac_auth != NULL) and make a second call to that
|
||||||
// ignores authentication explicitly if the first call failes.
|
// ignores authentication explicitly if the first call failes.
|
||||||
int aes_decrypt_ccm(const BYTE ciphertext[], // IN - Ciphertext, the concatination of encrypted plaintext and MAC.
|
int aes_decrypt_ccm(const BYTE ciphertext[], // IN - Ciphertext, the concatination of encrypted plaintext and MAC.
|
||||||
WORD ciphertext_len, // IN - Ciphertext length in bytes.
|
WORD ciphertext_len, // IN - Ciphertext length in bytes.
|
||||||
const BYTE assoc[], // IN - The Associated Data, required for authentication.
|
const BYTE assoc[], // IN - The Associated Data, required for authentication.
|
||||||
unsigned short assoc_len, // IN - Associated Data length in bytes.
|
unsigned short assoc_len, // IN - Associated Data length in bytes.
|
||||||
const BYTE nonce[], // IN - The Nonce to use for decryption, same one as for encryption.
|
const BYTE nonce[], // IN - The Nonce to use for decryption, same one as for encryption.
|
||||||
unsigned short nonce_len, // IN - Nonce length in bytes.
|
unsigned short nonce_len, // IN - Nonce length in bytes.
|
||||||
BYTE plaintext[], // OUT - The plaintext that was decrypted. Will need to be large enough to hold ciphertext_len - mac_len.
|
BYTE plaintext[], // OUT - The plaintext that was decrypted. Will need to be large enough to hold ciphertext_len - mac_len.
|
||||||
WORD *plaintext_len, // OUT - Length in bytes of the output plaintext, always ciphertext_len - mac_len .
|
WORD *plaintext_len, // OUT - Length in bytes of the output plaintext, always ciphertext_len - mac_len .
|
||||||
WORD mac_len, // IN - The length of the MAC that was calculated.
|
WORD mac_len, // IN - The length of the MAC that was calculated.
|
||||||
int *mac_auth, // OUT - TRUE if authentication succeeded, FALSE if it did not. NULL pointer will ignore the authentication.
|
int *mac_auth, // OUT - TRUE if authentication succeeded, FALSE if it did not. NULL pointer will ignore the authentication.
|
||||||
const BYTE key[], // IN - The AES key for decryption.
|
const BYTE key[], // IN - The AES key for decryption.
|
||||||
int keysize); // IN - The length of the key in BITS. Valid values are 128, 192, 256.
|
int keysize); // IN - The length of the key in BITS. Valid values are 128, 192, 256.
|
||||||
|
|
||||||
///////////////////
|
///////////////////
|
||||||
// Test functions
|
// Test functions
|
||||||
///////////////////
|
///////////////////
|
||||||
int aes_test();
|
int aes_test();
|
||||||
int aes_ecb_test();
|
int aes_ecb_test();
|
||||||
int aes_cbc_test();
|
int aes_cbc_test();
|
||||||
int aes_ctr_test();
|
int aes_ctr_test();
|
||||||
int aes_ccm_test();
|
int aes_ccm_test();
|
||||||
|
|
||||||
#endif // AES_H
|
#endif // AES_H
|
||||||
|
|
|
@ -11,13 +11,14 @@
|
||||||
|
|
||||||
/*************************** HEADER FILES ***************************/
|
/*************************** HEADER FILES ***************************/
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
/****************************** MACROS ******************************/
|
/****************************** MACROS ******************************/
|
||||||
#define SHA256_BLOCK_SIZE 32 // SHA256 outputs a 32 byte digest
|
#define SHA256_BLOCK_SIZE 32 // SHA256 outputs a 32 byte digest
|
||||||
|
|
||||||
/**************************** DATA TYPES ****************************/
|
/**************************** DATA TYPES ****************************/
|
||||||
typedef unsigned char BYTE; // 8-bit byte
|
typedef uint8_t BYTE; // 8-bit byte
|
||||||
typedef unsigned int WORD; // 32-bit word, change to "long" for 16-bit machines
|
typedef uint32_t WORD; // 32-bit word, change to "long" for 16-bit machines
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
BYTE data[64];
|
BYTE data[64];
|
||||||
|
|
|
@ -4498,7 +4498,7 @@ namespace {
|
||||||
sigaltstack(&sigStack, &oldSigStack);
|
sigaltstack(&sigStack, &oldSigStack);
|
||||||
struct sigaction sa = {};
|
struct sigaction sa = {};
|
||||||
sa.sa_handler = handleSignal; // NOLINT
|
sa.sa_handler = handleSignal; // NOLINT
|
||||||
sa.sa_flags = SA_ONSTACK;
|
sa.sa_flags = SS_ONSTACK;
|
||||||
for(std::size_t i = 0; i < DOCTEST_COUNTOF(signalDefs); ++i) {
|
for(std::size_t i = 0; i < DOCTEST_COUNTOF(signalDefs); ++i) {
|
||||||
sigaction(signalDefs[i].id, &sa, &oldSigActions[i]);
|
sigaction(signalDefs[i].id, &sa, &oldSigActions[i]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1684,7 +1684,7 @@ namespace {
|
||||||
sigaltstack(&sigStack, &oldSigStack);
|
sigaltstack(&sigStack, &oldSigStack);
|
||||||
struct sigaction sa = {};
|
struct sigaction sa = {};
|
||||||
sa.sa_handler = handleSignal; // NOLINT
|
sa.sa_handler = handleSignal; // NOLINT
|
||||||
sa.sa_flags = SA_ONSTACK;
|
sa.sa_flags = SS_ONSTACK;
|
||||||
for(std::size_t i = 0; i < DOCTEST_COUNTOF(signalDefs); ++i) {
|
for(std::size_t i = 0; i < DOCTEST_COUNTOF(signalDefs); ++i) {
|
||||||
sigaction(signalDefs[i].id, &sa, &oldSigActions[i]);
|
sigaction(signalDefs[i].id, &sa, &oldSigActions[i]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4498,7 +4498,7 @@ namespace {
|
||||||
sigaltstack(&sigStack, &oldSigStack);
|
sigaltstack(&sigStack, &oldSigStack);
|
||||||
struct sigaction sa = {};
|
struct sigaction sa = {};
|
||||||
sa.sa_handler = handleSignal; // NOLINT
|
sa.sa_handler = handleSignal; // NOLINT
|
||||||
sa.sa_flags = SA_ONSTACK;
|
sa.sa_flags = SS_ONSTACK;
|
||||||
for(std::size_t i = 0; i < DOCTEST_COUNTOF(signalDefs); ++i) {
|
for(std::size_t i = 0; i < DOCTEST_COUNTOF(signalDefs); ++i) {
|
||||||
sigaction(signalDefs[i].id, &sa, &oldSigActions[i]);
|
sigaction(signalDefs[i].id, &sa, &oldSigActions[i]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue