mirror of
https://github.com/shchmue/Lockpick.git
synced 2024-12-22 19:45:33 +00:00
v1.2.3: Remove mbedtls for libnx crypto
This commit is contained in:
parent
f7dc8f027b
commit
90563f6e63
8
Makefile
8
Makefile
|
@ -32,7 +32,7 @@ include $(DEVKITPRO)/libnx/switch_rules
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
APP_TITLE := Lockpick
|
APP_TITLE := Lockpick
|
||||||
APP_AUTHOR := shchmue
|
APP_AUTHOR := shchmue
|
||||||
APP_VERSION := 1.2.2
|
APP_VERSION := 1.2.3
|
||||||
|
|
||||||
TARGET := $(subst $e ,_,$(notdir $(APP_TITLE)))
|
TARGET := $(subst $e ,_,$(notdir $(APP_TITLE)))
|
||||||
BUILD := build
|
BUILD := build
|
||||||
|
@ -58,13 +58,13 @@ CXXFLAGS := $(CFLAGS) -std=gnu++17 -fno-rtti -fno-exceptions
|
||||||
ASFLAGS := -g $(ARCH)
|
ASFLAGS := -g $(ARCH)
|
||||||
LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
|
LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
|
||||||
|
|
||||||
LIBS := -lnx -lmbedcrypto -lstdc++fs `freetype-config --libs`
|
LIBS := -lnx -lstdc++fs `freetype-config --libs`
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
# list of directories containing libraries, this must be the top level containing
|
# list of directories containing libraries, this must be the top level containing
|
||||||
# include and lib
|
# include and lib
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
LIBDIRS := $(PORTLIBS) $(LIBNX) $(TOPDIR)/source/mbedtls
|
LIBDIRS := $(PORTLIBS) $(LIBNX)
|
||||||
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
|
@ -150,13 +150,11 @@ all: $(BUILD)
|
||||||
|
|
||||||
$(BUILD):
|
$(BUILD):
|
||||||
@[ -d $@ ] || mkdir -p $@ $(BUILD) $(OUTDIR)
|
@[ -d $@ ] || mkdir -p $@ $(BUILD) $(OUTDIR)
|
||||||
$(MAKE) -C source/mbedtls/lib all
|
|
||||||
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
|
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
clean:
|
clean:
|
||||||
@echo clean ...
|
@echo clean ...
|
||||||
$(MAKE) -C source/mbedtls/lib clean
|
|
||||||
@rm -fr $(BUILD) $(OUTDIR) $(TARGET).pfs0 $(TARGET).nso $(TARGET).nro $(TARGET).nacp $(TARGET).elf
|
@rm -fr $(BUILD) $(OUTDIR) $(TARGET).pfs0 $(TARGET).nso $(TARGET).nro $(TARGET).nacp $(TARGET).elf
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ Notes
|
||||||
|
|
||||||
Building
|
Building
|
||||||
=
|
=
|
||||||
Release built with `libnx v2.0.0` but still builds and runs with `v1.6.0`.
|
Release built with [libnx commit d2e2c15](https://github.com/switchbrew/libnx/tree/d2e2c159374f18c22350846019f2a615cb35b523).
|
||||||
|
|
||||||
Uses `freetype` which comes with `switch-portlibs` via `devkitPro pacman`:
|
Uses `freetype` which comes with `switch-portlibs` via `devkitPro pacman`:
|
||||||
```
|
```
|
||||||
|
@ -59,13 +59,12 @@ Special Thanks
|
||||||
* Shouts out to fellow key derivers: shadowninja108 for [HACGUI](https://github.com/shadowninja108/HACGUI), Thealexbarney for [Libhac](https://github.com/Thealexbarney/LibHac), and [rajkosto](https://github.com/rajkosto/) :eyes:
|
* Shouts out to fellow key derivers: shadowninja108 for [HACGUI](https://github.com/shadowninja108/HACGUI), Thealexbarney for [Libhac](https://github.com/Thealexbarney/LibHac), and [rajkosto](https://github.com/rajkosto/) :eyes:
|
||||||
* [misson2000](https://github.com/misson20000) for help with `std::invoke` to get the function timer working
|
* [misson2000](https://github.com/misson20000) for help with `std::invoke` to get the function timer working
|
||||||
* [Simon](https://github.com/simontime) for the `eticket_rsa_kek` derivation method and for suggesting invoking `spl` for faster titlekey derivation
|
* [Simon](https://github.com/simontime) for the `eticket_rsa_kek` derivation method and for suggesting invoking `spl` for faster titlekey derivation
|
||||||
|
* [SciresM](https://github.com/SciresM) for the libnx aes library
|
||||||
* The constantly-improving docs on [Switchbrew wiki](https://switchbrew.org/wiki/) and [libnx](https://switchbrew.github.io/libnx/files.html)
|
* The constantly-improving docs on [Switchbrew wiki](https://switchbrew.org/wiki/) and [libnx](https://switchbrew.github.io/libnx/files.html)
|
||||||
* Literally the friends I made along the way! I came to the scene late and I've still managed to meet some wonderful people :) Thanks for all the help testing, making suggestions, and cheerleading!
|
* Literally the friends I made along the way! I came to the scene late and I've still managed to meet some wonderful people :) Thanks for all the help testing, making suggestions, and cheerleading!
|
||||||
|
|
||||||
Licenses
|
Licenses
|
||||||
=
|
=
|
||||||
* `AES` functions are from [mbedtls 2.13.0](https://tls.mbed.org/) licensed under [GPLv2](source/mbedtls/gpl-2.0.txt)
|
|
||||||
* Aarch64 assembly `sha256` is from [Atmosphère](https://github.com/atmosphere-NX/Atmosphere) licensed under [GPLv2](https://github.com/Atmosphere-NX/Atmosphere/blob/master/LICENSE)
|
|
||||||
* `es` ipc code is from [Tinfoil](https://github.com/Adubbz/Tinfoil) licensed under [MIT](https://github.com/Adubbz/Tinfoil/blob/master/LICENSE)
|
* `es` ipc code is from [Tinfoil](https://github.com/Adubbz/Tinfoil) licensed under [MIT](https://github.com/Adubbz/Tinfoil/blob/master/LICENSE)
|
||||||
* `FatFs R0.13c` is located [here](http://elm-chan.org/fsw/ff/00index_e.html) and is licensed under its own [BSD-style license](source/fatfs/LICENSE.txt)
|
* `FatFs R0.13c` is located [here](http://elm-chan.org/fsw/ff/00index_e.html) and is licensed under its own [BSD-style license](source/fatfs/LICENSE.txt)
|
||||||
* Simple `xxHash` implementation is from [stbrumme](https://github.com/stbrumme/xxhash) licensed under [MIT](https://github.com/stbrumme/xxhash/blob/master/LICENSE)
|
* Simple `xxHash` implementation is from [stbrumme](https://github.com/stbrumme/xxhash) licensed under [MIT](https://github.com/stbrumme/xxhash/blob/master/LICENSE)
|
||||||
|
|
|
@ -1,4 +1,9 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
## Version 1.2.3
|
||||||
|
* Remove mbedtls dependency in favor of new libnx crypto library
|
||||||
|
* Remove libnx 1.6.0 support since crypto requires later commit
|
||||||
|
* Skip contradictory messaging if skipping keyfile save
|
||||||
|
|
||||||
## Version 1.2.2
|
## Version 1.2.2
|
||||||
* Do not overwrite existing keyfile that contains master_key_07
|
* Do not overwrite existing keyfile that contains master_key_07
|
||||||
* Read eticket_rsa_kek from existing keyfile in case user is only running this for titlekeys
|
* Read eticket_rsa_kek from existing keyfile in case user is only running this for titlekeys
|
||||||
|
|
|
@ -32,18 +32,10 @@
|
||||||
|
|
||||||
#include <switch.h>
|
#include <switch.h>
|
||||||
|
|
||||||
#include "sha256.h"
|
|
||||||
|
|
||||||
#ifdef RGBX8
|
|
||||||
#define LIBNX_200
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace Common {
|
namespace Common {
|
||||||
static u32 framebuf_width = 0;
|
static u32 framebuf_width = 0;
|
||||||
#ifdef LIBNX_200
|
|
||||||
static Framebuffer fb;
|
static Framebuffer fb;
|
||||||
static u32 stride;
|
static u32 stride;
|
||||||
#endif
|
|
||||||
static u32 *framebuf;
|
static u32 *framebuf;
|
||||||
// FreeType vars
|
// FreeType vars
|
||||||
static FT_Library library;
|
static FT_Library library;
|
||||||
|
@ -119,28 +111,19 @@ namespace Common {
|
||||||
|
|
||||||
PlFontData font;
|
PlFontData font;
|
||||||
|
|
||||||
#ifndef LIBNX_200
|
|
||||||
consoleInit(NULL);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
plGetSharedFontByType(&font, PlSharedFontType_Standard);
|
plGetSharedFontByType(&font, PlSharedFontType_Standard);
|
||||||
|
|
||||||
FT_Init_FreeType(&library);
|
FT_Init_FreeType(&library);
|
||||||
FT_New_Memory_Face(library, static_cast<FT_Byte *>(font.address), font.size, 0, &face);
|
FT_New_Memory_Face(library, static_cast<FT_Byte *>(font.address), font.size, 0, &face);
|
||||||
FT_Set_Char_Size(face, 0, 6*64, 300, 300);
|
FT_Set_Char_Size(face, 0, 6*64, 300, 300);
|
||||||
|
|
||||||
#ifdef LIBNX_200
|
|
||||||
framebufferCreate(&fb, nwindowGetDefault(), FB_WIDTH, FB_HEIGHT, PIXEL_FORMAT_RGBA_8888, 2);
|
framebufferCreate(&fb, nwindowGetDefault(), FB_WIDTH, FB_HEIGHT, PIXEL_FORMAT_RGBA_8888, 2);
|
||||||
framebufferMakeLinear(&fb);
|
framebufferMakeLinear(&fb);
|
||||||
framebuf = (u32 *)framebufferBegin(&fb, &stride);
|
framebuf = (u32 *)framebufferBegin(&fb, &stride);
|
||||||
framebuf_width = stride / sizeof(u32);
|
framebuf_width = stride / sizeof(u32);
|
||||||
memset(framebuf, 0, stride*FB_HEIGHT);
|
memset(framebuf, 0, stride*FB_HEIGHT);
|
||||||
framebufferEnd(&fb);
|
framebufferEnd(&fb);
|
||||||
#else
|
|
||||||
gfxSetMode(GfxMode_LinearDouble);
|
|
||||||
framebuf = (u32 *)gfxGetFramebuffer(&framebuf_width, NULL);
|
|
||||||
memset(framebuf, 0, gfxGetFramebufferSize());
|
|
||||||
#endif
|
|
||||||
draw_text(0x010, 0x020, YELLOW, "Lockpick! by shchmue");
|
draw_text(0x010, 0x020, YELLOW, "Lockpick! by shchmue");
|
||||||
draw_text(0x190, 0x020, YELLOW, "Note: This can only dump keys 00-05 (or 00-06 on 6.2.0)");
|
draw_text(0x190, 0x020, YELLOW, "Note: This can only dump keys 00-05 (or 00-06 on 6.2.0)");
|
||||||
draw_text(0x190, 0x040, YELLOW, "Use Lockpick_RCM for newer keys on firmware 7.0.0+!");
|
draw_text(0x190, 0x040, YELLOW, "Use Lockpick_RCM for newer keys on firmware 7.0.0+!");
|
||||||
|
@ -229,11 +212,7 @@ namespace Common {
|
||||||
update_display();
|
update_display();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef LIBNX_200
|
|
||||||
framebufferClose(&fb);
|
framebufferClose(&fb);
|
||||||
#else
|
|
||||||
consoleExit(NULL);
|
|
||||||
#endif
|
|
||||||
FT_Done_Face(face);
|
FT_Done_Face(face);
|
||||||
FT_Done_FreeType(library);
|
FT_Done_FreeType(library);
|
||||||
|
|
||||||
|
@ -241,20 +220,8 @@ namespace Common {
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_display() {
|
void update_display() {
|
||||||
#ifdef LIBNX_200
|
|
||||||
framebufferBegin(&fb, &stride);
|
framebufferBegin(&fb, &stride);
|
||||||
framebufferEnd(&fb);
|
framebufferEnd(&fb);
|
||||||
#else
|
|
||||||
consoleUpdate(NULL);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void sha256(const u8 *data, u8 *hash, size_t length) {
|
|
||||||
struct sha256_state ctx;
|
|
||||||
sha256_init(&ctx);
|
|
||||||
sha256_update(&ctx, data, length);
|
|
||||||
sha256_finalize(&ctx);
|
|
||||||
sha256_finish(&ctx, hash);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
byte_vector key_string_to_byte_vector(std::string key_string) {
|
byte_vector key_string_to_byte_vector(std::string key_string) {
|
||||||
|
|
|
@ -67,7 +67,6 @@ namespace Common {
|
||||||
// refresh display
|
// refresh display
|
||||||
void update_display();
|
void update_display();
|
||||||
|
|
||||||
void sha256(const u8 *data, u8 *hash, size_t length);
|
|
||||||
// reads "<keyname> = <hexkey>" and returns byte vector
|
// reads "<keyname> = <hexkey>" and returns byte vector
|
||||||
byte_vector key_string_to_byte_vector(std::string key_string);
|
byte_vector key_string_to_byte_vector(std::string key_string);
|
||||||
}
|
}
|
|
@ -19,12 +19,10 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <mbedtls/aes.h>
|
|
||||||
#include <mbedtls/cmac.h>
|
|
||||||
|
|
||||||
#include "Common.hpp"
|
|
||||||
#include "xxhash64.h"
|
#include "xxhash64.h"
|
||||||
|
|
||||||
|
#include <switch.h>
|
||||||
|
|
||||||
size_t Key::saved_key_count = 0;
|
size_t Key::saved_key_count = 0;
|
||||||
|
|
||||||
Key::Key(std::string name, u64 xx_hash, byte_vector hash, u8 length, byte_vector key) :
|
Key::Key(std::string name, u64 xx_hash, byte_vector hash, u8 length, byte_vector key) :
|
||||||
|
@ -86,16 +84,9 @@ byte_vector Key::aes_decrypt_ctr(const byte_vector &data, byte_vector iv) {
|
||||||
if (!found())
|
if (!found())
|
||||||
return dest;
|
return dest;
|
||||||
|
|
||||||
// used internally
|
Aes128CtrContext con;
|
||||||
size_t nc_off = 0;
|
aes128CtrContextCreate(&con, key.data(), iv.data());
|
||||||
u8 stream_block[0x10];
|
aes128CtrCrypt(&con, dest.data(), data.data(), data.size());
|
||||||
|
|
||||||
mbedtls_aes_context dec;
|
|
||||||
mbedtls_aes_init(&dec);
|
|
||||||
mbedtls_aes_setkey_enc(&dec, key.data(), length * 8);
|
|
||||||
mbedtls_aes_crypt_ctr(&dec, data.size(), &nc_off, iv.data(), stream_block, data.data(), dest.data());
|
|
||||||
mbedtls_aes_free(&dec);
|
|
||||||
|
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,13 +95,10 @@ byte_vector Key::aes_decrypt_ecb(const byte_vector &data) {
|
||||||
if (!found())
|
if (!found())
|
||||||
return dest;
|
return dest;
|
||||||
|
|
||||||
mbedtls_aes_context dec;
|
Aes128Context con;
|
||||||
mbedtls_aes_init(&dec);
|
aes128ContextCreate(&con, key.data(), false);
|
||||||
mbedtls_aes_setkey_dec(&dec, key.data(), length * 8);
|
|
||||||
for (size_t offset = 0; offset < data.size(); offset += 0x10)
|
for (size_t offset = 0; offset < data.size(); offset += 0x10)
|
||||||
mbedtls_aes_crypt_ecb(&dec, MBEDTLS_AES_DECRYPT, data.data() + offset, dest.data() + offset);
|
aes128DecryptBlock(&con, dest.data() + offset, data.data() + offset);
|
||||||
mbedtls_aes_free(&dec);
|
|
||||||
|
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,8 +107,7 @@ byte_vector Key::cmac(byte_vector data) {
|
||||||
if (!found())
|
if (!found())
|
||||||
return dest;
|
return dest;
|
||||||
|
|
||||||
mbedtls_cipher_cmac(mbedtls_cipher_info_from_type(MBEDTLS_CIPHER_AES_128_ECB), key.data(), length * 8, data.data(), data.size(), dest.data());
|
cmacAes128CalculateMac(dest.data(), key.data(), data.data(), data.size());
|
||||||
|
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,7 +118,7 @@ void Key::find_key(const byte_vector &buffer, size_t start) {
|
||||||
u8 temp_hash[0x20];
|
u8 temp_hash[0x20];
|
||||||
|
|
||||||
if (buffer.size() == length) {
|
if (buffer.size() == length) {
|
||||||
Common::sha256(buffer.data(), temp_hash, length);
|
sha256CalculateHash(temp_hash, buffer.data(), length);
|
||||||
if (!std::equal(hash.begin(), hash.end(), temp_hash))
|
if (!std::equal(hash.begin(), hash.end(), temp_hash))
|
||||||
return;
|
return;
|
||||||
std::copy(buffer.begin(), buffer.begin() + length, std::back_inserter(key));
|
std::copy(buffer.begin(), buffer.begin() + length, std::back_inserter(key));
|
||||||
|
@ -143,7 +130,7 @@ void Key::find_key(const byte_vector &buffer, size_t start) {
|
||||||
for (size_t i = start; i < buffer.size() - length; i++) {
|
for (size_t i = start; i < buffer.size() - length; i++) {
|
||||||
if (xx_hash == XXHash64::hash(buffer.data() + i, length, 0)) {
|
if (xx_hash == XXHash64::hash(buffer.data() + i, length, 0)) {
|
||||||
// double-check sha256 since xxhash64 isn't as collision-safe
|
// double-check sha256 since xxhash64 isn't as collision-safe
|
||||||
Common::sha256(buffer.data() + i, temp_hash, length);
|
sha256CalculateHash(temp_hash, buffer.data() + i, length);
|
||||||
if (!std::equal(hash.begin(), hash.end(), temp_hash))
|
if (!std::equal(hash.begin(), hash.end(), temp_hash))
|
||||||
continue;
|
continue;
|
||||||
std::copy(buffer.begin() + i, buffer.begin() + i + length, std::back_inserter(key));
|
std::copy(buffer.begin() + i, buffer.begin() + i + length, std::back_inserter(key));
|
||||||
|
|
|
@ -273,9 +273,11 @@ void KeyCollection::get_keys() {
|
||||||
Common::draw_text_with_time(0x10, 0x110, GREEN, "Total time elapsed:", total_time.get_elapsed());
|
Common::draw_text_with_time(0x10, 0x110, GREEN, "Total time elapsed:", total_time.get_elapsed());
|
||||||
|
|
||||||
char keys_str[32];
|
char keys_str[32];
|
||||||
|
if (!Lockpick_RCM_file_found) {
|
||||||
sprintf(keys_str, "Total keys found: %lu", Key::get_saved_key_count());
|
sprintf(keys_str, "Total keys found: %lu", Key::get_saved_key_count());
|
||||||
Common::draw_text(0x2a0, 0x110, CYAN, keys_str);
|
Common::draw_text(0x2a0, 0x110, CYAN, keys_str);
|
||||||
Common::draw_text(0x80, 0x140, YELLOW, "Keys saved to \"/switch/prod.keys\"!");
|
Common::draw_text(0x80, 0x140, YELLOW, "Keys saved to \"/switch/prod.keys\"!");
|
||||||
|
}
|
||||||
|
|
||||||
Common::draw_text(0x10, 0x170, CYAN, "Dumping titlekeys...");
|
Common::draw_text(0x10, 0x170, CYAN, "Dumping titlekeys...");
|
||||||
Common::update_display();
|
Common::update_display();
|
||||||
|
@ -727,15 +729,15 @@ void KeyCollection::get_titlekeys() {
|
||||||
void KeyCollection::mgf1(const u8 *data, size_t data_length, u8 *mask, size_t mask_length) {
|
void KeyCollection::mgf1(const u8 *data, size_t data_length, u8 *mask, size_t mask_length) {
|
||||||
u8 data_counter[data_length + 4] = {};
|
u8 data_counter[data_length + 4] = {};
|
||||||
std::copy(data, data + data_length, data_counter);
|
std::copy(data, data + data_length, data_counter);
|
||||||
Common::sha256(data_counter, mask, data_length + 4);
|
sha256CalculateHash(mask, data_counter, data_length + 4);
|
||||||
for (u32 i = 1; i < (mask_length / 0x20) + 1; i++) {
|
for (u32 i = 1; i < (mask_length / 0x20) + 1; i++) {
|
||||||
for (size_t j = 0; j < 4; j++)
|
for (size_t j = 0; j < 4; j++)
|
||||||
data_counter[data_length + 3 - j] = (i >> (8 * j)) & 0xff;
|
data_counter[data_length + 3 - j] = (i >> (8 * j)) & 0xff;
|
||||||
if (i * 0x20 <= mask_length)
|
if (i * 0x20 <= mask_length)
|
||||||
Common::sha256(data_counter, mask + (i * 0x20), data_length + 4);
|
sha256CalculateHash(mask + (i * 0x20), data_counter, data_length + 4);
|
||||||
else {
|
else {
|
||||||
u8 temp_mask[0x20];
|
u8 temp_mask[0x20];
|
||||||
Common::sha256(data_counter, temp_mask, data_length + 4);
|
sha256CalculateHash(temp_mask, data_counter, data_length + 4);
|
||||||
std::copy(temp_mask, temp_mask + mask_length - (i * 0x20), mask + (i * 0x20));
|
std::copy(temp_mask, temp_mask + mask_length - (i * 0x20), mask + (i * 0x20));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
|
|
||||||
#include "KeyLocation.hpp"
|
#include "KeyLocation.hpp"
|
||||||
|
|
||||||
#include "Common.hpp"
|
|
||||||
#include "xxhash64.h"
|
#include "xxhash64.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
@ -114,7 +113,7 @@ void KeyLocation::find_keys(std::vector<Key *> &keys) {
|
||||||
size_t key_index = hash_index[hash];
|
size_t key_index = hash_index[hash];
|
||||||
u8 key_length = keys[key_index]->length;
|
u8 key_length = keys[key_index]->length;
|
||||||
// double-check sha256 since xxhash64 isn't as collision-safe
|
// double-check sha256 since xxhash64 isn't as collision-safe
|
||||||
Common::sha256(data.data() + i, temp_hash, key_length);
|
sha256CalculateHash(temp_hash, data.data() + i, key_length);
|
||||||
if (!std::equal(keys[key_index]->hash.begin(), keys[key_index]->hash.end(), temp_hash))
|
if (!std::equal(keys[key_index]->hash.begin(), keys[key_index]->hash.end(), temp_hash))
|
||||||
continue;
|
continue;
|
||||||
std::copy(data.begin() + i, data.begin() + i + key_length, std::back_inserter(keys[key_index]->key));
|
std::copy(data.begin() + i, data.begin() + i + key_length, std::back_inserter(keys[key_index]->key));
|
||||||
|
|
28
source/mbedtls/.gitignore
vendored
28
source/mbedtls/.gitignore
vendored
|
@ -1,28 +0,0 @@
|
||||||
CMakeCache.txt
|
|
||||||
CMakeFiles
|
|
||||||
CTestTestfile.cmake
|
|
||||||
cmake_install.cmake
|
|
||||||
Testing
|
|
||||||
Coverage
|
|
||||||
*.gcno
|
|
||||||
*.gcda
|
|
||||||
|
|
||||||
# generated by scripts/memory.sh
|
|
||||||
massif-*
|
|
||||||
|
|
||||||
# MSVC files generated by CMake:
|
|
||||||
/*.sln
|
|
||||||
/*.vcxproj
|
|
||||||
/*.filters
|
|
||||||
|
|
||||||
# MSVC build artifacts:
|
|
||||||
*.exe
|
|
||||||
*.pdb
|
|
||||||
*.ilk
|
|
||||||
*.lib
|
|
||||||
|
|
||||||
# Python build artifacts:
|
|
||||||
*.pyc
|
|
||||||
|
|
||||||
# CMake generates *.dir/ folders for in-tree builds (used by MSVC projects), ignore all of those:
|
|
||||||
*.dir/
|
|
|
@ -1,2 +0,0 @@
|
||||||
This package of mbed TLS is specifically licensed under the GPL 2.0,
|
|
||||||
as can be found in: gpl-2.0.txt
|
|
|
@ -1,218 +0,0 @@
|
||||||
README for Mbed TLS
|
|
||||||
===================
|
|
||||||
|
|
||||||
Configuration
|
|
||||||
-------------
|
|
||||||
|
|
||||||
Mbed TLS should build out of the box on most systems. Some platform specific options are available in the fully documented configuration file `include/mbedtls/config.h`, which is also the place where features can be selected. This file can be edited manually, or in a more programmatic way using the Perl script `scripts/config.pl` (use `--help` for usage instructions).
|
|
||||||
|
|
||||||
Compiler options can be set using conventional environment variables such as `CC` and `CFLAGS` when using the Make and CMake build system (see below).
|
|
||||||
|
|
||||||
Compiling
|
|
||||||
---------
|
|
||||||
|
|
||||||
There are currently four active build systems used within Mbed TLS releases:
|
|
||||||
|
|
||||||
- yotta
|
|
||||||
- GNU Make
|
|
||||||
- CMake
|
|
||||||
- Microsoft Visual Studio (Microsoft Visual Studio 2010 or later)
|
|
||||||
|
|
||||||
The main systems used for development are CMake and GNU Make. Those systems are always complete and up-to-date. The others should reflect all changes present in the CMake and Make build system, although features may not be ported there automatically.
|
|
||||||
|
|
||||||
Yotta, as a build system, is slightly different from the other build systems:
|
|
||||||
|
|
||||||
- it provides a minimalistic configuration file by default
|
|
||||||
- depending on the yotta target, features of Mbed OS may be used in examples and tests
|
|
||||||
|
|
||||||
The Make and CMake build systems create three libraries: libmbedcrypto, libmbedx509, and libmbedtls. Note that libmbedtls depends on libmbedx509 and libmbedcrypto, and libmbedx509 depends on libmbedcrypto. As a result, some linkers will expect flags to be in a specific order, for example the GNU linker wants `-lmbedtls -lmbedx509 -lmbedcrypto`. Also, when loading shared libraries using dlopen(), you'll need to load libmbedcrypto first, then libmbedx509, before you can load libmbedtls.
|
|
||||||
|
|
||||||
### Yotta
|
|
||||||
|
|
||||||
[yotta](http://yottabuild.org) is a package manager and build system developed by Mbed, and is the build system of Mbed OS 16.03. To install it on your platform, please follow the yotta [installation instructions](http://docs.yottabuild.org/#installing).
|
|
||||||
|
|
||||||
Once yotta is installed, you can use it to download the latest version of Mbed TLS from the yotta registry with:
|
|
||||||
|
|
||||||
yotta install mbedtls
|
|
||||||
|
|
||||||
and build it with:
|
|
||||||
|
|
||||||
yotta build
|
|
||||||
|
|
||||||
If, on the other hand, you already have a copy of Mbed TLS from a source other than the yotta registry, for example from cloning our GitHub repository, or from downloading a tarball of the standalone edition, then you'll first need to generate the yotta module by running:
|
|
||||||
|
|
||||||
yotta/create-module.sh
|
|
||||||
|
|
||||||
This should be executed from the root Mbed TLS project directory. This will create the yotta module in the `yotta/module` directory within it. You can then change to that directory and build as usual:
|
|
||||||
|
|
||||||
cd yotta/module
|
|
||||||
yotta build
|
|
||||||
|
|
||||||
In any case, you'll probably want to set the yotta target before building unless it has already been set globally. For more information on using yotta, please consult the [yotta documentation](http://docs.yottabuild.org/).
|
|
||||||
|
|
||||||
For more details on the yotta/Mbed OS edition of Mbed TLS, including example programs, please consult the [Readme at the root of the yotta module](https://github.com/ARMmbed/mbedtls/blob/development/yotta/data/README.md).
|
|
||||||
|
|
||||||
### Make
|
|
||||||
|
|
||||||
We require GNU Make. To build the library and the sample programs, GNU Make and a C compiler are sufficient. Some of the more advanced build targets require some Unix/Linux tools.
|
|
||||||
|
|
||||||
We intentionally only use a minimum of functionality in the makefiles in order to keep them as simple and independent of different toolchains as possible, to allow users to more easily move between different platforms. Users who need more features are recommended to use CMake.
|
|
||||||
|
|
||||||
In order to build from the source code using GNU Make, just enter at the command line:
|
|
||||||
|
|
||||||
make
|
|
||||||
|
|
||||||
In order to run the tests, enter:
|
|
||||||
|
|
||||||
make check
|
|
||||||
|
|
||||||
The tests need Perl to be built and run. If you don't have Perl installed, you can skip building the tests with:
|
|
||||||
|
|
||||||
make no_test
|
|
||||||
|
|
||||||
You'll still be able to run a much smaller set of tests with:
|
|
||||||
|
|
||||||
programs/test/selftest
|
|
||||||
|
|
||||||
In order to build for a Windows platform, you should use `WINDOWS_BUILD=1` if the target is Windows but the build environment is Unix-like (for instance when cross-compiling, or compiling from an MSYS shell), and `WINDOWS=1` if the build environment is a Windows shell (for instance using mingw32-make) (in that case some targets will not be available).
|
|
||||||
|
|
||||||
Setting the variable `SHARED` in your environment will build shared libraries in addition to the static libraries. Setting `DEBUG` gives you a debug build. You can override `CFLAGS` and `LDFLAGS` by setting them in your environment or on the make command line; compiler warning options may be overridden separately using `WARNING_CFLAGS`. Some directory-specific options (for example, `-I` directives) are still preserved.
|
|
||||||
|
|
||||||
Please note that setting `CFLAGS` overrides its default value of `-O2` and setting `WARNING_CFLAGS` overrides its default value (starting with `-Wall -W`), so it you just want to add some warning options to the default ones, you can do so by setting `CFLAGS=-O2 -Werror` for example. Setting `WARNING_CFLAGS` is useful when you want to get rid of its default content (for example because your compiler doesn't accept `-Wall` as an option). Directory-specific options cannot be overriden from the command line.
|
|
||||||
|
|
||||||
Depending on your platform, you might run into some issues. Please check the Makefiles in `library/`, `programs/` and `tests/` for options to manually add or remove for specific platforms. You can also check [the Mbed TLS Knowledge Base](https://tls.mbed.org/kb) for articles on your platform or issue.
|
|
||||||
|
|
||||||
In case you find that you need to do something else as well, please let us know what, so we can add it to the [Mbed TLS Knowledge Base](https://tls.mbed.org/kb).
|
|
||||||
|
|
||||||
### CMake
|
|
||||||
|
|
||||||
In order to build the source using CMake in a separate directory (recommended), just enter at the command line:
|
|
||||||
|
|
||||||
mkdir /path/to/build_dir && cd /path/to/build_dir
|
|
||||||
cmake /path/to/mbedtls_source
|
|
||||||
make
|
|
||||||
|
|
||||||
In order to run the tests, enter:
|
|
||||||
|
|
||||||
make test
|
|
||||||
|
|
||||||
The test suites need Perl to be built. If you don't have Perl installed, you'll want to disable the test suites with:
|
|
||||||
|
|
||||||
cmake -DENABLE_TESTING=Off /path/to/mbedtls_source
|
|
||||||
|
|
||||||
If you disabled the test suites, but kept the programs enabled, you can still run a much smaller set of tests with:
|
|
||||||
|
|
||||||
programs/test/selftest
|
|
||||||
|
|
||||||
To configure CMake for building shared libraries, use:
|
|
||||||
|
|
||||||
cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On /path/to/mbedtls_source
|
|
||||||
|
|
||||||
There are many different build modes available within the CMake buildsystem. Most of them are available for gcc and clang, though some are compiler-specific:
|
|
||||||
|
|
||||||
- `Release`. This generates the default code without any unnecessary information in the binary files.
|
|
||||||
- `Debug`. This generates debug information and disables optimization of the code.
|
|
||||||
- `Coverage`. This generates code coverage information in addition to debug information.
|
|
||||||
- `ASan`. This instruments the code with AddressSanitizer to check for memory errors. (This includes LeakSanitizer, with recent version of gcc and clang.) (With recent version of clang, this mode also instruments the code with UndefinedSanitizer to check for undefined behaviour.)
|
|
||||||
- `ASanDbg`. Same as ASan but slower, with debug information and better stack traces.
|
|
||||||
- `MemSan`. This instruments the code with MemorySanitizer to check for uninitialised memory reads. Experimental, needs recent clang on Linux/x86\_64.
|
|
||||||
- `MemSanDbg`. Same as MemSan but slower, with debug information, better stack traces and origin tracking.
|
|
||||||
- `Check`. This activates the compiler warnings that depend on optimization and treats all warnings as errors.
|
|
||||||
|
|
||||||
Switching build modes in CMake is simple. For debug mode, enter at the command line:
|
|
||||||
|
|
||||||
cmake -D CMAKE_BUILD_TYPE=Debug /path/to/mbedtls_source
|
|
||||||
|
|
||||||
To list other available CMake options, use:
|
|
||||||
|
|
||||||
cmake -LH
|
|
||||||
|
|
||||||
Note that, with CMake, you can't adjust the compiler or its flags after the
|
|
||||||
initial invocation of cmake. This means that `CC=your_cc make` and `make
|
|
||||||
CC=your_cc` will *not* work (similarly with `CFLAGS` and other variables).
|
|
||||||
These variables need to be adjusted when invoking cmake for the first time,
|
|
||||||
for example:
|
|
||||||
|
|
||||||
CC=your_cc cmake /path/to/mbedtls_source
|
|
||||||
|
|
||||||
If you already invoked cmake and want to change those settings, you need to
|
|
||||||
remove the build directory and create it again.
|
|
||||||
|
|
||||||
Note that it is possible to build in-place; this will however overwrite the
|
|
||||||
provided Makefiles (see `scripts/tmp_ignore_makefiles.sh` if you want to
|
|
||||||
prevent `git status` from showing them as modified). In order to do so, from
|
|
||||||
the Mbed TLS source directory, use:
|
|
||||||
|
|
||||||
cmake .
|
|
||||||
make
|
|
||||||
|
|
||||||
If you want to change `CC` or `CFLAGS` afterwards, you will need to remove the
|
|
||||||
CMake cache. This can be done with the following command using GNU find:
|
|
||||||
|
|
||||||
find . -iname '*cmake*' -not -name CMakeLists.txt -exec rm -rf {} +
|
|
||||||
|
|
||||||
You can now make the desired change:
|
|
||||||
|
|
||||||
CC=your_cc cmake .
|
|
||||||
make
|
|
||||||
|
|
||||||
Regarding variables, also note that if you set CFLAGS when invoking cmake,
|
|
||||||
your value of CFLAGS doesn't override the content provided by cmake (depending
|
|
||||||
on the build mode as seen above), it's merely prepended to it.
|
|
||||||
|
|
||||||
### Microsoft Visual Studio
|
|
||||||
|
|
||||||
The build files for Microsoft Visual Studio are generated for Visual Studio 2010.
|
|
||||||
|
|
||||||
The solution file `mbedTLS.sln` contains all the basic projects needed to build the library and all the programs. The files in tests are not generated and compiled, as these need a perl environment as well. However, the selftest program in `programs/test/` is still available.
|
|
||||||
|
|
||||||
Example programs
|
|
||||||
----------------
|
|
||||||
|
|
||||||
We've included example programs for a lot of different features and uses in `programs/`. Most programs only focus on a single feature or usage scenario, so keep that in mind when copying parts of the code.
|
|
||||||
|
|
||||||
Tests
|
|
||||||
-----
|
|
||||||
|
|
||||||
Mbed TLS includes an elaborate test suite in `tests/` that initially requires Perl to generate the tests files (e.g. `test\_suite\_mpi.c`). These files are generated from a `function file` (e.g. `suites/test\_suite\_mpi.function`) and a `data file` (e.g. `suites/test\_suite\_mpi.data`). The `function file` contains the test functions. The `data file` contains the test cases, specified as parameters that will be passed to the test function.
|
|
||||||
|
|
||||||
For machines with a Unix shell and OpenSSL (and optionally GnuTLS) installed, additional test scripts are available:
|
|
||||||
|
|
||||||
- `tests/ssl-opt.sh` runs integration tests for various TLS options (renegotiation, resumption, etc.) and tests interoperability of these options with other implementations.
|
|
||||||
- `tests/compat.sh` tests interoperability of every ciphersuite with other implementations.
|
|
||||||
- `tests/scripts/test-ref-configs.pl` test builds in various reduced configurations.
|
|
||||||
- `tests/scripts/key-exchanges.pl` test builds in configurations with a single key exchange enabled
|
|
||||||
- `tests/scripts/all.sh` runs a combination of the above tests, plus some more, with various build options (such as ASan, full `config.h`, etc).
|
|
||||||
|
|
||||||
Configurations
|
|
||||||
--------------
|
|
||||||
|
|
||||||
We provide some non-standard configurations focused on specific use cases in the `configs/` directory. You can read more about those in `configs/README.txt`
|
|
||||||
|
|
||||||
Porting Mbed TLS
|
|
||||||
----------------
|
|
||||||
|
|
||||||
Mbed TLS can be ported to many different architectures, OS's and platforms. Before starting a port, you may find the following Knowledge Base articles useful:
|
|
||||||
|
|
||||||
- [Porting Mbed TLS to a new environment or OS](https://tls.mbed.org/kb/how-to/how-do-i-port-mbed-tls-to-a-new-environment-OS)
|
|
||||||
- [What external dependencies does Mbed TLS rely on?](https://tls.mbed.org/kb/development/what-external-dependencies-does-mbedtls-rely-on)
|
|
||||||
- [How do I configure Mbed TLS](https://tls.mbed.org/kb/compiling-and-building/how-do-i-configure-mbedtls)
|
|
||||||
|
|
||||||
Contributing
|
|
||||||
------------
|
|
||||||
|
|
||||||
We gratefully accept bug reports and contributions from the community. There are some requirements we need to fulfill in order to be able to integrate contributions:
|
|
||||||
|
|
||||||
- All contributions, whether large or small require a Contributor's License Agreement (CLA) to be accepted. This is because source code can possibly fall under copyright law and we need your consent to share in the ownership of the copyright.
|
|
||||||
- We would ask that contributions conform to [our coding standards](https://tls.mbed.org/kb/development/mbedtls-coding-standards), and that contributions should be fully tested before submission.
|
|
||||||
- As with any open source project, contributions will be reviewed by the project team and community and may need some modifications to be accepted.
|
|
||||||
|
|
||||||
To accept the Contributor’s Licence Agreement (CLA), individual contributors can do this by creating an Mbed account and [accepting the online agreement here with a click through](https://os.mbed.com/contributor_agreement/). Alternatively, for contributions from corporations, or those that do not wish to create an Mbed account, a slightly different agreement can be found [here](https://www.mbed.com/en/about-mbed/contributor-license-agreements/). This agreement should be signed and returned to Arm as described in the instructions given.
|
|
||||||
|
|
||||||
### Making a Contribution
|
|
||||||
|
|
||||||
1. [Check for open issues](https://github.com/ARMmbed/mbedtls/issues) or [start a discussion](https://forums.mbed.com/c/mbed-tls) around a feature idea or a bug.
|
|
||||||
2. Fork the [Mbed TLS repository on GitHub](https://github.com/ARMmbed/mbedtls) to start making your changes. As a general rule, you should use the "development" branch as a basis.
|
|
||||||
3. Write a test which shows that the bug was fixed or that the feature works as expected.
|
|
||||||
4. Send a pull request and bug us until it gets merged and published. Contributions may need some modifications, so work with us to get your change accepted. We will include your name in the ChangeLog :)
|
|
||||||
|
|
|
@ -1,339 +0,0 @@
|
||||||
GNU GENERAL PUBLIC LICENSE
|
|
||||||
Version 2, June 1991
|
|
||||||
|
|
||||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
|
||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
|
||||||
of this license document, but changing it is not allowed.
|
|
||||||
|
|
||||||
Preamble
|
|
||||||
|
|
||||||
The licenses for most software are designed to take away your
|
|
||||||
freedom to share and change it. By contrast, the GNU General Public
|
|
||||||
License is intended to guarantee your freedom to share and change free
|
|
||||||
software--to make sure the software is free for all its users. This
|
|
||||||
General Public License applies to most of the Free Software
|
|
||||||
Foundation's software and to any other program whose authors commit to
|
|
||||||
using it. (Some other Free Software Foundation software is covered by
|
|
||||||
the GNU Lesser General Public License instead.) You can apply it to
|
|
||||||
your programs, too.
|
|
||||||
|
|
||||||
When we speak of free software, we are referring to freedom, not
|
|
||||||
price. Our General Public Licenses are designed to make sure that you
|
|
||||||
have the freedom to distribute copies of free software (and charge for
|
|
||||||
this service if you wish), that you receive source code or can get it
|
|
||||||
if you want it, that you can change the software or use pieces of it
|
|
||||||
in new free programs; and that you know you can do these things.
|
|
||||||
|
|
||||||
To protect your rights, we need to make restrictions that forbid
|
|
||||||
anyone to deny you these rights or to ask you to surrender the rights.
|
|
||||||
These restrictions translate to certain responsibilities for you if you
|
|
||||||
distribute copies of the software, or if you modify it.
|
|
||||||
|
|
||||||
For example, if you distribute copies of such a program, whether
|
|
||||||
gratis or for a fee, you must give the recipients all the rights that
|
|
||||||
you have. You must make sure that they, too, receive or can get the
|
|
||||||
source code. And you must show them these terms so they know their
|
|
||||||
rights.
|
|
||||||
|
|
||||||
We protect your rights with two steps: (1) copyright the software, and
|
|
||||||
(2) offer you this license which gives you legal permission to copy,
|
|
||||||
distribute and/or modify the software.
|
|
||||||
|
|
||||||
Also, for each author's protection and ours, we want to make certain
|
|
||||||
that everyone understands that there is no warranty for this free
|
|
||||||
software. If the software is modified by someone else and passed on, we
|
|
||||||
want its recipients to know that what they have is not the original, so
|
|
||||||
that any problems introduced by others will not reflect on the original
|
|
||||||
authors' reputations.
|
|
||||||
|
|
||||||
Finally, any free program is threatened constantly by software
|
|
||||||
patents. We wish to avoid the danger that redistributors of a free
|
|
||||||
program will individually obtain patent licenses, in effect making the
|
|
||||||
program proprietary. To prevent this, we have made it clear that any
|
|
||||||
patent must be licensed for everyone's free use or not licensed at all.
|
|
||||||
|
|
||||||
The precise terms and conditions for copying, distribution and
|
|
||||||
modification follow.
|
|
||||||
|
|
||||||
GNU GENERAL PUBLIC LICENSE
|
|
||||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
|
||||||
|
|
||||||
0. This License applies to any program or other work which contains
|
|
||||||
a notice placed by the copyright holder saying it may be distributed
|
|
||||||
under the terms of this General Public License. The "Program", below,
|
|
||||||
refers to any such program or work, and a "work based on the Program"
|
|
||||||
means either the Program or any derivative work under copyright law:
|
|
||||||
that is to say, a work containing the Program or a portion of it,
|
|
||||||
either verbatim or with modifications and/or translated into another
|
|
||||||
language. (Hereinafter, translation is included without limitation in
|
|
||||||
the term "modification".) Each licensee is addressed as "you".
|
|
||||||
|
|
||||||
Activities other than copying, distribution and modification are not
|
|
||||||
covered by this License; they are outside its scope. The act of
|
|
||||||
running the Program is not restricted, and the output from the Program
|
|
||||||
is covered only if its contents constitute a work based on the
|
|
||||||
Program (independent of having been made by running the Program).
|
|
||||||
Whether that is true depends on what the Program does.
|
|
||||||
|
|
||||||
1. You may copy and distribute verbatim copies of the Program's
|
|
||||||
source code as you receive it, in any medium, provided that you
|
|
||||||
conspicuously and appropriately publish on each copy an appropriate
|
|
||||||
copyright notice and disclaimer of warranty; keep intact all the
|
|
||||||
notices that refer to this License and to the absence of any warranty;
|
|
||||||
and give any other recipients of the Program a copy of this License
|
|
||||||
along with the Program.
|
|
||||||
|
|
||||||
You may charge a fee for the physical act of transferring a copy, and
|
|
||||||
you may at your option offer warranty protection in exchange for a fee.
|
|
||||||
|
|
||||||
2. You may modify your copy or copies of the Program or any portion
|
|
||||||
of it, thus forming a work based on the Program, and copy and
|
|
||||||
distribute such modifications or work under the terms of Section 1
|
|
||||||
above, provided that you also meet all of these conditions:
|
|
||||||
|
|
||||||
a) You must cause the modified files to carry prominent notices
|
|
||||||
stating that you changed the files and the date of any change.
|
|
||||||
|
|
||||||
b) You must cause any work that you distribute or publish, that in
|
|
||||||
whole or in part contains or is derived from the Program or any
|
|
||||||
part thereof, to be licensed as a whole at no charge to all third
|
|
||||||
parties under the terms of this License.
|
|
||||||
|
|
||||||
c) If the modified program normally reads commands interactively
|
|
||||||
when run, you must cause it, when started running for such
|
|
||||||
interactive use in the most ordinary way, to print or display an
|
|
||||||
announcement including an appropriate copyright notice and a
|
|
||||||
notice that there is no warranty (or else, saying that you provide
|
|
||||||
a warranty) and that users may redistribute the program under
|
|
||||||
these conditions, and telling the user how to view a copy of this
|
|
||||||
License. (Exception: if the Program itself is interactive but
|
|
||||||
does not normally print such an announcement, your work based on
|
|
||||||
the Program is not required to print an announcement.)
|
|
||||||
|
|
||||||
These requirements apply to the modified work as a whole. If
|
|
||||||
identifiable sections of that work are not derived from the Program,
|
|
||||||
and can be reasonably considered independent and separate works in
|
|
||||||
themselves, then this License, and its terms, do not apply to those
|
|
||||||
sections when you distribute them as separate works. But when you
|
|
||||||
distribute the same sections as part of a whole which is a work based
|
|
||||||
on the Program, the distribution of the whole must be on the terms of
|
|
||||||
this License, whose permissions for other licensees extend to the
|
|
||||||
entire whole, and thus to each and every part regardless of who wrote it.
|
|
||||||
|
|
||||||
Thus, it is not the intent of this section to claim rights or contest
|
|
||||||
your rights to work written entirely by you; rather, the intent is to
|
|
||||||
exercise the right to control the distribution of derivative or
|
|
||||||
collective works based on the Program.
|
|
||||||
|
|
||||||
In addition, mere aggregation of another work not based on the Program
|
|
||||||
with the Program (or with a work based on the Program) on a volume of
|
|
||||||
a storage or distribution medium does not bring the other work under
|
|
||||||
the scope of this License.
|
|
||||||
|
|
||||||
3. You may copy and distribute the Program (or a work based on it,
|
|
||||||
under Section 2) in object code or executable form under the terms of
|
|
||||||
Sections 1 and 2 above provided that you also do one of the following:
|
|
||||||
|
|
||||||
a) Accompany it with the complete corresponding machine-readable
|
|
||||||
source code, which must be distributed under the terms of Sections
|
|
||||||
1 and 2 above on a medium customarily used for software interchange; or,
|
|
||||||
|
|
||||||
b) Accompany it with a written offer, valid for at least three
|
|
||||||
years, to give any third party, for a charge no more than your
|
|
||||||
cost of physically performing source distribution, a complete
|
|
||||||
machine-readable copy of the corresponding source code, to be
|
|
||||||
distributed under the terms of Sections 1 and 2 above on a medium
|
|
||||||
customarily used for software interchange; or,
|
|
||||||
|
|
||||||
c) Accompany it with the information you received as to the offer
|
|
||||||
to distribute corresponding source code. (This alternative is
|
|
||||||
allowed only for noncommercial distribution and only if you
|
|
||||||
received the program in object code or executable form with such
|
|
||||||
an offer, in accord with Subsection b above.)
|
|
||||||
|
|
||||||
The source code for a work means the preferred form of the work for
|
|
||||||
making modifications to it. For an executable work, complete source
|
|
||||||
code means all the source code for all modules it contains, plus any
|
|
||||||
associated interface definition files, plus the scripts used to
|
|
||||||
control compilation and installation of the executable. However, as a
|
|
||||||
special exception, the source code distributed need not include
|
|
||||||
anything that is normally distributed (in either source or binary
|
|
||||||
form) with the major components (compiler, kernel, and so on) of the
|
|
||||||
operating system on which the executable runs, unless that component
|
|
||||||
itself accompanies the executable.
|
|
||||||
|
|
||||||
If distribution of executable or object code is made by offering
|
|
||||||
access to copy from a designated place, then offering equivalent
|
|
||||||
access to copy the source code from the same place counts as
|
|
||||||
distribution of the source code, even though third parties are not
|
|
||||||
compelled to copy the source along with the object code.
|
|
||||||
|
|
||||||
4. You may not copy, modify, sublicense, or distribute the Program
|
|
||||||
except as expressly provided under this License. Any attempt
|
|
||||||
otherwise to copy, modify, sublicense or distribute the Program is
|
|
||||||
void, and will automatically terminate your rights under this License.
|
|
||||||
However, parties who have received copies, or rights, from you under
|
|
||||||
this License will not have their licenses terminated so long as such
|
|
||||||
parties remain in full compliance.
|
|
||||||
|
|
||||||
5. You are not required to accept this License, since you have not
|
|
||||||
signed it. However, nothing else grants you permission to modify or
|
|
||||||
distribute the Program or its derivative works. These actions are
|
|
||||||
prohibited by law if you do not accept this License. Therefore, by
|
|
||||||
modifying or distributing the Program (or any work based on the
|
|
||||||
Program), you indicate your acceptance of this License to do so, and
|
|
||||||
all its terms and conditions for copying, distributing or modifying
|
|
||||||
the Program or works based on it.
|
|
||||||
|
|
||||||
6. Each time you redistribute the Program (or any work based on the
|
|
||||||
Program), the recipient automatically receives a license from the
|
|
||||||
original licensor to copy, distribute or modify the Program subject to
|
|
||||||
these terms and conditions. You may not impose any further
|
|
||||||
restrictions on the recipients' exercise of the rights granted herein.
|
|
||||||
You are not responsible for enforcing compliance by third parties to
|
|
||||||
this License.
|
|
||||||
|
|
||||||
7. If, as a consequence of a court judgment or allegation of patent
|
|
||||||
infringement or for any other reason (not limited to patent issues),
|
|
||||||
conditions are imposed on you (whether by court order, agreement or
|
|
||||||
otherwise) that contradict the conditions of this License, they do not
|
|
||||||
excuse you from the conditions of this License. If you cannot
|
|
||||||
distribute so as to satisfy simultaneously your obligations under this
|
|
||||||
License and any other pertinent obligations, then as a consequence you
|
|
||||||
may not distribute the Program at all. For example, if a patent
|
|
||||||
license would not permit royalty-free redistribution of the Program by
|
|
||||||
all those who receive copies directly or indirectly through you, then
|
|
||||||
the only way you could satisfy both it and this License would be to
|
|
||||||
refrain entirely from distribution of the Program.
|
|
||||||
|
|
||||||
If any portion of this section is held invalid or unenforceable under
|
|
||||||
any particular circumstance, the balance of the section is intended to
|
|
||||||
apply and the section as a whole is intended to apply in other
|
|
||||||
circumstances.
|
|
||||||
|
|
||||||
It is not the purpose of this section to induce you to infringe any
|
|
||||||
patents or other property right claims or to contest validity of any
|
|
||||||
such claims; this section has the sole purpose of protecting the
|
|
||||||
integrity of the free software distribution system, which is
|
|
||||||
implemented by public license practices. Many people have made
|
|
||||||
generous contributions to the wide range of software distributed
|
|
||||||
through that system in reliance on consistent application of that
|
|
||||||
system; it is up to the author/donor to decide if he or she is willing
|
|
||||||
to distribute software through any other system and a licensee cannot
|
|
||||||
impose that choice.
|
|
||||||
|
|
||||||
This section is intended to make thoroughly clear what is believed to
|
|
||||||
be a consequence of the rest of this License.
|
|
||||||
|
|
||||||
8. If the distribution and/or use of the Program is restricted in
|
|
||||||
certain countries either by patents or by copyrighted interfaces, the
|
|
||||||
original copyright holder who places the Program under this License
|
|
||||||
may add an explicit geographical distribution limitation excluding
|
|
||||||
those countries, so that distribution is permitted only in or among
|
|
||||||
countries not thus excluded. In such case, this License incorporates
|
|
||||||
the limitation as if written in the body of this License.
|
|
||||||
|
|
||||||
9. The Free Software Foundation may publish revised and/or new versions
|
|
||||||
of the General Public License from time to time. Such new versions will
|
|
||||||
be similar in spirit to the present version, but may differ in detail to
|
|
||||||
address new problems or concerns.
|
|
||||||
|
|
||||||
Each version is given a distinguishing version number. If the Program
|
|
||||||
specifies a version number of this License which applies to it and "any
|
|
||||||
later version", you have the option of following the terms and conditions
|
|
||||||
either of that version or of any later version published by the Free
|
|
||||||
Software Foundation. If the Program does not specify a version number of
|
|
||||||
this License, you may choose any version ever published by the Free Software
|
|
||||||
Foundation.
|
|
||||||
|
|
||||||
10. If you wish to incorporate parts of the Program into other free
|
|
||||||
programs whose distribution conditions are different, write to the author
|
|
||||||
to ask for permission. For software which is copyrighted by the Free
|
|
||||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
|
||||||
make exceptions for this. Our decision will be guided by the two goals
|
|
||||||
of preserving the free status of all derivatives of our free software and
|
|
||||||
of promoting the sharing and reuse of software generally.
|
|
||||||
|
|
||||||
NO WARRANTY
|
|
||||||
|
|
||||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
|
||||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
|
||||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
|
||||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
|
||||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
||||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
|
||||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
|
||||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
|
||||||
REPAIR OR CORRECTION.
|
|
||||||
|
|
||||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
|
||||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
|
||||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
|
||||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
|
||||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
|
||||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
|
||||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
|
||||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
|
||||||
POSSIBILITY OF SUCH DAMAGES.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
How to Apply These Terms to Your New Programs
|
|
||||||
|
|
||||||
If you develop a new program, and you want it to be of the greatest
|
|
||||||
possible use to the public, the best way to achieve this is to make it
|
|
||||||
free software which everyone can redistribute and change under these terms.
|
|
||||||
|
|
||||||
To do so, attach the following notices to the program. It is safest
|
|
||||||
to attach them to the start of each source file to most effectively
|
|
||||||
convey the exclusion of warranty; and each file should have at least
|
|
||||||
the "copyright" line and a pointer to where the full notice is found.
|
|
||||||
|
|
||||||
<one line to give the program's name and a brief idea of what it does.>
|
|
||||||
Copyright (C) <year> <name of author>
|
|
||||||
|
|
||||||
This program 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 2 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program 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 this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
|
|
||||||
Also add information on how to contact you by electronic and paper mail.
|
|
||||||
|
|
||||||
If the program is interactive, make it output a short notice like this
|
|
||||||
when it starts in an interactive mode:
|
|
||||||
|
|
||||||
Gnomovision version 69, Copyright (C) year name of author
|
|
||||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
|
||||||
This is free software, and you are welcome to redistribute it
|
|
||||||
under certain conditions; type `show c' for details.
|
|
||||||
|
|
||||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
|
||||||
parts of the General Public License. Of course, the commands you use may
|
|
||||||
be called something other than `show w' and `show c'; they could even be
|
|
||||||
mouse-clicks or menu items--whatever suits your program.
|
|
||||||
|
|
||||||
You should also get your employer (if you work as a programmer) or your
|
|
||||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
|
||||||
necessary. Here is a sample; alter the names:
|
|
||||||
|
|
||||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
|
||||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
|
||||||
|
|
||||||
<signature of Ty Coon>, 1 April 1989
|
|
||||||
Ty Coon, President of Vice
|
|
||||||
|
|
||||||
This General Public License does not permit incorporating your program into
|
|
||||||
proprietary programs. If your program is a subroutine library, you may
|
|
||||||
consider it more useful to permit linking proprietary applications with the
|
|
||||||
library. If this is what you want to do, use the GNU Lesser General
|
|
||||||
Public License instead of this License.
|
|
4
source/mbedtls/include/.gitignore
vendored
4
source/mbedtls/include/.gitignore
vendored
|
@ -1,4 +0,0 @@
|
||||||
Makefile
|
|
||||||
*.sln
|
|
||||||
*.vcxproj
|
|
||||||
mbedtls/check_config
|
|
|
@ -1,16 +0,0 @@
|
||||||
option(INSTALL_MBEDTLS_HEADERS "Install mbed TLS headers." ON)
|
|
||||||
|
|
||||||
if(INSTALL_MBEDTLS_HEADERS)
|
|
||||||
|
|
||||||
file(GLOB headers "mbedtls/*.h")
|
|
||||||
|
|
||||||
install(FILES ${headers}
|
|
||||||
DESTINATION include/mbedtls
|
|
||||||
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
|
|
||||||
|
|
||||||
endif(INSTALL_MBEDTLS_HEADERS)
|
|
||||||
|
|
||||||
# Make config.h available in an out-of-source build. ssl-opt.sh requires it.
|
|
||||||
if (NOT ${CMAKE_CURRENT_BINARY_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
|
|
||||||
link_to_source(mbedtls)
|
|
||||||
endif()
|
|
|
@ -1,628 +0,0 @@
|
||||||
/**
|
|
||||||
* \file aes.h
|
|
||||||
*
|
|
||||||
* \brief This file contains AES definitions and functions.
|
|
||||||
*
|
|
||||||
* The Advanced Encryption Standard (AES) specifies a FIPS-approved
|
|
||||||
* cryptographic algorithm that can be used to protect electronic
|
|
||||||
* data.
|
|
||||||
*
|
|
||||||
* The AES algorithm is a symmetric block cipher that can
|
|
||||||
* encrypt and decrypt information. For more information, see
|
|
||||||
* <em>FIPS Publication 197: Advanced Encryption Standard</em> and
|
|
||||||
* <em>ISO/IEC 18033-2:2006: Information technology -- Security
|
|
||||||
* techniques -- Encryption algorithms -- Part 2: Asymmetric
|
|
||||||
* ciphers</em>.
|
|
||||||
*
|
|
||||||
* The AES-XTS block mode is standardized by NIST SP 800-38E
|
|
||||||
* <https://nvlpubs.nist.gov/nistpubs/legacy/sp/nistspecialpublication800-38e.pdf>
|
|
||||||
* and described in detail by IEEE P1619
|
|
||||||
* <https://ieeexplore.ieee.org/servlet/opac?punumber=4375278>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved.
|
|
||||||
* SPDX-License-Identifier: GPL-2.0
|
|
||||||
*
|
|
||||||
* This program 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 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*
|
|
||||||
* This file is part of Mbed TLS (https://tls.mbed.org)
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef MBEDTLS_AES_H
|
|
||||||
#define MBEDTLS_AES_H
|
|
||||||
|
|
||||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
|
||||||
#include "config.h"
|
|
||||||
#else
|
|
||||||
#include MBEDTLS_CONFIG_FILE
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
/* padlock.c and aesni.c rely on these values! */
|
|
||||||
#define MBEDTLS_AES_ENCRYPT 1 /**< AES encryption. */
|
|
||||||
#define MBEDTLS_AES_DECRYPT 0 /**< AES decryption. */
|
|
||||||
|
|
||||||
/* Error codes in range 0x0020-0x0022 */
|
|
||||||
#define MBEDTLS_ERR_AES_INVALID_KEY_LENGTH -0x0020 /**< Invalid key length. */
|
|
||||||
#define MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH -0x0022 /**< Invalid data input length. */
|
|
||||||
|
|
||||||
/* Error codes in range 0x0021-0x0025 */
|
|
||||||
#define MBEDTLS_ERR_AES_BAD_INPUT_DATA -0x0021 /**< Invalid input data. */
|
|
||||||
#define MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE -0x0023 /**< Feature not available. For example, an unsupported AES key size. */
|
|
||||||
#define MBEDTLS_ERR_AES_HW_ACCEL_FAILED -0x0025 /**< AES hardware accelerator failed. */
|
|
||||||
|
|
||||||
#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
|
|
||||||
!defined(inline) && !defined(__cplusplus)
|
|
||||||
#define inline __inline
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if !defined(MBEDTLS_AES_ALT)
|
|
||||||
// Regular implementation
|
|
||||||
//
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief The AES context-type definition.
|
|
||||||
*/
|
|
||||||
typedef struct mbedtls_aes_context
|
|
||||||
{
|
|
||||||
int nr; /*!< The number of rounds. */
|
|
||||||
uint32_t *rk; /*!< AES round keys. */
|
|
||||||
uint32_t buf[68]; /*!< Unaligned data buffer. This buffer can
|
|
||||||
hold 32 extra Bytes, which can be used for
|
|
||||||
one of the following purposes:
|
|
||||||
<ul><li>Alignment if VIA padlock is
|
|
||||||
used.</li>
|
|
||||||
<li>Simplifying key expansion in the 256-bit
|
|
||||||
case by generating an extra round key.
|
|
||||||
</li></ul> */
|
|
||||||
}
|
|
||||||
mbedtls_aes_context;
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_CIPHER_MODE_XTS)
|
|
||||||
/**
|
|
||||||
* \brief The AES XTS context-type definition.
|
|
||||||
*/
|
|
||||||
typedef struct mbedtls_aes_xts_context
|
|
||||||
{
|
|
||||||
mbedtls_aes_context crypt; /*!< The AES context to use for AES block
|
|
||||||
encryption or decryption. */
|
|
||||||
mbedtls_aes_context tweak; /*!< The AES context used for tweak
|
|
||||||
computation. */
|
|
||||||
} mbedtls_aes_xts_context;
|
|
||||||
#endif /* MBEDTLS_CIPHER_MODE_XTS */
|
|
||||||
|
|
||||||
#else /* MBEDTLS_AES_ALT */
|
|
||||||
#include "aes_alt.h"
|
|
||||||
#endif /* MBEDTLS_AES_ALT */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief This function initializes the specified AES context.
|
|
||||||
*
|
|
||||||
* It must be the first API called before using
|
|
||||||
* the context.
|
|
||||||
*
|
|
||||||
* \param ctx The AES context to initialize.
|
|
||||||
*/
|
|
||||||
void mbedtls_aes_init( mbedtls_aes_context *ctx );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief This function releases and clears the specified AES context.
|
|
||||||
*
|
|
||||||
* \param ctx The AES context to clear.
|
|
||||||
*/
|
|
||||||
void mbedtls_aes_free( mbedtls_aes_context *ctx );
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_CIPHER_MODE_XTS)
|
|
||||||
/**
|
|
||||||
* \brief This function initializes the specified AES XTS context.
|
|
||||||
*
|
|
||||||
* It must be the first API called before using
|
|
||||||
* the context.
|
|
||||||
*
|
|
||||||
* \param ctx The AES XTS context to initialize.
|
|
||||||
*/
|
|
||||||
void mbedtls_aes_xts_init( mbedtls_aes_xts_context *ctx );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief This function releases and clears the specified AES XTS context.
|
|
||||||
*
|
|
||||||
* \param ctx The AES XTS context to clear.
|
|
||||||
*/
|
|
||||||
void mbedtls_aes_xts_free( mbedtls_aes_xts_context *ctx );
|
|
||||||
#endif /* MBEDTLS_CIPHER_MODE_XTS */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief This function sets the encryption key.
|
|
||||||
*
|
|
||||||
* \param ctx The AES context to which the key should be bound.
|
|
||||||
* \param key The encryption key.
|
|
||||||
* \param keybits The size of data passed in bits. Valid options are:
|
|
||||||
* <ul><li>128 bits</li>
|
|
||||||
* <li>192 bits</li>
|
|
||||||
* <li>256 bits</li></ul>
|
|
||||||
*
|
|
||||||
* \return \c 0 on success.
|
|
||||||
* \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
|
|
||||||
*/
|
|
||||||
int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key,
|
|
||||||
unsigned int keybits );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief This function sets the decryption key.
|
|
||||||
*
|
|
||||||
* \param ctx The AES context to which the key should be bound.
|
|
||||||
* \param key The decryption key.
|
|
||||||
* \param keybits The size of data passed. Valid options are:
|
|
||||||
* <ul><li>128 bits</li>
|
|
||||||
* <li>192 bits</li>
|
|
||||||
* <li>256 bits</li></ul>
|
|
||||||
*
|
|
||||||
* \return \c 0 on success.
|
|
||||||
* \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
|
|
||||||
*/
|
|
||||||
int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key,
|
|
||||||
unsigned int keybits );
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_CIPHER_MODE_XTS)
|
|
||||||
/**
|
|
||||||
* \brief This function prepares an XTS context for encryption and
|
|
||||||
* sets the encryption key.
|
|
||||||
*
|
|
||||||
* \param ctx The AES XTS context to which the key should be bound.
|
|
||||||
* \param key The encryption key. This is comprised of the XTS key1
|
|
||||||
* concatenated with the XTS key2.
|
|
||||||
* \param keybits The size of \p key passed in bits. Valid options are:
|
|
||||||
* <ul><li>256 bits (each of key1 and key2 is a 128-bit key)</li>
|
|
||||||
* <li>512 bits (each of key1 and key2 is a 256-bit key)</li></ul>
|
|
||||||
*
|
|
||||||
* \return \c 0 on success.
|
|
||||||
* \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
|
|
||||||
*/
|
|
||||||
int mbedtls_aes_xts_setkey_enc( mbedtls_aes_xts_context *ctx,
|
|
||||||
const unsigned char *key,
|
|
||||||
unsigned int keybits );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief This function prepares an XTS context for decryption and
|
|
||||||
* sets the decryption key.
|
|
||||||
*
|
|
||||||
* \param ctx The AES XTS context to which the key should be bound.
|
|
||||||
* \param key The decryption key. This is comprised of the XTS key1
|
|
||||||
* concatenated with the XTS key2.
|
|
||||||
* \param keybits The size of \p key passed in bits. Valid options are:
|
|
||||||
* <ul><li>256 bits (each of key1 and key2 is a 128-bit key)</li>
|
|
||||||
* <li>512 bits (each of key1 and key2 is a 256-bit key)</li></ul>
|
|
||||||
*
|
|
||||||
* \return \c 0 on success.
|
|
||||||
* \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
|
|
||||||
*/
|
|
||||||
int mbedtls_aes_xts_setkey_dec( mbedtls_aes_xts_context *ctx,
|
|
||||||
const unsigned char *key,
|
|
||||||
unsigned int keybits );
|
|
||||||
#endif /* MBEDTLS_CIPHER_MODE_XTS */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief This function performs an AES single-block encryption or
|
|
||||||
* decryption operation.
|
|
||||||
*
|
|
||||||
* It performs the operation defined in the \p mode parameter
|
|
||||||
* (encrypt or decrypt), on the input data buffer defined in
|
|
||||||
* the \p input parameter.
|
|
||||||
*
|
|
||||||
* mbedtls_aes_init(), and either mbedtls_aes_setkey_enc() or
|
|
||||||
* mbedtls_aes_setkey_dec() must be called before the first
|
|
||||||
* call to this API with the same context.
|
|
||||||
*
|
|
||||||
* \param ctx The AES context to use for encryption or decryption.
|
|
||||||
* \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
|
|
||||||
* #MBEDTLS_AES_DECRYPT.
|
|
||||||
* \param input The 16-Byte buffer holding the input data.
|
|
||||||
* \param output The 16-Byte buffer holding the output data.
|
|
||||||
|
|
||||||
* \return \c 0 on success.
|
|
||||||
*/
|
|
||||||
int mbedtls_aes_crypt_ecb( mbedtls_aes_context *ctx,
|
|
||||||
int mode,
|
|
||||||
const unsigned char input[16],
|
|
||||||
unsigned char output[16] );
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
|
||||||
/**
|
|
||||||
* \brief This function performs an AES-CBC encryption or decryption operation
|
|
||||||
* on full blocks.
|
|
||||||
*
|
|
||||||
* It performs the operation defined in the \p mode
|
|
||||||
* parameter (encrypt/decrypt), on the input data buffer defined in
|
|
||||||
* the \p input parameter.
|
|
||||||
*
|
|
||||||
* It can be called as many times as needed, until all the input
|
|
||||||
* data is processed. mbedtls_aes_init(), and either
|
|
||||||
* mbedtls_aes_setkey_enc() or mbedtls_aes_setkey_dec() must be called
|
|
||||||
* before the first call to this API with the same context.
|
|
||||||
*
|
|
||||||
* \note This function operates on aligned blocks, that is, the input size
|
|
||||||
* must be a multiple of the AES block size of 16 Bytes.
|
|
||||||
*
|
|
||||||
* \note Upon exit, the content of the IV is updated so that you can
|
|
||||||
* call the same function again on the next
|
|
||||||
* block(s) of data and get the same result as if it was
|
|
||||||
* encrypted in one call. This allows a "streaming" usage.
|
|
||||||
* If you need to retain the contents of the IV, you should
|
|
||||||
* either save it manually or use the cipher module instead.
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* \param ctx The AES context to use for encryption or decryption.
|
|
||||||
* \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
|
|
||||||
* #MBEDTLS_AES_DECRYPT.
|
|
||||||
* \param length The length of the input data in Bytes. This must be a
|
|
||||||
* multiple of the block size (16 Bytes).
|
|
||||||
* \param iv Initialization vector (updated after use).
|
|
||||||
* \param input The buffer holding the input data.
|
|
||||||
* \param output The buffer holding the output data.
|
|
||||||
*
|
|
||||||
* \return \c 0 on success.
|
|
||||||
* \return #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH
|
|
||||||
* on failure.
|
|
||||||
*/
|
|
||||||
int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx,
|
|
||||||
int mode,
|
|
||||||
size_t length,
|
|
||||||
unsigned char iv[16],
|
|
||||||
const unsigned char *input,
|
|
||||||
unsigned char *output );
|
|
||||||
#endif /* MBEDTLS_CIPHER_MODE_CBC */
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_CIPHER_MODE_XTS)
|
|
||||||
/**
|
|
||||||
* \brief This function performs an AES-XTS encryption or decryption
|
|
||||||
* operation for an entire XTS data unit.
|
|
||||||
*
|
|
||||||
* AES-XTS encrypts or decrypts blocks based on their location as
|
|
||||||
* defined by a data unit number. The data unit number must be
|
|
||||||
* provided by \p data_unit.
|
|
||||||
*
|
|
||||||
* NIST SP 800-38E limits the maximum size of a data unit to 2^20
|
|
||||||
* AES blocks. If the data unit is larger than this, this function
|
|
||||||
* returns #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH.
|
|
||||||
*
|
|
||||||
* \param ctx The AES XTS context to use for AES XTS operations.
|
|
||||||
* \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
|
|
||||||
* #MBEDTLS_AES_DECRYPT.
|
|
||||||
* \param length The length of a data unit in bytes. This can be any
|
|
||||||
* length between 16 bytes and 2^24 bytes inclusive
|
|
||||||
* (between 1 and 2^20 block cipher blocks).
|
|
||||||
* \param data_unit The address of the data unit encoded as an array of 16
|
|
||||||
* bytes in little-endian format. For disk encryption, this
|
|
||||||
* is typically the index of the block device sector that
|
|
||||||
* contains the data.
|
|
||||||
* \param input The buffer holding the input data (which is an entire
|
|
||||||
* data unit). This function reads \p length bytes from \p
|
|
||||||
* input.
|
|
||||||
* \param output The buffer holding the output data (which is an entire
|
|
||||||
* data unit). This function writes \p length bytes to \p
|
|
||||||
* output.
|
|
||||||
*
|
|
||||||
* \return \c 0 on success.
|
|
||||||
* \return #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH if \p length is
|
|
||||||
* smaller than an AES block in size (16 bytes) or if \p
|
|
||||||
* length is larger than 2^20 blocks (16 MiB).
|
|
||||||
*/
|
|
||||||
int mbedtls_aes_crypt_xts( mbedtls_aes_xts_context *ctx,
|
|
||||||
int mode,
|
|
||||||
size_t length,
|
|
||||||
const unsigned char data_unit[16],
|
|
||||||
const unsigned char *input,
|
|
||||||
unsigned char *output );
|
|
||||||
#endif /* MBEDTLS_CIPHER_MODE_XTS */
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_CIPHER_MODE_CFB)
|
|
||||||
/**
|
|
||||||
* \brief This function performs an AES-CFB128 encryption or decryption
|
|
||||||
* operation.
|
|
||||||
*
|
|
||||||
* It performs the operation defined in the \p mode
|
|
||||||
* parameter (encrypt or decrypt), on the input data buffer
|
|
||||||
* defined in the \p input parameter.
|
|
||||||
*
|
|
||||||
* For CFB, you must set up the context with mbedtls_aes_setkey_enc(),
|
|
||||||
* regardless of whether you are performing an encryption or decryption
|
|
||||||
* operation, that is, regardless of the \p mode parameter. This is
|
|
||||||
* because CFB mode uses the same key schedule for encryption and
|
|
||||||
* decryption.
|
|
||||||
*
|
|
||||||
* \note Upon exit, the content of the IV is updated so that you can
|
|
||||||
* call the same function again on the next
|
|
||||||
* block(s) of data and get the same result as if it was
|
|
||||||
* encrypted in one call. This allows a "streaming" usage.
|
|
||||||
* If you need to retain the contents of the
|
|
||||||
* IV, you must either save it manually or use the cipher
|
|
||||||
* module instead.
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* \param ctx The AES context to use for encryption or decryption.
|
|
||||||
* \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
|
|
||||||
* #MBEDTLS_AES_DECRYPT.
|
|
||||||
* \param length The length of the input data.
|
|
||||||
* \param iv_off The offset in IV (updated after use).
|
|
||||||
* \param iv The initialization vector (updated after use).
|
|
||||||
* \param input The buffer holding the input data.
|
|
||||||
* \param output The buffer holding the output data.
|
|
||||||
*
|
|
||||||
* \return \c 0 on success.
|
|
||||||
*/
|
|
||||||
int mbedtls_aes_crypt_cfb128( mbedtls_aes_context *ctx,
|
|
||||||
int mode,
|
|
||||||
size_t length,
|
|
||||||
size_t *iv_off,
|
|
||||||
unsigned char iv[16],
|
|
||||||
const unsigned char *input,
|
|
||||||
unsigned char *output );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief This function performs an AES-CFB8 encryption or decryption
|
|
||||||
* operation.
|
|
||||||
*
|
|
||||||
* It performs the operation defined in the \p mode
|
|
||||||
* parameter (encrypt/decrypt), on the input data buffer defined
|
|
||||||
* in the \p input parameter.
|
|
||||||
*
|
|
||||||
* Due to the nature of CFB, you must use the same key schedule for
|
|
||||||
* both encryption and decryption operations. Therefore, you must
|
|
||||||
* use the context initialized with mbedtls_aes_setkey_enc() for
|
|
||||||
* both #MBEDTLS_AES_ENCRYPT and #MBEDTLS_AES_DECRYPT.
|
|
||||||
*
|
|
||||||
* \note Upon exit, the content of the IV is updated so that you can
|
|
||||||
* call the same function again on the next
|
|
||||||
* block(s) of data and get the same result as if it was
|
|
||||||
* encrypted in one call. This allows a "streaming" usage.
|
|
||||||
* If you need to retain the contents of the
|
|
||||||
* IV, you should either save it manually or use the cipher
|
|
||||||
* module instead.
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* \param ctx The AES context to use for encryption or decryption.
|
|
||||||
* \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
|
|
||||||
* #MBEDTLS_AES_DECRYPT
|
|
||||||
* \param length The length of the input data.
|
|
||||||
* \param iv The initialization vector (updated after use).
|
|
||||||
* \param input The buffer holding the input data.
|
|
||||||
* \param output The buffer holding the output data.
|
|
||||||
*
|
|
||||||
* \return \c 0 on success.
|
|
||||||
*/
|
|
||||||
int mbedtls_aes_crypt_cfb8( mbedtls_aes_context *ctx,
|
|
||||||
int mode,
|
|
||||||
size_t length,
|
|
||||||
unsigned char iv[16],
|
|
||||||
const unsigned char *input,
|
|
||||||
unsigned char *output );
|
|
||||||
#endif /*MBEDTLS_CIPHER_MODE_CFB */
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_CIPHER_MODE_OFB)
|
|
||||||
/**
|
|
||||||
* \brief This function performs an AES-OFB (Output Feedback Mode)
|
|
||||||
* encryption or decryption operation.
|
|
||||||
*
|
|
||||||
* For OFB, you must set up the context with
|
|
||||||
* mbedtls_aes_setkey_enc(), regardless of whether you are
|
|
||||||
* performing an encryption or decryption operation. This is
|
|
||||||
* because OFB mode uses the same key schedule for encryption and
|
|
||||||
* decryption.
|
|
||||||
*
|
|
||||||
* The OFB operation is identical for encryption or decryption,
|
|
||||||
* therefore no operation mode needs to be specified.
|
|
||||||
*
|
|
||||||
* \note Upon exit, the content of iv, the Initialisation Vector, is
|
|
||||||
* updated so that you can call the same function again on the next
|
|
||||||
* block(s) of data and get the same result as if it was encrypted
|
|
||||||
* in one call. This allows a "streaming" usage, by initialising
|
|
||||||
* iv_off to 0 before the first call, and preserving its value
|
|
||||||
* between calls.
|
|
||||||
*
|
|
||||||
* For non-streaming use, the iv should be initialised on each call
|
|
||||||
* to a unique value, and iv_off set to 0 on each call.
|
|
||||||
*
|
|
||||||
* If you need to retain the contents of the initialisation vector,
|
|
||||||
* you must either save it manually or use the cipher module
|
|
||||||
* instead.
|
|
||||||
*
|
|
||||||
* \warning For the OFB mode, the initialisation vector must be unique
|
|
||||||
* every encryption operation. Reuse of an initialisation vector
|
|
||||||
* will compromise security.
|
|
||||||
*
|
|
||||||
* \param ctx The AES context to use for encryption or decryption.
|
|
||||||
* \param length The length of the input data.
|
|
||||||
* \param iv_off The offset in IV (updated after use).
|
|
||||||
* \param iv The initialization vector (updated after use).
|
|
||||||
* \param input The buffer holding the input data.
|
|
||||||
* \param output The buffer holding the output data.
|
|
||||||
*
|
|
||||||
* \return \c 0 on success.
|
|
||||||
*/
|
|
||||||
int mbedtls_aes_crypt_ofb( mbedtls_aes_context *ctx,
|
|
||||||
size_t length,
|
|
||||||
size_t *iv_off,
|
|
||||||
unsigned char iv[16],
|
|
||||||
const unsigned char *input,
|
|
||||||
unsigned char *output );
|
|
||||||
|
|
||||||
#endif /* MBEDTLS_CIPHER_MODE_OFB */
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_CIPHER_MODE_CTR)
|
|
||||||
/**
|
|
||||||
* \brief This function performs an AES-CTR encryption or decryption
|
|
||||||
* operation.
|
|
||||||
*
|
|
||||||
* This function performs the operation defined in the \p mode
|
|
||||||
* parameter (encrypt/decrypt), on the input data buffer
|
|
||||||
* defined in the \p input parameter.
|
|
||||||
*
|
|
||||||
* Due to the nature of CTR, you must use the same key schedule
|
|
||||||
* for both encryption and decryption operations. Therefore, you
|
|
||||||
* must use the context initialized with mbedtls_aes_setkey_enc()
|
|
||||||
* for both #MBEDTLS_AES_ENCRYPT and #MBEDTLS_AES_DECRYPT.
|
|
||||||
*
|
|
||||||
* \warning You must never reuse a nonce value with the same key. Doing so
|
|
||||||
* would void the encryption for the two messages encrypted with
|
|
||||||
* the same nonce and key.
|
|
||||||
*
|
|
||||||
* There are two common strategies for managing nonces with CTR:
|
|
||||||
*
|
|
||||||
* 1. You can handle everything as a single message processed over
|
|
||||||
* successive calls to this function. In that case, you want to
|
|
||||||
* set \p nonce_counter and \p nc_off to 0 for the first call, and
|
|
||||||
* then preserve the values of \p nonce_counter, \p nc_off and \p
|
|
||||||
* stream_block across calls to this function as they will be
|
|
||||||
* updated by this function.
|
|
||||||
*
|
|
||||||
* With this strategy, you must not encrypt more than 2**128
|
|
||||||
* blocks of data with the same key.
|
|
||||||
*
|
|
||||||
* 2. You can encrypt separate messages by dividing the \p
|
|
||||||
* nonce_counter buffer in two areas: the first one used for a
|
|
||||||
* per-message nonce, handled by yourself, and the second one
|
|
||||||
* updated by this function internally.
|
|
||||||
*
|
|
||||||
* For example, you might reserve the first 12 bytes for the
|
|
||||||
* per-message nonce, and the last 4 bytes for internal use. In that
|
|
||||||
* case, before calling this function on a new message you need to
|
|
||||||
* set the first 12 bytes of \p nonce_counter to your chosen nonce
|
|
||||||
* value, the last 4 to 0, and \p nc_off to 0 (which will cause \p
|
|
||||||
* stream_block to be ignored). That way, you can encrypt at most
|
|
||||||
* 2**96 messages of up to 2**32 blocks each with the same key.
|
|
||||||
*
|
|
||||||
* The per-message nonce (or information sufficient to reconstruct
|
|
||||||
* it) needs to be communicated with the ciphertext and must be unique.
|
|
||||||
* The recommended way to ensure uniqueness is to use a message
|
|
||||||
* counter. An alternative is to generate random nonces, but this
|
|
||||||
* limits the number of messages that can be securely encrypted:
|
|
||||||
* for example, with 96-bit random nonces, you should not encrypt
|
|
||||||
* more than 2**32 messages with the same key.
|
|
||||||
*
|
|
||||||
* Note that for both stategies, sizes are measured in blocks and
|
|
||||||
* that an AES block is 16 bytes.
|
|
||||||
*
|
|
||||||
* \warning Upon return, \p stream_block contains sensitive data. Its
|
|
||||||
* content must not be written to insecure storage and should be
|
|
||||||
* securely discarded as soon as it's no longer needed.
|
|
||||||
*
|
|
||||||
* \param ctx The AES context to use for encryption or decryption.
|
|
||||||
* \param length The length of the input data.
|
|
||||||
* \param nc_off The offset in the current \p stream_block, for
|
|
||||||
* resuming within the current cipher stream. The
|
|
||||||
* offset pointer should be 0 at the start of a stream.
|
|
||||||
* \param nonce_counter The 128-bit nonce and counter.
|
|
||||||
* \param stream_block The saved stream block for resuming. This is
|
|
||||||
* overwritten by the function.
|
|
||||||
* \param input The buffer holding the input data.
|
|
||||||
* \param output The buffer holding the output data.
|
|
||||||
*
|
|
||||||
* \return \c 0 on success.
|
|
||||||
*/
|
|
||||||
int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx,
|
|
||||||
size_t length,
|
|
||||||
size_t *nc_off,
|
|
||||||
unsigned char nonce_counter[16],
|
|
||||||
unsigned char stream_block[16],
|
|
||||||
const unsigned char *input,
|
|
||||||
unsigned char *output );
|
|
||||||
#endif /* MBEDTLS_CIPHER_MODE_CTR */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Internal AES block encryption function. This is only
|
|
||||||
* exposed to allow overriding it using
|
|
||||||
* \c MBEDTLS_AES_ENCRYPT_ALT.
|
|
||||||
*
|
|
||||||
* \param ctx The AES context to use for encryption.
|
|
||||||
* \param input The plaintext block.
|
|
||||||
* \param output The output (ciphertext) block.
|
|
||||||
*
|
|
||||||
* \return \c 0 on success.
|
|
||||||
*/
|
|
||||||
int mbedtls_internal_aes_encrypt( mbedtls_aes_context *ctx,
|
|
||||||
const unsigned char input[16],
|
|
||||||
unsigned char output[16] );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Internal AES block decryption function. This is only
|
|
||||||
* exposed to allow overriding it using see
|
|
||||||
* \c MBEDTLS_AES_DECRYPT_ALT.
|
|
||||||
*
|
|
||||||
* \param ctx The AES context to use for decryption.
|
|
||||||
* \param input The ciphertext block.
|
|
||||||
* \param output The output (plaintext) block.
|
|
||||||
*
|
|
||||||
* \return \c 0 on success.
|
|
||||||
*/
|
|
||||||
int mbedtls_internal_aes_decrypt( mbedtls_aes_context *ctx,
|
|
||||||
const unsigned char input[16],
|
|
||||||
unsigned char output[16] );
|
|
||||||
|
|
||||||
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
|
||||||
#if defined(MBEDTLS_DEPRECATED_WARNING)
|
|
||||||
#define MBEDTLS_DEPRECATED __attribute__((deprecated))
|
|
||||||
#else
|
|
||||||
#define MBEDTLS_DEPRECATED
|
|
||||||
#endif
|
|
||||||
/**
|
|
||||||
* \brief Deprecated internal AES block encryption function
|
|
||||||
* without return value.
|
|
||||||
*
|
|
||||||
* \deprecated Superseded by mbedtls_aes_encrypt_ext() in 2.5.0.
|
|
||||||
*
|
|
||||||
* \param ctx The AES context to use for encryption.
|
|
||||||
* \param input Plaintext block.
|
|
||||||
* \param output Output (ciphertext) block.
|
|
||||||
*/
|
|
||||||
MBEDTLS_DEPRECATED void mbedtls_aes_encrypt( mbedtls_aes_context *ctx,
|
|
||||||
const unsigned char input[16],
|
|
||||||
unsigned char output[16] );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Deprecated internal AES block decryption function
|
|
||||||
* without return value.
|
|
||||||
*
|
|
||||||
* \deprecated Superseded by mbedtls_aes_decrypt_ext() in 2.5.0.
|
|
||||||
*
|
|
||||||
* \param ctx The AES context to use for decryption.
|
|
||||||
* \param input Ciphertext block.
|
|
||||||
* \param output Output (plaintext) block.
|
|
||||||
*/
|
|
||||||
MBEDTLS_DEPRECATED void mbedtls_aes_decrypt( mbedtls_aes_context *ctx,
|
|
||||||
const unsigned char input[16],
|
|
||||||
unsigned char output[16] );
|
|
||||||
|
|
||||||
#undef MBEDTLS_DEPRECATED
|
|
||||||
#endif /* !MBEDTLS_DEPRECATED_REMOVED */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Checkup routine.
|
|
||||||
*
|
|
||||||
* \return \c 0 on success.
|
|
||||||
* \return \c 1 on failure.
|
|
||||||
*/
|
|
||||||
int mbedtls_aes_self_test( int verbose );
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* aes.h */
|
|
|
@ -1,685 +0,0 @@
|
||||||
/**
|
|
||||||
* \file check_config.h
|
|
||||||
*
|
|
||||||
* \brief Consistency checks for configuration options
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* Copyright (C) 2006-2018, ARM Limited, All Rights Reserved
|
|
||||||
* SPDX-License-Identifier: GPL-2.0
|
|
||||||
*
|
|
||||||
* This program 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 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*
|
|
||||||
* This file is part of mbed TLS (https://tls.mbed.org)
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* It is recommended to include this file from your config.h
|
|
||||||
* in order to catch dependency issues early.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef MBEDTLS_CHECK_CONFIG_H
|
|
||||||
#define MBEDTLS_CHECK_CONFIG_H
|
|
||||||
|
|
||||||
/*
|
|
||||||
* We assume CHAR_BIT is 8 in many places. In practice, this is true on our
|
|
||||||
* target platforms, so not an issue, but let's just be extra sure.
|
|
||||||
*/
|
|
||||||
#include <limits.h>
|
|
||||||
#if CHAR_BIT != 8
|
|
||||||
#error "mbed TLS requires a platform with 8-bit chars"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(_WIN32)
|
|
||||||
#if !defined(MBEDTLS_PLATFORM_C)
|
|
||||||
#error "MBEDTLS_PLATFORM_C is required on Windows"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Fix the config here. Not convenient to put an #ifdef _WIN32 in config.h as
|
|
||||||
* it would confuse config.pl. */
|
|
||||||
#if !defined(MBEDTLS_PLATFORM_SNPRINTF_ALT) && \
|
|
||||||
!defined(MBEDTLS_PLATFORM_SNPRINTF_MACRO)
|
|
||||||
#define MBEDTLS_PLATFORM_SNPRINTF_ALT
|
|
||||||
#endif
|
|
||||||
#endif /* _WIN32 */
|
|
||||||
|
|
||||||
#if defined(TARGET_LIKE_MBED) && \
|
|
||||||
( defined(MBEDTLS_NET_C) || defined(MBEDTLS_TIMING_C) )
|
|
||||||
#error "The NET and TIMING modules are not available for mbed OS - please use the network and timing functions provided by mbed OS"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_DEPRECATED_WARNING) && \
|
|
||||||
!defined(__GNUC__) && !defined(__clang__)
|
|
||||||
#error "MBEDTLS_DEPRECATED_WARNING only works with GCC and Clang"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_HAVE_TIME_DATE) && !defined(MBEDTLS_HAVE_TIME)
|
|
||||||
#error "MBEDTLS_HAVE_TIME_DATE without MBEDTLS_HAVE_TIME does not make sense"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_AESNI_C) && !defined(MBEDTLS_HAVE_ASM)
|
|
||||||
#error "MBEDTLS_AESNI_C defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_CTR_DRBG_C) && !defined(MBEDTLS_AES_C)
|
|
||||||
#error "MBEDTLS_CTR_DRBG_C defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_DHM_C) && !defined(MBEDTLS_BIGNUM_C)
|
|
||||||
#error "MBEDTLS_DHM_C defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_SSL_TRUNCATED_HMAC_COMPAT) && !defined(MBEDTLS_SSL_TRUNCATED_HMAC)
|
|
||||||
#error "MBEDTLS_SSL_TRUNCATED_HMAC_COMPAT defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_CMAC_C) && \
|
|
||||||
!defined(MBEDTLS_AES_C) && !defined(MBEDTLS_DES_C)
|
|
||||||
#error "MBEDTLS_CMAC_C defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_NIST_KW_C) && \
|
|
||||||
( !defined(MBEDTLS_AES_C) || !defined(MBEDTLS_CIPHER_C) )
|
|
||||||
#error "MBEDTLS_NIST_KW_C defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_ECDH_C) && !defined(MBEDTLS_ECP_C)
|
|
||||||
#error "MBEDTLS_ECDH_C defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_ECDSA_C) && \
|
|
||||||
( !defined(MBEDTLS_ECP_C) || \
|
|
||||||
!defined(MBEDTLS_ASN1_PARSE_C) || \
|
|
||||||
!defined(MBEDTLS_ASN1_WRITE_C) )
|
|
||||||
#error "MBEDTLS_ECDSA_C defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_ECJPAKE_C) && \
|
|
||||||
( !defined(MBEDTLS_ECP_C) || !defined(MBEDTLS_MD_C) )
|
|
||||||
#error "MBEDTLS_ECJPAKE_C defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_ECDSA_DETERMINISTIC) && !defined(MBEDTLS_HMAC_DRBG_C)
|
|
||||||
#error "MBEDTLS_ECDSA_DETERMINISTIC defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_ECP_C) && ( !defined(MBEDTLS_BIGNUM_C) || ( \
|
|
||||||
!defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED) && \
|
|
||||||
!defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED) && \
|
|
||||||
!defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) && \
|
|
||||||
!defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED) && \
|
|
||||||
!defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED) && \
|
|
||||||
!defined(MBEDTLS_ECP_DP_BP256R1_ENABLED) && \
|
|
||||||
!defined(MBEDTLS_ECP_DP_BP384R1_ENABLED) && \
|
|
||||||
!defined(MBEDTLS_ECP_DP_BP512R1_ENABLED) && \
|
|
||||||
!defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED) && \
|
|
||||||
!defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED) && \
|
|
||||||
!defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED) ) )
|
|
||||||
#error "MBEDTLS_ECP_C defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_ENTROPY_C) && (!defined(MBEDTLS_SHA512_C) && \
|
|
||||||
!defined(MBEDTLS_SHA256_C))
|
|
||||||
#error "MBEDTLS_ENTROPY_C defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
#if defined(MBEDTLS_ENTROPY_C) && defined(MBEDTLS_SHA512_C) && \
|
|
||||||
defined(MBEDTLS_CTR_DRBG_ENTROPY_LEN) && (MBEDTLS_CTR_DRBG_ENTROPY_LEN > 64)
|
|
||||||
#error "MBEDTLS_CTR_DRBG_ENTROPY_LEN value too high"
|
|
||||||
#endif
|
|
||||||
#if defined(MBEDTLS_ENTROPY_C) && \
|
|
||||||
( !defined(MBEDTLS_SHA512_C) || defined(MBEDTLS_ENTROPY_FORCE_SHA256) ) \
|
|
||||||
&& defined(MBEDTLS_CTR_DRBG_ENTROPY_LEN) && (MBEDTLS_CTR_DRBG_ENTROPY_LEN > 32)
|
|
||||||
#error "MBEDTLS_CTR_DRBG_ENTROPY_LEN value too high"
|
|
||||||
#endif
|
|
||||||
#if defined(MBEDTLS_ENTROPY_C) && \
|
|
||||||
defined(MBEDTLS_ENTROPY_FORCE_SHA256) && !defined(MBEDTLS_SHA256_C)
|
|
||||||
#error "MBEDTLS_ENTROPY_FORCE_SHA256 defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_TEST_NULL_ENTROPY) && \
|
|
||||||
( !defined(MBEDTLS_ENTROPY_C) || !defined(MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES) )
|
|
||||||
#error "MBEDTLS_TEST_NULL_ENTROPY defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
#if defined(MBEDTLS_TEST_NULL_ENTROPY) && \
|
|
||||||
( defined(MBEDTLS_ENTROPY_NV_SEED) || defined(MBEDTLS_ENTROPY_HARDWARE_ALT) || \
|
|
||||||
defined(MBEDTLS_HAVEGE_C) )
|
|
||||||
#error "MBEDTLS_TEST_NULL_ENTROPY defined, but entropy sources too"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_GCM_C) && ( \
|
|
||||||
!defined(MBEDTLS_AES_C) && !defined(MBEDTLS_CAMELLIA_C) )
|
|
||||||
#error "MBEDTLS_GCM_C defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_ECP_RANDOMIZE_JAC_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
|
|
||||||
#error "MBEDTLS_ECP_RANDOMIZE_JAC_ALT defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_ECP_ADD_MIXED_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
|
|
||||||
#error "MBEDTLS_ECP_ADD_MIXED_ALT defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_ECP_DOUBLE_JAC_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
|
|
||||||
#error "MBEDTLS_ECP_DOUBLE_JAC_ALT defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_ECP_NORMALIZE_JAC_MANY_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
|
|
||||||
#error "MBEDTLS_ECP_NORMALIZE_JAC_MANY_ALT defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_ECP_NORMALIZE_JAC_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
|
|
||||||
#error "MBEDTLS_ECP_NORMALIZE_JAC_ALT defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_ECP_DOUBLE_ADD_MXZ_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
|
|
||||||
#error "MBEDTLS_ECP_DOUBLE_ADD_MXZ_ALT defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_ECP_RANDOMIZE_MXZ_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
|
|
||||||
#error "MBEDTLS_ECP_RANDOMIZE_MXZ_ALT defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_ECP_NORMALIZE_MXZ_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
|
|
||||||
#error "MBEDTLS_ECP_NORMALIZE_MXZ_ALT defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_HAVEGE_C) && !defined(MBEDTLS_TIMING_C)
|
|
||||||
#error "MBEDTLS_HAVEGE_C defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_HKDF_C) && !defined(MBEDTLS_MD_C)
|
|
||||||
#error "MBEDTLS_HKDF_C defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_HMAC_DRBG_C) && !defined(MBEDTLS_MD_C)
|
|
||||||
#error "MBEDTLS_HMAC_DRBG_C defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED) && \
|
|
||||||
( !defined(MBEDTLS_ECDH_C) || !defined(MBEDTLS_X509_CRT_PARSE_C) )
|
|
||||||
#error "MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) && \
|
|
||||||
( !defined(MBEDTLS_ECDH_C) || !defined(MBEDTLS_X509_CRT_PARSE_C) )
|
|
||||||
#error "MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED) && !defined(MBEDTLS_DHM_C)
|
|
||||||
#error "MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED) && \
|
|
||||||
!defined(MBEDTLS_ECDH_C)
|
|
||||||
#error "MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) && \
|
|
||||||
( !defined(MBEDTLS_DHM_C) || !defined(MBEDTLS_RSA_C) || \
|
|
||||||
!defined(MBEDTLS_X509_CRT_PARSE_C) || !defined(MBEDTLS_PKCS1_V15) )
|
|
||||||
#error "MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) && \
|
|
||||||
( !defined(MBEDTLS_ECDH_C) || !defined(MBEDTLS_RSA_C) || \
|
|
||||||
!defined(MBEDTLS_X509_CRT_PARSE_C) || !defined(MBEDTLS_PKCS1_V15) )
|
|
||||||
#error "MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) && \
|
|
||||||
( !defined(MBEDTLS_ECDH_C) || !defined(MBEDTLS_ECDSA_C) || \
|
|
||||||
!defined(MBEDTLS_X509_CRT_PARSE_C) )
|
|
||||||
#error "MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED) && \
|
|
||||||
( !defined(MBEDTLS_RSA_C) || !defined(MBEDTLS_X509_CRT_PARSE_C) || \
|
|
||||||
!defined(MBEDTLS_PKCS1_V15) )
|
|
||||||
#error "MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) && \
|
|
||||||
( !defined(MBEDTLS_RSA_C) || !defined(MBEDTLS_X509_CRT_PARSE_C) || \
|
|
||||||
!defined(MBEDTLS_PKCS1_V15) )
|
|
||||||
#error "MBEDTLS_KEY_EXCHANGE_RSA_ENABLED defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED) && \
|
|
||||||
( !defined(MBEDTLS_ECJPAKE_C) || !defined(MBEDTLS_SHA256_C) || \
|
|
||||||
!defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) )
|
|
||||||
#error "MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && \
|
|
||||||
( !defined(MBEDTLS_PLATFORM_C) || !defined(MBEDTLS_PLATFORM_MEMORY) )
|
|
||||||
#error "MBEDTLS_MEMORY_BUFFER_ALLOC_C defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PADLOCK_C) && !defined(MBEDTLS_HAVE_ASM)
|
|
||||||
#error "MBEDTLS_PADLOCK_C defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PEM_PARSE_C) && !defined(MBEDTLS_BASE64_C)
|
|
||||||
#error "MBEDTLS_PEM_PARSE_C defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PEM_WRITE_C) && !defined(MBEDTLS_BASE64_C)
|
|
||||||
#error "MBEDTLS_PEM_WRITE_C defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PK_C) && \
|
|
||||||
( !defined(MBEDTLS_RSA_C) && !defined(MBEDTLS_ECP_C) )
|
|
||||||
#error "MBEDTLS_PK_C defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PK_PARSE_C) && !defined(MBEDTLS_PK_C)
|
|
||||||
#error "MBEDTLS_PK_PARSE_C defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PK_WRITE_C) && !defined(MBEDTLS_PK_C)
|
|
||||||
#error "MBEDTLS_PK_WRITE_C defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PKCS11_C) && !defined(MBEDTLS_PK_C)
|
|
||||||
#error "MBEDTLS_PKCS11_C defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PLATFORM_EXIT_ALT) && !defined(MBEDTLS_PLATFORM_C)
|
|
||||||
#error "MBEDTLS_PLATFORM_EXIT_ALT defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PLATFORM_EXIT_MACRO) && !defined(MBEDTLS_PLATFORM_C)
|
|
||||||
#error "MBEDTLS_PLATFORM_EXIT_MACRO defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PLATFORM_EXIT_MACRO) &&\
|
|
||||||
( defined(MBEDTLS_PLATFORM_STD_EXIT) ||\
|
|
||||||
defined(MBEDTLS_PLATFORM_EXIT_ALT) )
|
|
||||||
#error "MBEDTLS_PLATFORM_EXIT_MACRO and MBEDTLS_PLATFORM_STD_EXIT/MBEDTLS_PLATFORM_EXIT_ALT cannot be defined simultaneously"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PLATFORM_TIME_ALT) &&\
|
|
||||||
( !defined(MBEDTLS_PLATFORM_C) ||\
|
|
||||||
!defined(MBEDTLS_HAVE_TIME) )
|
|
||||||
#error "MBEDTLS_PLATFORM_TIME_ALT defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PLATFORM_TIME_MACRO) &&\
|
|
||||||
( !defined(MBEDTLS_PLATFORM_C) ||\
|
|
||||||
!defined(MBEDTLS_HAVE_TIME) )
|
|
||||||
#error "MBEDTLS_PLATFORM_TIME_MACRO defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PLATFORM_TIME_TYPE_MACRO) &&\
|
|
||||||
( !defined(MBEDTLS_PLATFORM_C) ||\
|
|
||||||
!defined(MBEDTLS_HAVE_TIME) )
|
|
||||||
#error "MBEDTLS_PLATFORM_TIME_TYPE_MACRO defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PLATFORM_TIME_MACRO) &&\
|
|
||||||
( defined(MBEDTLS_PLATFORM_STD_TIME) ||\
|
|
||||||
defined(MBEDTLS_PLATFORM_TIME_ALT) )
|
|
||||||
#error "MBEDTLS_PLATFORM_TIME_MACRO and MBEDTLS_PLATFORM_STD_TIME/MBEDTLS_PLATFORM_TIME_ALT cannot be defined simultaneously"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PLATFORM_TIME_TYPE_MACRO) &&\
|
|
||||||
( defined(MBEDTLS_PLATFORM_STD_TIME) ||\
|
|
||||||
defined(MBEDTLS_PLATFORM_TIME_ALT) )
|
|
||||||
#error "MBEDTLS_PLATFORM_TIME_TYPE_MACRO and MBEDTLS_PLATFORM_STD_TIME/MBEDTLS_PLATFORM_TIME_ALT cannot be defined simultaneously"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PLATFORM_FPRINTF_ALT) && !defined(MBEDTLS_PLATFORM_C)
|
|
||||||
#error "MBEDTLS_PLATFORM_FPRINTF_ALT defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PLATFORM_FPRINTF_MACRO) && !defined(MBEDTLS_PLATFORM_C)
|
|
||||||
#error "MBEDTLS_PLATFORM_FPRINTF_MACRO defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PLATFORM_FPRINTF_MACRO) &&\
|
|
||||||
( defined(MBEDTLS_PLATFORM_STD_FPRINTF) ||\
|
|
||||||
defined(MBEDTLS_PLATFORM_FPRINTF_ALT) )
|
|
||||||
#error "MBEDTLS_PLATFORM_FPRINTF_MACRO and MBEDTLS_PLATFORM_STD_FPRINTF/MBEDTLS_PLATFORM_FPRINTF_ALT cannot be defined simultaneously"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PLATFORM_FREE_MACRO) &&\
|
|
||||||
( !defined(MBEDTLS_PLATFORM_C) || !defined(MBEDTLS_PLATFORM_MEMORY) )
|
|
||||||
#error "MBEDTLS_PLATFORM_FREE_MACRO defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PLATFORM_FREE_MACRO) &&\
|
|
||||||
defined(MBEDTLS_PLATFORM_STD_FREE)
|
|
||||||
#error "MBEDTLS_PLATFORM_FREE_MACRO and MBEDTLS_PLATFORM_STD_FREE cannot be defined simultaneously"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PLATFORM_FREE_MACRO) && !defined(MBEDTLS_PLATFORM_CALLOC_MACRO)
|
|
||||||
#error "MBEDTLS_PLATFORM_CALLOC_MACRO must be defined if MBEDTLS_PLATFORM_FREE_MACRO is"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PLATFORM_CALLOC_MACRO) &&\
|
|
||||||
( !defined(MBEDTLS_PLATFORM_C) || !defined(MBEDTLS_PLATFORM_MEMORY) )
|
|
||||||
#error "MBEDTLS_PLATFORM_CALLOC_MACRO defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PLATFORM_CALLOC_MACRO) &&\
|
|
||||||
defined(MBEDTLS_PLATFORM_STD_CALLOC)
|
|
||||||
#error "MBEDTLS_PLATFORM_CALLOC_MACRO and MBEDTLS_PLATFORM_STD_CALLOC cannot be defined simultaneously"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PLATFORM_CALLOC_MACRO) && !defined(MBEDTLS_PLATFORM_FREE_MACRO)
|
|
||||||
#error "MBEDTLS_PLATFORM_FREE_MACRO must be defined if MBEDTLS_PLATFORM_CALLOC_MACRO is"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PLATFORM_MEMORY) && !defined(MBEDTLS_PLATFORM_C)
|
|
||||||
#error "MBEDTLS_PLATFORM_MEMORY defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PLATFORM_PRINTF_ALT) && !defined(MBEDTLS_PLATFORM_C)
|
|
||||||
#error "MBEDTLS_PLATFORM_PRINTF_ALT defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PLATFORM_PRINTF_MACRO) && !defined(MBEDTLS_PLATFORM_C)
|
|
||||||
#error "MBEDTLS_PLATFORM_PRINTF_MACRO defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PLATFORM_PRINTF_MACRO) &&\
|
|
||||||
( defined(MBEDTLS_PLATFORM_STD_PRINTF) ||\
|
|
||||||
defined(MBEDTLS_PLATFORM_PRINTF_ALT) )
|
|
||||||
#error "MBEDTLS_PLATFORM_PRINTF_MACRO and MBEDTLS_PLATFORM_STD_PRINTF/MBEDTLS_PLATFORM_PRINTF_ALT cannot be defined simultaneously"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PLATFORM_SNPRINTF_ALT) && !defined(MBEDTLS_PLATFORM_C)
|
|
||||||
#error "MBEDTLS_PLATFORM_SNPRINTF_ALT defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PLATFORM_SNPRINTF_MACRO) && !defined(MBEDTLS_PLATFORM_C)
|
|
||||||
#error "MBEDTLS_PLATFORM_SNPRINTF_MACRO defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PLATFORM_SNPRINTF_MACRO) &&\
|
|
||||||
( defined(MBEDTLS_PLATFORM_STD_SNPRINTF) ||\
|
|
||||||
defined(MBEDTLS_PLATFORM_SNPRINTF_ALT) )
|
|
||||||
#error "MBEDTLS_PLATFORM_SNPRINTF_MACRO and MBEDTLS_PLATFORM_STD_SNPRINTF/MBEDTLS_PLATFORM_SNPRINTF_ALT cannot be defined simultaneously"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PLATFORM_STD_MEM_HDR) &&\
|
|
||||||
!defined(MBEDTLS_PLATFORM_NO_STD_FUNCTIONS)
|
|
||||||
#error "MBEDTLS_PLATFORM_STD_MEM_HDR defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PLATFORM_STD_CALLOC) && !defined(MBEDTLS_PLATFORM_MEMORY)
|
|
||||||
#error "MBEDTLS_PLATFORM_STD_CALLOC defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PLATFORM_STD_CALLOC) && !defined(MBEDTLS_PLATFORM_MEMORY)
|
|
||||||
#error "MBEDTLS_PLATFORM_STD_CALLOC defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PLATFORM_STD_FREE) && !defined(MBEDTLS_PLATFORM_MEMORY)
|
|
||||||
#error "MBEDTLS_PLATFORM_STD_FREE defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PLATFORM_STD_EXIT) &&\
|
|
||||||
!defined(MBEDTLS_PLATFORM_EXIT_ALT)
|
|
||||||
#error "MBEDTLS_PLATFORM_STD_EXIT defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PLATFORM_STD_TIME) &&\
|
|
||||||
( !defined(MBEDTLS_PLATFORM_TIME_ALT) ||\
|
|
||||||
!defined(MBEDTLS_HAVE_TIME) )
|
|
||||||
#error "MBEDTLS_PLATFORM_STD_TIME defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PLATFORM_STD_FPRINTF) &&\
|
|
||||||
!defined(MBEDTLS_PLATFORM_FPRINTF_ALT)
|
|
||||||
#error "MBEDTLS_PLATFORM_STD_FPRINTF defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PLATFORM_STD_PRINTF) &&\
|
|
||||||
!defined(MBEDTLS_PLATFORM_PRINTF_ALT)
|
|
||||||
#error "MBEDTLS_PLATFORM_STD_PRINTF defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PLATFORM_STD_SNPRINTF) &&\
|
|
||||||
!defined(MBEDTLS_PLATFORM_SNPRINTF_ALT)
|
|
||||||
#error "MBEDTLS_PLATFORM_STD_SNPRINTF defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_ENTROPY_NV_SEED) &&\
|
|
||||||
( !defined(MBEDTLS_PLATFORM_C) || !defined(MBEDTLS_ENTROPY_C) )
|
|
||||||
#error "MBEDTLS_ENTROPY_NV_SEED defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PLATFORM_NV_SEED_ALT) &&\
|
|
||||||
!defined(MBEDTLS_ENTROPY_NV_SEED)
|
|
||||||
#error "MBEDTLS_PLATFORM_NV_SEED_ALT defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PLATFORM_STD_NV_SEED_READ) &&\
|
|
||||||
!defined(MBEDTLS_PLATFORM_NV_SEED_ALT)
|
|
||||||
#error "MBEDTLS_PLATFORM_STD_NV_SEED_READ defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PLATFORM_STD_NV_SEED_WRITE) &&\
|
|
||||||
!defined(MBEDTLS_PLATFORM_NV_SEED_ALT)
|
|
||||||
#error "MBEDTLS_PLATFORM_STD_NV_SEED_WRITE defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PLATFORM_NV_SEED_READ_MACRO) &&\
|
|
||||||
( defined(MBEDTLS_PLATFORM_STD_NV_SEED_READ) ||\
|
|
||||||
defined(MBEDTLS_PLATFORM_NV_SEED_ALT) )
|
|
||||||
#error "MBEDTLS_PLATFORM_NV_SEED_READ_MACRO and MBEDTLS_PLATFORM_STD_NV_SEED_READ cannot be defined simultaneously"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO) &&\
|
|
||||||
( defined(MBEDTLS_PLATFORM_STD_NV_SEED_WRITE) ||\
|
|
||||||
defined(MBEDTLS_PLATFORM_NV_SEED_ALT) )
|
|
||||||
#error "MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO and MBEDTLS_PLATFORM_STD_NV_SEED_WRITE cannot be defined simultaneously"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_RSA_C) && ( !defined(MBEDTLS_BIGNUM_C) || \
|
|
||||||
!defined(MBEDTLS_OID_C) )
|
|
||||||
#error "MBEDTLS_RSA_C defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_RSA_C) && ( !defined(MBEDTLS_PKCS1_V21) && \
|
|
||||||
!defined(MBEDTLS_PKCS1_V15) )
|
|
||||||
#error "MBEDTLS_RSA_C defined, but none of the PKCS1 versions enabled"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_X509_RSASSA_PSS_SUPPORT) && \
|
|
||||||
( !defined(MBEDTLS_RSA_C) || !defined(MBEDTLS_PKCS1_V21) )
|
|
||||||
#error "MBEDTLS_X509_RSASSA_PSS_SUPPORT defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_SSL_PROTO_SSL3) && ( !defined(MBEDTLS_MD5_C) || \
|
|
||||||
!defined(MBEDTLS_SHA1_C) )
|
|
||||||
#error "MBEDTLS_SSL_PROTO_SSL3 defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_SSL_PROTO_TLS1) && ( !defined(MBEDTLS_MD5_C) || \
|
|
||||||
!defined(MBEDTLS_SHA1_C) )
|
|
||||||
#error "MBEDTLS_SSL_PROTO_TLS1 defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_SSL_PROTO_TLS1_1) && ( !defined(MBEDTLS_MD5_C) || \
|
|
||||||
!defined(MBEDTLS_SHA1_C) )
|
|
||||||
#error "MBEDTLS_SSL_PROTO_TLS1_1 defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_SSL_PROTO_TLS1_2) && ( !defined(MBEDTLS_SHA1_C) && \
|
|
||||||
!defined(MBEDTLS_SHA256_C) && !defined(MBEDTLS_SHA512_C) )
|
|
||||||
#error "MBEDTLS_SSL_PROTO_TLS1_2 defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_SSL_PROTO_DTLS) && \
|
|
||||||
!defined(MBEDTLS_SSL_PROTO_TLS1_1) && \
|
|
||||||
!defined(MBEDTLS_SSL_PROTO_TLS1_2)
|
|
||||||
#error "MBEDTLS_SSL_PROTO_DTLS defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_SSL_CLI_C) && !defined(MBEDTLS_SSL_TLS_C)
|
|
||||||
#error "MBEDTLS_SSL_CLI_C defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_SSL_TLS_C) && ( !defined(MBEDTLS_CIPHER_C) || \
|
|
||||||
!defined(MBEDTLS_MD_C) )
|
|
||||||
#error "MBEDTLS_SSL_TLS_C defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_SSL_SRV_C) && !defined(MBEDTLS_SSL_TLS_C)
|
|
||||||
#error "MBEDTLS_SSL_SRV_C defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_SSL_TLS_C) && (!defined(MBEDTLS_SSL_PROTO_SSL3) && \
|
|
||||||
!defined(MBEDTLS_SSL_PROTO_TLS1) && !defined(MBEDTLS_SSL_PROTO_TLS1_1) && \
|
|
||||||
!defined(MBEDTLS_SSL_PROTO_TLS1_2))
|
|
||||||
#error "MBEDTLS_SSL_TLS_C defined, but no protocols are active"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_SSL_TLS_C) && (defined(MBEDTLS_SSL_PROTO_SSL3) && \
|
|
||||||
defined(MBEDTLS_SSL_PROTO_TLS1_1) && !defined(MBEDTLS_SSL_PROTO_TLS1))
|
|
||||||
#error "Illegal protocol selection"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_SSL_TLS_C) && (defined(MBEDTLS_SSL_PROTO_TLS1) && \
|
|
||||||
defined(MBEDTLS_SSL_PROTO_TLS1_2) && !defined(MBEDTLS_SSL_PROTO_TLS1_1))
|
|
||||||
#error "Illegal protocol selection"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_SSL_TLS_C) && (defined(MBEDTLS_SSL_PROTO_SSL3) && \
|
|
||||||
defined(MBEDTLS_SSL_PROTO_TLS1_2) && (!defined(MBEDTLS_SSL_PROTO_TLS1) || \
|
|
||||||
!defined(MBEDTLS_SSL_PROTO_TLS1_1)))
|
|
||||||
#error "Illegal protocol selection"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && !defined(MBEDTLS_SSL_PROTO_DTLS)
|
|
||||||
#error "MBEDTLS_SSL_DTLS_HELLO_VERIFY defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_SSL_DTLS_CLIENT_PORT_REUSE) && \
|
|
||||||
!defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY)
|
|
||||||
#error "MBEDTLS_SSL_DTLS_CLIENT_PORT_REUSE defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY) && \
|
|
||||||
( !defined(MBEDTLS_SSL_TLS_C) || !defined(MBEDTLS_SSL_PROTO_DTLS) )
|
|
||||||
#error "MBEDTLS_SSL_DTLS_ANTI_REPLAY defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_SSL_DTLS_BADMAC_LIMIT) && \
|
|
||||||
( !defined(MBEDTLS_SSL_TLS_C) || !defined(MBEDTLS_SSL_PROTO_DTLS) )
|
|
||||||
#error "MBEDTLS_SSL_DTLS_BADMAC_LIMIT defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC) && \
|
|
||||||
!defined(MBEDTLS_SSL_PROTO_TLS1) && \
|
|
||||||
!defined(MBEDTLS_SSL_PROTO_TLS1_1) && \
|
|
||||||
!defined(MBEDTLS_SSL_PROTO_TLS1_2)
|
|
||||||
#error "MBEDTLS_SSL_ENCRYPT_THEN_MAC defined, but not all prerequsites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET) && \
|
|
||||||
!defined(MBEDTLS_SSL_PROTO_TLS1) && \
|
|
||||||
!defined(MBEDTLS_SSL_PROTO_TLS1_1) && \
|
|
||||||
!defined(MBEDTLS_SSL_PROTO_TLS1_2)
|
|
||||||
#error "MBEDTLS_SSL_EXTENDED_MASTER_SECRET defined, but not all prerequsites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_SSL_TICKET_C) && !defined(MBEDTLS_CIPHER_C)
|
|
||||||
#error "MBEDTLS_SSL_TICKET_C defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_SSL_CBC_RECORD_SPLITTING) && \
|
|
||||||
!defined(MBEDTLS_SSL_PROTO_SSL3) && !defined(MBEDTLS_SSL_PROTO_TLS1)
|
|
||||||
#error "MBEDTLS_SSL_CBC_RECORD_SPLITTING defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION) && \
|
|
||||||
!defined(MBEDTLS_X509_CRT_PARSE_C)
|
|
||||||
#error "MBEDTLS_SSL_SERVER_NAME_INDICATION defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_THREADING_PTHREAD)
|
|
||||||
#if !defined(MBEDTLS_THREADING_C) || defined(MBEDTLS_THREADING_IMPL)
|
|
||||||
#error "MBEDTLS_THREADING_PTHREAD defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
#define MBEDTLS_THREADING_IMPL
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_THREADING_ALT)
|
|
||||||
#if !defined(MBEDTLS_THREADING_C) || defined(MBEDTLS_THREADING_IMPL)
|
|
||||||
#error "MBEDTLS_THREADING_ALT defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
#define MBEDTLS_THREADING_IMPL
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_THREADING_C) && !defined(MBEDTLS_THREADING_IMPL)
|
|
||||||
#error "MBEDTLS_THREADING_C defined, single threading implementation required"
|
|
||||||
#endif
|
|
||||||
#undef MBEDTLS_THREADING_IMPL
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_VERSION_FEATURES) && !defined(MBEDTLS_VERSION_C)
|
|
||||||
#error "MBEDTLS_VERSION_FEATURES defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_X509_USE_C) && ( !defined(MBEDTLS_BIGNUM_C) || \
|
|
||||||
!defined(MBEDTLS_OID_C) || !defined(MBEDTLS_ASN1_PARSE_C) || \
|
|
||||||
!defined(MBEDTLS_PK_PARSE_C) )
|
|
||||||
#error "MBEDTLS_X509_USE_C defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_X509_CREATE_C) && ( !defined(MBEDTLS_BIGNUM_C) || \
|
|
||||||
!defined(MBEDTLS_OID_C) || !defined(MBEDTLS_ASN1_WRITE_C) || \
|
|
||||||
!defined(MBEDTLS_PK_WRITE_C) )
|
|
||||||
#error "MBEDTLS_X509_CREATE_C defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_X509_CRT_PARSE_C) && ( !defined(MBEDTLS_X509_USE_C) )
|
|
||||||
#error "MBEDTLS_X509_CRT_PARSE_C defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_X509_CRL_PARSE_C) && ( !defined(MBEDTLS_X509_USE_C) )
|
|
||||||
#error "MBEDTLS_X509_CRL_PARSE_C defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_X509_CSR_PARSE_C) && ( !defined(MBEDTLS_X509_USE_C) )
|
|
||||||
#error "MBEDTLS_X509_CSR_PARSE_C defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_X509_CRT_WRITE_C) && ( !defined(MBEDTLS_X509_CREATE_C) )
|
|
||||||
#error "MBEDTLS_X509_CRT_WRITE_C defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_X509_CSR_WRITE_C) && ( !defined(MBEDTLS_X509_CREATE_C) )
|
|
||||||
#error "MBEDTLS_X509_CSR_WRITE_C defined, but not all prerequisites"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_HAVE_INT32) && defined(MBEDTLS_HAVE_INT64)
|
|
||||||
#error "MBEDTLS_HAVE_INT32 and MBEDTLS_HAVE_INT64 cannot be defined simultaneously"
|
|
||||||
#endif /* MBEDTLS_HAVE_INT32 && MBEDTLS_HAVE_INT64 */
|
|
||||||
|
|
||||||
#if ( defined(MBEDTLS_HAVE_INT32) || defined(MBEDTLS_HAVE_INT64) ) && \
|
|
||||||
defined(MBEDTLS_HAVE_ASM)
|
|
||||||
#error "MBEDTLS_HAVE_INT32/MBEDTLS_HAVE_INT64 and MBEDTLS_HAVE_ASM cannot be defined simultaneously"
|
|
||||||
#endif /* (MBEDTLS_HAVE_INT32 || MBEDTLS_HAVE_INT64) && MBEDTLS_HAVE_ASM */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Avoid warning from -pedantic. This is a convenient place for this
|
|
||||||
* workaround since this is included by every single file before the
|
|
||||||
* #if defined(MBEDTLS_xxx_C) that results in emtpy translation units.
|
|
||||||
*/
|
|
||||||
typedef int mbedtls_iso_c_forbids_empty_translation_units;
|
|
||||||
|
|
||||||
#endif /* MBEDTLS_CHECK_CONFIG_H */
|
|
|
@ -1,808 +0,0 @@
|
||||||
/**
|
|
||||||
* \file cipher.h
|
|
||||||
*
|
|
||||||
* \brief This file contains an abstraction interface for use with the cipher
|
|
||||||
* primitives provided by the library. It provides a common interface to all of
|
|
||||||
* the available cipher operations.
|
|
||||||
*
|
|
||||||
* \author Adriaan de Jong <dejong@fox-it.com>
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
|
|
||||||
* SPDX-License-Identifier: GPL-2.0
|
|
||||||
*
|
|
||||||
* This program 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 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*
|
|
||||||
* This file is part of Mbed TLS (https://tls.mbed.org)
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef MBEDTLS_CIPHER_H
|
|
||||||
#define MBEDTLS_CIPHER_H
|
|
||||||
|
|
||||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
|
||||||
#include "config.h"
|
|
||||||
#else
|
|
||||||
#include MBEDTLS_CONFIG_FILE
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <stddef.h>
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CCM_C) || defined(MBEDTLS_CHACHAPOLY_C)
|
|
||||||
#define MBEDTLS_CIPHER_MODE_AEAD
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
|
||||||
#define MBEDTLS_CIPHER_MODE_WITH_PADDING
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_ARC4_C) || defined(MBEDTLS_CIPHER_NULL_CIPHER) || \
|
|
||||||
defined(MBEDTLS_CHACHA20_C)
|
|
||||||
#define MBEDTLS_CIPHER_MODE_STREAM
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
|
|
||||||
!defined(inline) && !defined(__cplusplus)
|
|
||||||
#define inline __inline
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE -0x6080 /**< The selected feature is not available. */
|
|
||||||
#define MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA -0x6100 /**< Bad input parameters. */
|
|
||||||
#define MBEDTLS_ERR_CIPHER_ALLOC_FAILED -0x6180 /**< Failed to allocate memory. */
|
|
||||||
#define MBEDTLS_ERR_CIPHER_INVALID_PADDING -0x6200 /**< Input data contains invalid padding and is rejected. */
|
|
||||||
#define MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED -0x6280 /**< Decryption of block requires a full block. */
|
|
||||||
#define MBEDTLS_ERR_CIPHER_AUTH_FAILED -0x6300 /**< Authentication failed (for AEAD modes). */
|
|
||||||
#define MBEDTLS_ERR_CIPHER_INVALID_CONTEXT -0x6380 /**< The context is invalid. For example, because it was freed. */
|
|
||||||
#define MBEDTLS_ERR_CIPHER_HW_ACCEL_FAILED -0x6400 /**< Cipher hardware accelerator failed. */
|
|
||||||
|
|
||||||
#define MBEDTLS_CIPHER_VARIABLE_IV_LEN 0x01 /**< Cipher accepts IVs of variable length. */
|
|
||||||
#define MBEDTLS_CIPHER_VARIABLE_KEY_LEN 0x02 /**< Cipher accepts keys of variable length. */
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Supported cipher types.
|
|
||||||
*
|
|
||||||
* \warning RC4 and DES are considered weak ciphers and their use
|
|
||||||
* constitutes a security risk. Arm recommends considering stronger
|
|
||||||
* ciphers instead.
|
|
||||||
*/
|
|
||||||
typedef enum {
|
|
||||||
MBEDTLS_CIPHER_ID_NONE = 0, /**< Placeholder to mark the end of cipher ID lists. */
|
|
||||||
MBEDTLS_CIPHER_ID_NULL, /**< The identity cipher, treated as a stream cipher. */
|
|
||||||
MBEDTLS_CIPHER_ID_AES, /**< The AES cipher. */
|
|
||||||
MBEDTLS_CIPHER_ID_DES, /**< The DES cipher. */
|
|
||||||
MBEDTLS_CIPHER_ID_3DES, /**< The Triple DES cipher. */
|
|
||||||
MBEDTLS_CIPHER_ID_CAMELLIA, /**< The Camellia cipher. */
|
|
||||||
MBEDTLS_CIPHER_ID_BLOWFISH, /**< The Blowfish cipher. */
|
|
||||||
MBEDTLS_CIPHER_ID_ARC4, /**< The RC4 cipher. */
|
|
||||||
MBEDTLS_CIPHER_ID_ARIA, /**< The Aria cipher. */
|
|
||||||
MBEDTLS_CIPHER_ID_CHACHA20, /**< The ChaCha20 cipher. */
|
|
||||||
} mbedtls_cipher_id_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Supported {cipher type, cipher mode} pairs.
|
|
||||||
*
|
|
||||||
* \warning RC4 and DES are considered weak ciphers and their use
|
|
||||||
* constitutes a security risk. Arm recommends considering stronger
|
|
||||||
* ciphers instead.
|
|
||||||
*/
|
|
||||||
typedef enum {
|
|
||||||
MBEDTLS_CIPHER_NONE = 0, /**< Placeholder to mark the end of cipher-pair lists. */
|
|
||||||
MBEDTLS_CIPHER_NULL, /**< The identity stream cipher. */
|
|
||||||
MBEDTLS_CIPHER_AES_128_ECB, /**< AES cipher with 128-bit ECB mode. */
|
|
||||||
MBEDTLS_CIPHER_AES_192_ECB, /**< AES cipher with 192-bit ECB mode. */
|
|
||||||
MBEDTLS_CIPHER_AES_256_ECB, /**< AES cipher with 256-bit ECB mode. */
|
|
||||||
MBEDTLS_CIPHER_AES_128_CBC, /**< AES cipher with 128-bit CBC mode. */
|
|
||||||
MBEDTLS_CIPHER_AES_192_CBC, /**< AES cipher with 192-bit CBC mode. */
|
|
||||||
MBEDTLS_CIPHER_AES_256_CBC, /**< AES cipher with 256-bit CBC mode. */
|
|
||||||
MBEDTLS_CIPHER_AES_128_CFB128, /**< AES cipher with 128-bit CFB128 mode. */
|
|
||||||
MBEDTLS_CIPHER_AES_192_CFB128, /**< AES cipher with 192-bit CFB128 mode. */
|
|
||||||
MBEDTLS_CIPHER_AES_256_CFB128, /**< AES cipher with 256-bit CFB128 mode. */
|
|
||||||
MBEDTLS_CIPHER_AES_128_CTR, /**< AES cipher with 128-bit CTR mode. */
|
|
||||||
MBEDTLS_CIPHER_AES_192_CTR, /**< AES cipher with 192-bit CTR mode. */
|
|
||||||
MBEDTLS_CIPHER_AES_256_CTR, /**< AES cipher with 256-bit CTR mode. */
|
|
||||||
MBEDTLS_CIPHER_AES_128_GCM, /**< AES cipher with 128-bit GCM mode. */
|
|
||||||
MBEDTLS_CIPHER_AES_192_GCM, /**< AES cipher with 192-bit GCM mode. */
|
|
||||||
MBEDTLS_CIPHER_AES_256_GCM, /**< AES cipher with 256-bit GCM mode. */
|
|
||||||
MBEDTLS_CIPHER_CAMELLIA_128_ECB, /**< Camellia cipher with 128-bit ECB mode. */
|
|
||||||
MBEDTLS_CIPHER_CAMELLIA_192_ECB, /**< Camellia cipher with 192-bit ECB mode. */
|
|
||||||
MBEDTLS_CIPHER_CAMELLIA_256_ECB, /**< Camellia cipher with 256-bit ECB mode. */
|
|
||||||
MBEDTLS_CIPHER_CAMELLIA_128_CBC, /**< Camellia cipher with 128-bit CBC mode. */
|
|
||||||
MBEDTLS_CIPHER_CAMELLIA_192_CBC, /**< Camellia cipher with 192-bit CBC mode. */
|
|
||||||
MBEDTLS_CIPHER_CAMELLIA_256_CBC, /**< Camellia cipher with 256-bit CBC mode. */
|
|
||||||
MBEDTLS_CIPHER_CAMELLIA_128_CFB128, /**< Camellia cipher with 128-bit CFB128 mode. */
|
|
||||||
MBEDTLS_CIPHER_CAMELLIA_192_CFB128, /**< Camellia cipher with 192-bit CFB128 mode. */
|
|
||||||
MBEDTLS_CIPHER_CAMELLIA_256_CFB128, /**< Camellia cipher with 256-bit CFB128 mode. */
|
|
||||||
MBEDTLS_CIPHER_CAMELLIA_128_CTR, /**< Camellia cipher with 128-bit CTR mode. */
|
|
||||||
MBEDTLS_CIPHER_CAMELLIA_192_CTR, /**< Camellia cipher with 192-bit CTR mode. */
|
|
||||||
MBEDTLS_CIPHER_CAMELLIA_256_CTR, /**< Camellia cipher with 256-bit CTR mode. */
|
|
||||||
MBEDTLS_CIPHER_CAMELLIA_128_GCM, /**< Camellia cipher with 128-bit GCM mode. */
|
|
||||||
MBEDTLS_CIPHER_CAMELLIA_192_GCM, /**< Camellia cipher with 192-bit GCM mode. */
|
|
||||||
MBEDTLS_CIPHER_CAMELLIA_256_GCM, /**< Camellia cipher with 256-bit GCM mode. */
|
|
||||||
MBEDTLS_CIPHER_DES_ECB, /**< DES cipher with ECB mode. */
|
|
||||||
MBEDTLS_CIPHER_DES_CBC, /**< DES cipher with CBC mode. */
|
|
||||||
MBEDTLS_CIPHER_DES_EDE_ECB, /**< DES cipher with EDE ECB mode. */
|
|
||||||
MBEDTLS_CIPHER_DES_EDE_CBC, /**< DES cipher with EDE CBC mode. */
|
|
||||||
MBEDTLS_CIPHER_DES_EDE3_ECB, /**< DES cipher with EDE3 ECB mode. */
|
|
||||||
MBEDTLS_CIPHER_DES_EDE3_CBC, /**< DES cipher with EDE3 CBC mode. */
|
|
||||||
MBEDTLS_CIPHER_BLOWFISH_ECB, /**< Blowfish cipher with ECB mode. */
|
|
||||||
MBEDTLS_CIPHER_BLOWFISH_CBC, /**< Blowfish cipher with CBC mode. */
|
|
||||||
MBEDTLS_CIPHER_BLOWFISH_CFB64, /**< Blowfish cipher with CFB64 mode. */
|
|
||||||
MBEDTLS_CIPHER_BLOWFISH_CTR, /**< Blowfish cipher with CTR mode. */
|
|
||||||
MBEDTLS_CIPHER_ARC4_128, /**< RC4 cipher with 128-bit mode. */
|
|
||||||
MBEDTLS_CIPHER_AES_128_CCM, /**< AES cipher with 128-bit CCM mode. */
|
|
||||||
MBEDTLS_CIPHER_AES_192_CCM, /**< AES cipher with 192-bit CCM mode. */
|
|
||||||
MBEDTLS_CIPHER_AES_256_CCM, /**< AES cipher with 256-bit CCM mode. */
|
|
||||||
MBEDTLS_CIPHER_CAMELLIA_128_CCM, /**< Camellia cipher with 128-bit CCM mode. */
|
|
||||||
MBEDTLS_CIPHER_CAMELLIA_192_CCM, /**< Camellia cipher with 192-bit CCM mode. */
|
|
||||||
MBEDTLS_CIPHER_CAMELLIA_256_CCM, /**< Camellia cipher with 256-bit CCM mode. */
|
|
||||||
MBEDTLS_CIPHER_ARIA_128_ECB, /**< Aria cipher with 128-bit key and ECB mode. */
|
|
||||||
MBEDTLS_CIPHER_ARIA_192_ECB, /**< Aria cipher with 192-bit key and ECB mode. */
|
|
||||||
MBEDTLS_CIPHER_ARIA_256_ECB, /**< Aria cipher with 256-bit key and ECB mode. */
|
|
||||||
MBEDTLS_CIPHER_ARIA_128_CBC, /**< Aria cipher with 128-bit key and CBC mode. */
|
|
||||||
MBEDTLS_CIPHER_ARIA_192_CBC, /**< Aria cipher with 192-bit key and CBC mode. */
|
|
||||||
MBEDTLS_CIPHER_ARIA_256_CBC, /**< Aria cipher with 256-bit key and CBC mode. */
|
|
||||||
MBEDTLS_CIPHER_ARIA_128_CFB128, /**< Aria cipher with 128-bit key and CFB-128 mode. */
|
|
||||||
MBEDTLS_CIPHER_ARIA_192_CFB128, /**< Aria cipher with 192-bit key and CFB-128 mode. */
|
|
||||||
MBEDTLS_CIPHER_ARIA_256_CFB128, /**< Aria cipher with 256-bit key and CFB-128 mode. */
|
|
||||||
MBEDTLS_CIPHER_ARIA_128_CTR, /**< Aria cipher with 128-bit key and CTR mode. */
|
|
||||||
MBEDTLS_CIPHER_ARIA_192_CTR, /**< Aria cipher with 192-bit key and CTR mode. */
|
|
||||||
MBEDTLS_CIPHER_ARIA_256_CTR, /**< Aria cipher with 256-bit key and CTR mode. */
|
|
||||||
MBEDTLS_CIPHER_ARIA_128_GCM, /**< Aria cipher with 128-bit key and GCM mode. */
|
|
||||||
MBEDTLS_CIPHER_ARIA_192_GCM, /**< Aria cipher with 192-bit key and GCM mode. */
|
|
||||||
MBEDTLS_CIPHER_ARIA_256_GCM, /**< Aria cipher with 256-bit key and GCM mode. */
|
|
||||||
MBEDTLS_CIPHER_ARIA_128_CCM, /**< Aria cipher with 128-bit key and CCM mode. */
|
|
||||||
MBEDTLS_CIPHER_ARIA_192_CCM, /**< Aria cipher with 192-bit key and CCM mode. */
|
|
||||||
MBEDTLS_CIPHER_ARIA_256_CCM, /**< Aria cipher with 256-bit key and CCM mode. */
|
|
||||||
MBEDTLS_CIPHER_AES_128_OFB, /**< AES 128-bit cipher in OFB mode. */
|
|
||||||
MBEDTLS_CIPHER_AES_192_OFB, /**< AES 192-bit cipher in OFB mode. */
|
|
||||||
MBEDTLS_CIPHER_AES_256_OFB, /**< AES 256-bit cipher in OFB mode. */
|
|
||||||
MBEDTLS_CIPHER_AES_128_XTS, /**< AES 128-bit cipher in XTS block mode. */
|
|
||||||
MBEDTLS_CIPHER_AES_256_XTS, /**< AES 256-bit cipher in XTS block mode. */
|
|
||||||
MBEDTLS_CIPHER_CHACHA20, /**< ChaCha20 stream cipher. */
|
|
||||||
MBEDTLS_CIPHER_CHACHA20_POLY1305, /**< ChaCha20-Poly1305 AEAD cipher. */
|
|
||||||
} mbedtls_cipher_type_t;
|
|
||||||
|
|
||||||
/** Supported cipher modes. */
|
|
||||||
typedef enum {
|
|
||||||
MBEDTLS_MODE_NONE = 0, /**< None. */
|
|
||||||
MBEDTLS_MODE_ECB, /**< The ECB cipher mode. */
|
|
||||||
MBEDTLS_MODE_CBC, /**< The CBC cipher mode. */
|
|
||||||
MBEDTLS_MODE_CFB, /**< The CFB cipher mode. */
|
|
||||||
MBEDTLS_MODE_OFB, /**< The OFB cipher mode. */
|
|
||||||
MBEDTLS_MODE_CTR, /**< The CTR cipher mode. */
|
|
||||||
MBEDTLS_MODE_GCM, /**< The GCM cipher mode. */
|
|
||||||
MBEDTLS_MODE_STREAM, /**< The stream cipher mode. */
|
|
||||||
MBEDTLS_MODE_CCM, /**< The CCM cipher mode. */
|
|
||||||
MBEDTLS_MODE_XTS, /**< The XTS cipher mode. */
|
|
||||||
MBEDTLS_MODE_CHACHAPOLY, /**< The ChaCha-Poly cipher mode. */
|
|
||||||
} mbedtls_cipher_mode_t;
|
|
||||||
|
|
||||||
/** Supported cipher padding types. */
|
|
||||||
typedef enum {
|
|
||||||
MBEDTLS_PADDING_PKCS7 = 0, /**< PKCS7 padding (default). */
|
|
||||||
MBEDTLS_PADDING_ONE_AND_ZEROS, /**< ISO/IEC 7816-4 padding. */
|
|
||||||
MBEDTLS_PADDING_ZEROS_AND_LEN, /**< ANSI X.923 padding. */
|
|
||||||
MBEDTLS_PADDING_ZEROS, /**< Zero padding (not reversible). */
|
|
||||||
MBEDTLS_PADDING_NONE, /**< Never pad (full blocks only). */
|
|
||||||
} mbedtls_cipher_padding_t;
|
|
||||||
|
|
||||||
/** Type of operation. */
|
|
||||||
typedef enum {
|
|
||||||
MBEDTLS_OPERATION_NONE = -1,
|
|
||||||
MBEDTLS_DECRYPT = 0,
|
|
||||||
MBEDTLS_ENCRYPT,
|
|
||||||
} mbedtls_operation_t;
|
|
||||||
|
|
||||||
enum {
|
|
||||||
/** Undefined key length. */
|
|
||||||
MBEDTLS_KEY_LENGTH_NONE = 0,
|
|
||||||
/** Key length, in bits (including parity), for DES keys. */
|
|
||||||
MBEDTLS_KEY_LENGTH_DES = 64,
|
|
||||||
/** Key length in bits, including parity, for DES in two-key EDE. */
|
|
||||||
MBEDTLS_KEY_LENGTH_DES_EDE = 128,
|
|
||||||
/** Key length in bits, including parity, for DES in three-key EDE. */
|
|
||||||
MBEDTLS_KEY_LENGTH_DES_EDE3 = 192,
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Maximum length of any IV, in Bytes. */
|
|
||||||
#define MBEDTLS_MAX_IV_LENGTH 16
|
|
||||||
/** Maximum block size of any cipher, in Bytes. */
|
|
||||||
#define MBEDTLS_MAX_BLOCK_LENGTH 16
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Base cipher information (opaque struct).
|
|
||||||
*/
|
|
||||||
typedef struct mbedtls_cipher_base_t mbedtls_cipher_base_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* CMAC context (opaque struct).
|
|
||||||
*/
|
|
||||||
typedef struct mbedtls_cmac_context_t mbedtls_cmac_context_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Cipher information. Allows calling cipher functions
|
|
||||||
* in a generic way.
|
|
||||||
*/
|
|
||||||
typedef struct mbedtls_cipher_info_t
|
|
||||||
{
|
|
||||||
/** Full cipher identifier. For example,
|
|
||||||
* MBEDTLS_CIPHER_AES_256_CBC.
|
|
||||||
*/
|
|
||||||
mbedtls_cipher_type_t type;
|
|
||||||
|
|
||||||
/** The cipher mode. For example, MBEDTLS_MODE_CBC. */
|
|
||||||
mbedtls_cipher_mode_t mode;
|
|
||||||
|
|
||||||
/** The cipher key length, in bits. This is the
|
|
||||||
* default length for variable sized ciphers.
|
|
||||||
* Includes parity bits for ciphers like DES.
|
|
||||||
*/
|
|
||||||
unsigned int key_bitlen;
|
|
||||||
|
|
||||||
/** Name of the cipher. */
|
|
||||||
const char * name;
|
|
||||||
|
|
||||||
/** IV or nonce size, in Bytes.
|
|
||||||
* For ciphers that accept variable IV sizes,
|
|
||||||
* this is the recommended size.
|
|
||||||
*/
|
|
||||||
unsigned int iv_size;
|
|
||||||
|
|
||||||
/** Bitflag comprised of MBEDTLS_CIPHER_VARIABLE_IV_LEN and
|
|
||||||
* MBEDTLS_CIPHER_VARIABLE_KEY_LEN indicating whether the
|
|
||||||
* cipher supports variable IV or variable key sizes, respectively.
|
|
||||||
*/
|
|
||||||
int flags;
|
|
||||||
|
|
||||||
/** The block size, in Bytes. */
|
|
||||||
unsigned int block_size;
|
|
||||||
|
|
||||||
/** Struct for base cipher information and functions. */
|
|
||||||
const mbedtls_cipher_base_t *base;
|
|
||||||
|
|
||||||
} mbedtls_cipher_info_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generic cipher context.
|
|
||||||
*/
|
|
||||||
typedef struct mbedtls_cipher_context_t
|
|
||||||
{
|
|
||||||
/** Information about the associated cipher. */
|
|
||||||
const mbedtls_cipher_info_t *cipher_info;
|
|
||||||
|
|
||||||
/** Key length to use. */
|
|
||||||
int key_bitlen;
|
|
||||||
|
|
||||||
/** Operation that the key of the context has been
|
|
||||||
* initialized for.
|
|
||||||
*/
|
|
||||||
mbedtls_operation_t operation;
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_CIPHER_MODE_WITH_PADDING)
|
|
||||||
/** Padding functions to use, if relevant for
|
|
||||||
* the specific cipher mode.
|
|
||||||
*/
|
|
||||||
void (*add_padding)( unsigned char *output, size_t olen, size_t data_len );
|
|
||||||
int (*get_padding)( unsigned char *input, size_t ilen, size_t *data_len );
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/** Buffer for input that has not been processed yet. */
|
|
||||||
unsigned char unprocessed_data[MBEDTLS_MAX_BLOCK_LENGTH];
|
|
||||||
|
|
||||||
/** Number of Bytes that have not been processed yet. */
|
|
||||||
size_t unprocessed_len;
|
|
||||||
|
|
||||||
/** Current IV or NONCE_COUNTER for CTR-mode, data unit (or sector) number
|
|
||||||
* for XTS-mode. */
|
|
||||||
unsigned char iv[MBEDTLS_MAX_IV_LENGTH];
|
|
||||||
|
|
||||||
/** IV size in Bytes, for ciphers with variable-length IVs. */
|
|
||||||
size_t iv_size;
|
|
||||||
|
|
||||||
/** The cipher-specific context. */
|
|
||||||
void *cipher_ctx;
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_CMAC_C)
|
|
||||||
/** CMAC-specific context. */
|
|
||||||
mbedtls_cmac_context_t *cmac_ctx;
|
|
||||||
#endif
|
|
||||||
} mbedtls_cipher_context_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief This function retrieves the list of ciphers supported by the generic
|
|
||||||
* cipher module.
|
|
||||||
*
|
|
||||||
* \return A statically-allocated array of ciphers. The last entry
|
|
||||||
* is zero.
|
|
||||||
*/
|
|
||||||
const int *mbedtls_cipher_list( void );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief This function retrieves the cipher-information
|
|
||||||
* structure associated with the given cipher name.
|
|
||||||
*
|
|
||||||
* \param cipher_name Name of the cipher to search for.
|
|
||||||
*
|
|
||||||
* \return The cipher information structure associated with the
|
|
||||||
* given \p cipher_name.
|
|
||||||
* \return NULL if the associated cipher information is not found.
|
|
||||||
*/
|
|
||||||
const mbedtls_cipher_info_t *mbedtls_cipher_info_from_string( const char *cipher_name );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief This function retrieves the cipher-information
|
|
||||||
* structure associated with the given cipher type.
|
|
||||||
*
|
|
||||||
* \param cipher_type Type of the cipher to search for.
|
|
||||||
*
|
|
||||||
* \return The cipher information structure associated with the
|
|
||||||
* given \p cipher_type.
|
|
||||||
* \return NULL if the associated cipher information is not found.
|
|
||||||
*/
|
|
||||||
const mbedtls_cipher_info_t *mbedtls_cipher_info_from_type( const mbedtls_cipher_type_t cipher_type );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief This function retrieves the cipher-information
|
|
||||||
* structure associated with the given cipher ID,
|
|
||||||
* key size and mode.
|
|
||||||
*
|
|
||||||
* \param cipher_id The ID of the cipher to search for. For example,
|
|
||||||
* #MBEDTLS_CIPHER_ID_AES.
|
|
||||||
* \param key_bitlen The length of the key in bits.
|
|
||||||
* \param mode The cipher mode. For example, #MBEDTLS_MODE_CBC.
|
|
||||||
*
|
|
||||||
* \return The cipher information structure associated with the
|
|
||||||
* given \p cipher_id.
|
|
||||||
* \return NULL if the associated cipher information is not found.
|
|
||||||
*/
|
|
||||||
const mbedtls_cipher_info_t *mbedtls_cipher_info_from_values( const mbedtls_cipher_id_t cipher_id,
|
|
||||||
int key_bitlen,
|
|
||||||
const mbedtls_cipher_mode_t mode );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief This function initializes a \p cipher_context as NONE.
|
|
||||||
*/
|
|
||||||
void mbedtls_cipher_init( mbedtls_cipher_context_t *ctx );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief This function frees and clears the cipher-specific
|
|
||||||
* context of \p ctx. Freeing \p ctx itself remains the
|
|
||||||
* responsibility of the caller.
|
|
||||||
*/
|
|
||||||
void mbedtls_cipher_free( mbedtls_cipher_context_t *ctx );
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief This function initializes and fills the cipher-context
|
|
||||||
* structure with the appropriate values. It also clears
|
|
||||||
* the structure.
|
|
||||||
*
|
|
||||||
* \param ctx The context to initialize. May not be NULL.
|
|
||||||
* \param cipher_info The cipher to use.
|
|
||||||
*
|
|
||||||
* \return \c 0 on success.
|
|
||||||
* \return #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on
|
|
||||||
* parameter-verification failure.
|
|
||||||
* \return #MBEDTLS_ERR_CIPHER_ALLOC_FAILED if allocation of the
|
|
||||||
* cipher-specific context fails.
|
|
||||||
*
|
|
||||||
* \internal Currently, the function also clears the structure.
|
|
||||||
* In future versions, the caller will be required to call
|
|
||||||
* mbedtls_cipher_init() on the structure first.
|
|
||||||
*/
|
|
||||||
int mbedtls_cipher_setup( mbedtls_cipher_context_t *ctx, const mbedtls_cipher_info_t *cipher_info );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief This function returns the block size of the given cipher.
|
|
||||||
*
|
|
||||||
* \param ctx The context of the cipher. Must be initialized.
|
|
||||||
*
|
|
||||||
* \return The size of the blocks of the cipher.
|
|
||||||
* \return 0 if \p ctx has not been initialized.
|
|
||||||
*/
|
|
||||||
static inline unsigned int mbedtls_cipher_get_block_size( const mbedtls_cipher_context_t *ctx )
|
|
||||||
{
|
|
||||||
if( NULL == ctx || NULL == ctx->cipher_info )
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
return ctx->cipher_info->block_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief This function returns the mode of operation for
|
|
||||||
* the cipher. For example, MBEDTLS_MODE_CBC.
|
|
||||||
*
|
|
||||||
* \param ctx The context of the cipher. Must be initialized.
|
|
||||||
*
|
|
||||||
* \return The mode of operation.
|
|
||||||
* \return #MBEDTLS_MODE_NONE if \p ctx has not been initialized.
|
|
||||||
*/
|
|
||||||
static inline mbedtls_cipher_mode_t mbedtls_cipher_get_cipher_mode( const mbedtls_cipher_context_t *ctx )
|
|
||||||
{
|
|
||||||
if( NULL == ctx || NULL == ctx->cipher_info )
|
|
||||||
return MBEDTLS_MODE_NONE;
|
|
||||||
|
|
||||||
return ctx->cipher_info->mode;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief This function returns the size of the IV or nonce
|
|
||||||
* of the cipher, in Bytes.
|
|
||||||
*
|
|
||||||
* \param ctx The context of the cipher. Must be initialized.
|
|
||||||
*
|
|
||||||
* \return The recommended IV size if no IV has been set.
|
|
||||||
* \return \c 0 for ciphers not using an IV or a nonce.
|
|
||||||
* \return The actual size if an IV has been set.
|
|
||||||
*/
|
|
||||||
static inline int mbedtls_cipher_get_iv_size( const mbedtls_cipher_context_t *ctx )
|
|
||||||
{
|
|
||||||
if( NULL == ctx || NULL == ctx->cipher_info )
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if( ctx->iv_size != 0 )
|
|
||||||
return (int) ctx->iv_size;
|
|
||||||
|
|
||||||
return (int) ctx->cipher_info->iv_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief This function returns the type of the given cipher.
|
|
||||||
*
|
|
||||||
* \param ctx The context of the cipher. Must be initialized.
|
|
||||||
*
|
|
||||||
* \return The type of the cipher.
|
|
||||||
* \return #MBEDTLS_CIPHER_NONE if \p ctx has not been initialized.
|
|
||||||
*/
|
|
||||||
static inline mbedtls_cipher_type_t mbedtls_cipher_get_type( const mbedtls_cipher_context_t *ctx )
|
|
||||||
{
|
|
||||||
if( NULL == ctx || NULL == ctx->cipher_info )
|
|
||||||
return MBEDTLS_CIPHER_NONE;
|
|
||||||
|
|
||||||
return ctx->cipher_info->type;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief This function returns the name of the given cipher
|
|
||||||
* as a string.
|
|
||||||
*
|
|
||||||
* \param ctx The context of the cipher. Must be initialized.
|
|
||||||
*
|
|
||||||
* \return The name of the cipher.
|
|
||||||
* \return NULL if \p ctx has not been not initialized.
|
|
||||||
*/
|
|
||||||
static inline const char *mbedtls_cipher_get_name( const mbedtls_cipher_context_t *ctx )
|
|
||||||
{
|
|
||||||
if( NULL == ctx || NULL == ctx->cipher_info )
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
return ctx->cipher_info->name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief This function returns the key length of the cipher.
|
|
||||||
*
|
|
||||||
* \param ctx The context of the cipher. Must be initialized.
|
|
||||||
*
|
|
||||||
* \return The key length of the cipher in bits.
|
|
||||||
* \return #MBEDTLS_KEY_LENGTH_NONE if ctx \p has not been
|
|
||||||
* initialized.
|
|
||||||
*/
|
|
||||||
static inline int mbedtls_cipher_get_key_bitlen( const mbedtls_cipher_context_t *ctx )
|
|
||||||
{
|
|
||||||
if( NULL == ctx || NULL == ctx->cipher_info )
|
|
||||||
return MBEDTLS_KEY_LENGTH_NONE;
|
|
||||||
|
|
||||||
return (int) ctx->cipher_info->key_bitlen;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief This function returns the operation of the given cipher.
|
|
||||||
*
|
|
||||||
* \param ctx The context of the cipher. Must be initialized.
|
|
||||||
*
|
|
||||||
* \return The type of operation: #MBEDTLS_ENCRYPT or #MBEDTLS_DECRYPT.
|
|
||||||
* \return #MBEDTLS_OPERATION_NONE if \p ctx has not been initialized.
|
|
||||||
*/
|
|
||||||
static inline mbedtls_operation_t mbedtls_cipher_get_operation( const mbedtls_cipher_context_t *ctx )
|
|
||||||
{
|
|
||||||
if( NULL == ctx || NULL == ctx->cipher_info )
|
|
||||||
return MBEDTLS_OPERATION_NONE;
|
|
||||||
|
|
||||||
return ctx->operation;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief This function sets the key to use with the given context.
|
|
||||||
*
|
|
||||||
* \param ctx The generic cipher context. May not be NULL. Must have
|
|
||||||
* been initialized using mbedtls_cipher_info_from_type()
|
|
||||||
* or mbedtls_cipher_info_from_string().
|
|
||||||
* \param key The key to use.
|
|
||||||
* \param key_bitlen The key length to use, in bits.
|
|
||||||
* \param operation The operation that the key will be used for:
|
|
||||||
* #MBEDTLS_ENCRYPT or #MBEDTLS_DECRYPT.
|
|
||||||
*
|
|
||||||
* \return \c 0 on success.
|
|
||||||
* \return #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on
|
|
||||||
* parameter-verification failure.
|
|
||||||
* \return A cipher-specific error code on failure.
|
|
||||||
*/
|
|
||||||
int mbedtls_cipher_setkey( mbedtls_cipher_context_t *ctx, const unsigned char *key,
|
|
||||||
int key_bitlen, const mbedtls_operation_t operation );
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_CIPHER_MODE_WITH_PADDING)
|
|
||||||
/**
|
|
||||||
* \brief This function sets the padding mode, for cipher modes
|
|
||||||
* that use padding.
|
|
||||||
*
|
|
||||||
* The default passing mode is PKCS7 padding.
|
|
||||||
*
|
|
||||||
* \param ctx The generic cipher context.
|
|
||||||
* \param mode The padding mode.
|
|
||||||
*
|
|
||||||
* \return \c 0 on success.
|
|
||||||
* \return #MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE
|
|
||||||
* if the selected padding mode is not supported.
|
|
||||||
* \return #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA if the cipher mode
|
|
||||||
* does not support padding.
|
|
||||||
*/
|
|
||||||
int mbedtls_cipher_set_padding_mode( mbedtls_cipher_context_t *ctx, mbedtls_cipher_padding_t mode );
|
|
||||||
#endif /* MBEDTLS_CIPHER_MODE_WITH_PADDING */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief This function sets the initialization vector (IV)
|
|
||||||
* or nonce.
|
|
||||||
*
|
|
||||||
* \note Some ciphers do not use IVs nor nonce. For these
|
|
||||||
* ciphers, this function has no effect.
|
|
||||||
*
|
|
||||||
* \param ctx The generic cipher context.
|
|
||||||
* \param iv The IV to use, or NONCE_COUNTER for CTR-mode ciphers.
|
|
||||||
* \param iv_len The IV length for ciphers with variable-size IV.
|
|
||||||
* This parameter is discarded by ciphers with fixed-size IV.
|
|
||||||
*
|
|
||||||
* \return \c 0 on success.
|
|
||||||
* \return #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on
|
|
||||||
* parameter-verification failure.
|
|
||||||
*/
|
|
||||||
int mbedtls_cipher_set_iv( mbedtls_cipher_context_t *ctx,
|
|
||||||
const unsigned char *iv, size_t iv_len );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief This function resets the cipher state.
|
|
||||||
*
|
|
||||||
* \param ctx The generic cipher context.
|
|
||||||
*
|
|
||||||
* \return \c 0 on success.
|
|
||||||
* \return #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on
|
|
||||||
* parameter-verification failure.
|
|
||||||
*/
|
|
||||||
int mbedtls_cipher_reset( mbedtls_cipher_context_t *ctx );
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CHACHAPOLY_C)
|
|
||||||
/**
|
|
||||||
* \brief This function adds additional data for AEAD ciphers.
|
|
||||||
* Currently supported with GCM and ChaCha20+Poly1305.
|
|
||||||
* Must be called exactly once, after mbedtls_cipher_reset().
|
|
||||||
*
|
|
||||||
* \param ctx The generic cipher context.
|
|
||||||
* \param ad The additional data to use.
|
|
||||||
* \param ad_len the Length of \p ad.
|
|
||||||
*
|
|
||||||
* \return \c 0 on success.
|
|
||||||
* \return A specific error code on failure.
|
|
||||||
*/
|
|
||||||
int mbedtls_cipher_update_ad( mbedtls_cipher_context_t *ctx,
|
|
||||||
const unsigned char *ad, size_t ad_len );
|
|
||||||
#endif /* MBEDTLS_GCM_C || MBEDTLS_CHACHAPOLY_C */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief The generic cipher update function. It encrypts or
|
|
||||||
* decrypts using the given cipher context. Writes as
|
|
||||||
* many block-sized blocks of data as possible to output.
|
|
||||||
* Any data that cannot be written immediately is either
|
|
||||||
* added to the next block, or flushed when
|
|
||||||
* mbedtls_cipher_finish() is called.
|
|
||||||
* Exception: For MBEDTLS_MODE_ECB, expects a single block
|
|
||||||
* in size. For example, 16 Bytes for AES.
|
|
||||||
*
|
|
||||||
* \note If the underlying cipher is used in GCM mode, all calls
|
|
||||||
* to this function, except for the last one before
|
|
||||||
* mbedtls_cipher_finish(), must have \p ilen as a
|
|
||||||
* multiple of the block size of the cipher.
|
|
||||||
*
|
|
||||||
* \param ctx The generic cipher context.
|
|
||||||
* \param input The buffer holding the input data.
|
|
||||||
* \param ilen The length of the input data.
|
|
||||||
* \param output The buffer for the output data. Must be able to hold at
|
|
||||||
* least \p ilen + block_size. Must not be the same buffer
|
|
||||||
* as input.
|
|
||||||
* \param olen The length of the output data, to be updated with the
|
|
||||||
* actual number of Bytes written.
|
|
||||||
*
|
|
||||||
* \return \c 0 on success.
|
|
||||||
* \return #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on
|
|
||||||
* parameter-verification failure.
|
|
||||||
* \return #MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE on an
|
|
||||||
* unsupported mode for a cipher.
|
|
||||||
* \return A cipher-specific error code on failure.
|
|
||||||
*/
|
|
||||||
int mbedtls_cipher_update( mbedtls_cipher_context_t *ctx, const unsigned char *input,
|
|
||||||
size_t ilen, unsigned char *output, size_t *olen );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief The generic cipher finalization function. If data still
|
|
||||||
* needs to be flushed from an incomplete block, the data
|
|
||||||
* contained in it is padded to the size of
|
|
||||||
* the last block, and written to the \p output buffer.
|
|
||||||
*
|
|
||||||
* \param ctx The generic cipher context.
|
|
||||||
* \param output The buffer to write data to. Needs block_size available.
|
|
||||||
* \param olen The length of the data written to the \p output buffer.
|
|
||||||
*
|
|
||||||
* \return \c 0 on success.
|
|
||||||
* \return #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on
|
|
||||||
* parameter-verification failure.
|
|
||||||
* \return #MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED on decryption
|
|
||||||
* expecting a full block but not receiving one.
|
|
||||||
* \return #MBEDTLS_ERR_CIPHER_INVALID_PADDING on invalid padding
|
|
||||||
* while decrypting.
|
|
||||||
* \return A cipher-specific error code on failure.
|
|
||||||
*/
|
|
||||||
int mbedtls_cipher_finish( mbedtls_cipher_context_t *ctx,
|
|
||||||
unsigned char *output, size_t *olen );
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CHACHAPOLY_C)
|
|
||||||
/**
|
|
||||||
* \brief This function writes a tag for AEAD ciphers.
|
|
||||||
* Currently supported with GCM and ChaCha20+Poly1305.
|
|
||||||
* Must be called after mbedtls_cipher_finish().
|
|
||||||
*
|
|
||||||
* \param ctx The generic cipher context.
|
|
||||||
* \param tag The buffer to write the tag to.
|
|
||||||
* \param tag_len The length of the tag to write.
|
|
||||||
*
|
|
||||||
* \return \c 0 on success.
|
|
||||||
* \return A specific error code on failure.
|
|
||||||
*/
|
|
||||||
int mbedtls_cipher_write_tag( mbedtls_cipher_context_t *ctx,
|
|
||||||
unsigned char *tag, size_t tag_len );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief This function checks the tag for AEAD ciphers.
|
|
||||||
* Currently supported with GCM and ChaCha20+Poly1305.
|
|
||||||
* Must be called after mbedtls_cipher_finish().
|
|
||||||
*
|
|
||||||
* \param ctx The generic cipher context.
|
|
||||||
* \param tag The buffer holding the tag.
|
|
||||||
* \param tag_len The length of the tag to check.
|
|
||||||
*
|
|
||||||
* \return \c 0 on success.
|
|
||||||
* \return A specific error code on failure.
|
|
||||||
*/
|
|
||||||
int mbedtls_cipher_check_tag( mbedtls_cipher_context_t *ctx,
|
|
||||||
const unsigned char *tag, size_t tag_len );
|
|
||||||
#endif /* MBEDTLS_GCM_C || MBEDTLS_CHACHAPOLY_C */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief The generic all-in-one encryption/decryption function,
|
|
||||||
* for all ciphers except AEAD constructs.
|
|
||||||
*
|
|
||||||
* \param ctx The generic cipher context.
|
|
||||||
* \param iv The IV to use, or NONCE_COUNTER for CTR-mode ciphers.
|
|
||||||
* \param iv_len The IV length for ciphers with variable-size IV.
|
|
||||||
* This parameter is discarded by ciphers with fixed-size
|
|
||||||
* IV.
|
|
||||||
* \param input The buffer holding the input data.
|
|
||||||
* \param ilen The length of the input data.
|
|
||||||
* \param output The buffer for the output data. Must be able to hold at
|
|
||||||
* least \p ilen + block_size. Must not be the same buffer
|
|
||||||
* as input.
|
|
||||||
* \param olen The length of the output data, to be updated with the
|
|
||||||
* actual number of Bytes written.
|
|
||||||
*
|
|
||||||
* \note Some ciphers do not use IVs nor nonce. For these
|
|
||||||
* ciphers, use \p iv = NULL and \p iv_len = 0.
|
|
||||||
*
|
|
||||||
* \return \c 0 on success.
|
|
||||||
* \return #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on
|
|
||||||
* parameter-verification failure.
|
|
||||||
* \return #MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED on decryption
|
|
||||||
* expecting a full block but not receiving one.
|
|
||||||
* \return #MBEDTLS_ERR_CIPHER_INVALID_PADDING on invalid padding
|
|
||||||
* while decrypting.
|
|
||||||
* \return A cipher-specific error code on failure.
|
|
||||||
*/
|
|
||||||
int mbedtls_cipher_crypt( mbedtls_cipher_context_t *ctx,
|
|
||||||
const unsigned char *iv, size_t iv_len,
|
|
||||||
const unsigned char *input, size_t ilen,
|
|
||||||
unsigned char *output, size_t *olen );
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_CIPHER_MODE_AEAD)
|
|
||||||
/**
|
|
||||||
* \brief The generic autenticated encryption (AEAD) function.
|
|
||||||
*
|
|
||||||
* \param ctx The generic cipher context.
|
|
||||||
* \param iv The IV to use, or NONCE_COUNTER for CTR-mode ciphers.
|
|
||||||
* \param iv_len The IV length for ciphers with variable-size IV.
|
|
||||||
* This parameter is discarded by ciphers with fixed-size IV.
|
|
||||||
* \param ad The additional data to authenticate.
|
|
||||||
* \param ad_len The length of \p ad.
|
|
||||||
* \param input The buffer holding the input data.
|
|
||||||
* \param ilen The length of the input data.
|
|
||||||
* \param output The buffer for the output data.
|
|
||||||
* Must be able to hold at least \p ilen.
|
|
||||||
* \param olen The length of the output data, to be updated with the
|
|
||||||
* actual number of Bytes written.
|
|
||||||
* \param tag The buffer for the authentication tag.
|
|
||||||
* \param tag_len The desired length of the authentication tag.
|
|
||||||
*
|
|
||||||
* \return \c 0 on success.
|
|
||||||
* \return #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on
|
|
||||||
* parameter-verification failure.
|
|
||||||
* \return A cipher-specific error code on failure.
|
|
||||||
*/
|
|
||||||
int mbedtls_cipher_auth_encrypt( mbedtls_cipher_context_t *ctx,
|
|
||||||
const unsigned char *iv, size_t iv_len,
|
|
||||||
const unsigned char *ad, size_t ad_len,
|
|
||||||
const unsigned char *input, size_t ilen,
|
|
||||||
unsigned char *output, size_t *olen,
|
|
||||||
unsigned char *tag, size_t tag_len );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief The generic autenticated decryption (AEAD) function.
|
|
||||||
*
|
|
||||||
* \note If the data is not authentic, then the output buffer
|
|
||||||
* is zeroed out to prevent the unauthentic plaintext being
|
|
||||||
* used, making this interface safer.
|
|
||||||
*
|
|
||||||
* \param ctx The generic cipher context.
|
|
||||||
* \param iv The IV to use, or NONCE_COUNTER for CTR-mode ciphers.
|
|
||||||
* \param iv_len The IV length for ciphers with variable-size IV.
|
|
||||||
* This parameter is discarded by ciphers with fixed-size IV.
|
|
||||||
* \param ad The additional data to be authenticated.
|
|
||||||
* \param ad_len The length of \p ad.
|
|
||||||
* \param input The buffer holding the input data.
|
|
||||||
* \param ilen The length of the input data.
|
|
||||||
* \param output The buffer for the output data.
|
|
||||||
* Must be able to hold at least \p ilen.
|
|
||||||
* \param olen The length of the output data, to be updated with the
|
|
||||||
* actual number of Bytes written.
|
|
||||||
* \param tag The buffer holding the authentication tag.
|
|
||||||
* \param tag_len The length of the authentication tag.
|
|
||||||
*
|
|
||||||
* \return \c 0 on success.
|
|
||||||
* \return #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on
|
|
||||||
* parameter-verification failure.
|
|
||||||
* \return #MBEDTLS_ERR_CIPHER_AUTH_FAILED if data is not authentic.
|
|
||||||
* \return A cipher-specific error code on failure.
|
|
||||||
*/
|
|
||||||
int mbedtls_cipher_auth_decrypt( mbedtls_cipher_context_t *ctx,
|
|
||||||
const unsigned char *iv, size_t iv_len,
|
|
||||||
const unsigned char *ad, size_t ad_len,
|
|
||||||
const unsigned char *input, size_t ilen,
|
|
||||||
unsigned char *output, size_t *olen,
|
|
||||||
const unsigned char *tag, size_t tag_len );
|
|
||||||
#endif /* MBEDTLS_CIPHER_MODE_AEAD */
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* MBEDTLS_CIPHER_H */
|
|
|
@ -1,127 +0,0 @@
|
||||||
/**
|
|
||||||
* \file cipher_internal.h
|
|
||||||
*
|
|
||||||
* \brief Cipher wrappers.
|
|
||||||
*
|
|
||||||
* \author Adriaan de Jong <dejong@fox-it.com>
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
|
|
||||||
* SPDX-License-Identifier: GPL-2.0
|
|
||||||
*
|
|
||||||
* This program 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 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*
|
|
||||||
* This file is part of mbed TLS (https://tls.mbed.org)
|
|
||||||
*/
|
|
||||||
#ifndef MBEDTLS_CIPHER_WRAP_H
|
|
||||||
#define MBEDTLS_CIPHER_WRAP_H
|
|
||||||
|
|
||||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
|
||||||
#include "config.h"
|
|
||||||
#else
|
|
||||||
#include MBEDTLS_CONFIG_FILE
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "cipher.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Base cipher information. The non-mode specific functions and values.
|
|
||||||
*/
|
|
||||||
struct mbedtls_cipher_base_t
|
|
||||||
{
|
|
||||||
/** Base Cipher type (e.g. MBEDTLS_CIPHER_ID_AES) */
|
|
||||||
mbedtls_cipher_id_t cipher;
|
|
||||||
|
|
||||||
/** Encrypt using ECB */
|
|
||||||
int (*ecb_func)( void *ctx, mbedtls_operation_t mode,
|
|
||||||
const unsigned char *input, unsigned char *output );
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
|
||||||
/** Encrypt using CBC */
|
|
||||||
int (*cbc_func)( void *ctx, mbedtls_operation_t mode, size_t length,
|
|
||||||
unsigned char *iv, const unsigned char *input,
|
|
||||||
unsigned char *output );
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_CIPHER_MODE_CFB)
|
|
||||||
/** Encrypt using CFB (Full length) */
|
|
||||||
int (*cfb_func)( void *ctx, mbedtls_operation_t mode, size_t length, size_t *iv_off,
|
|
||||||
unsigned char *iv, const unsigned char *input,
|
|
||||||
unsigned char *output );
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_CIPHER_MODE_OFB)
|
|
||||||
/** Encrypt using OFB (Full length) */
|
|
||||||
int (*ofb_func)( void *ctx, size_t length, size_t *iv_off,
|
|
||||||
unsigned char *iv,
|
|
||||||
const unsigned char *input,
|
|
||||||
unsigned char *output );
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_CIPHER_MODE_CTR)
|
|
||||||
/** Encrypt using CTR */
|
|
||||||
int (*ctr_func)( void *ctx, size_t length, size_t *nc_off,
|
|
||||||
unsigned char *nonce_counter, unsigned char *stream_block,
|
|
||||||
const unsigned char *input, unsigned char *output );
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_CIPHER_MODE_XTS)
|
|
||||||
/** Encrypt or decrypt using XTS. */
|
|
||||||
int (*xts_func)( void *ctx, mbedtls_operation_t mode, size_t length,
|
|
||||||
const unsigned char data_unit[16],
|
|
||||||
const unsigned char *input, unsigned char *output );
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_CIPHER_MODE_STREAM)
|
|
||||||
/** Encrypt using STREAM */
|
|
||||||
int (*stream_func)( void *ctx, size_t length,
|
|
||||||
const unsigned char *input, unsigned char *output );
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/** Set key for encryption purposes */
|
|
||||||
int (*setkey_enc_func)( void *ctx, const unsigned char *key,
|
|
||||||
unsigned int key_bitlen );
|
|
||||||
|
|
||||||
/** Set key for decryption purposes */
|
|
||||||
int (*setkey_dec_func)( void *ctx, const unsigned char *key,
|
|
||||||
unsigned int key_bitlen);
|
|
||||||
|
|
||||||
/** Allocate a new context */
|
|
||||||
void * (*ctx_alloc_func)( void );
|
|
||||||
|
|
||||||
/** Free the given context */
|
|
||||||
void (*ctx_free_func)( void *ctx );
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
mbedtls_cipher_type_t type;
|
|
||||||
const mbedtls_cipher_info_t *info;
|
|
||||||
} mbedtls_cipher_definition_t;
|
|
||||||
|
|
||||||
extern const mbedtls_cipher_definition_t mbedtls_cipher_definitions[];
|
|
||||||
|
|
||||||
extern int mbedtls_cipher_supported[];
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* MBEDTLS_CIPHER_WRAP_H */
|
|
|
@ -1,208 +0,0 @@
|
||||||
/**
|
|
||||||
* \file cmac.h
|
|
||||||
*
|
|
||||||
* \brief This file contains CMAC definitions and functions.
|
|
||||||
*
|
|
||||||
* The Cipher-based Message Authentication Code (CMAC) Mode for
|
|
||||||
* Authentication is defined in <em>RFC-4493: The AES-CMAC Algorithm</em>.
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* Copyright (C) 2015-2018, Arm Limited (or its affiliates), All Rights Reserved
|
|
||||||
* SPDX-License-Identifier: GPL-2.0
|
|
||||||
*
|
|
||||||
* This program 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 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*
|
|
||||||
* This file is part of Mbed TLS (https://tls.mbed.org)
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef MBEDTLS_CMAC_H
|
|
||||||
#define MBEDTLS_CMAC_H
|
|
||||||
|
|
||||||
#include "cipher.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define MBEDTLS_ERR_CMAC_HW_ACCEL_FAILED -0x007A /**< CMAC hardware accelerator failed. */
|
|
||||||
|
|
||||||
#define MBEDTLS_AES_BLOCK_SIZE 16
|
|
||||||
#define MBEDTLS_DES3_BLOCK_SIZE 8
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_AES_C)
|
|
||||||
#define MBEDTLS_CIPHER_BLKSIZE_MAX 16 /**< The longest block used by CMAC is that of AES. */
|
|
||||||
#else
|
|
||||||
#define MBEDTLS_CIPHER_BLKSIZE_MAX 8 /**< The longest block used by CMAC is that of 3DES. */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if !defined(MBEDTLS_CMAC_ALT)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The CMAC context structure.
|
|
||||||
*/
|
|
||||||
struct mbedtls_cmac_context_t
|
|
||||||
{
|
|
||||||
/** The internal state of the CMAC algorithm. */
|
|
||||||
unsigned char state[MBEDTLS_CIPHER_BLKSIZE_MAX];
|
|
||||||
|
|
||||||
/** Unprocessed data - either data that was not block aligned and is still
|
|
||||||
* pending processing, or the final block. */
|
|
||||||
unsigned char unprocessed_block[MBEDTLS_CIPHER_BLKSIZE_MAX];
|
|
||||||
|
|
||||||
/** The length of data pending processing. */
|
|
||||||
size_t unprocessed_len;
|
|
||||||
};
|
|
||||||
|
|
||||||
#else /* !MBEDTLS_CMAC_ALT */
|
|
||||||
#include "cmac_alt.h"
|
|
||||||
#endif /* !MBEDTLS_CMAC_ALT */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief This function sets the CMAC key, and prepares to authenticate
|
|
||||||
* the input data.
|
|
||||||
* Must be called with an initialized cipher context.
|
|
||||||
*
|
|
||||||
* \param ctx The cipher context used for the CMAC operation, initialized
|
|
||||||
* as one of the following types: MBEDTLS_CIPHER_AES_128_ECB,
|
|
||||||
* MBEDTLS_CIPHER_AES_192_ECB, MBEDTLS_CIPHER_AES_256_ECB,
|
|
||||||
* or MBEDTLS_CIPHER_DES_EDE3_ECB.
|
|
||||||
* \param key The CMAC key.
|
|
||||||
* \param keybits The length of the CMAC key in bits.
|
|
||||||
* Must be supported by the cipher.
|
|
||||||
*
|
|
||||||
* \return \c 0 on success.
|
|
||||||
* \return A cipher-specific error code on failure.
|
|
||||||
*/
|
|
||||||
int mbedtls_cipher_cmac_starts( mbedtls_cipher_context_t *ctx,
|
|
||||||
const unsigned char *key, size_t keybits );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief This function feeds an input buffer into an ongoing CMAC
|
|
||||||
* computation.
|
|
||||||
*
|
|
||||||
* It is called between mbedtls_cipher_cmac_starts() or
|
|
||||||
* mbedtls_cipher_cmac_reset(), and mbedtls_cipher_cmac_finish().
|
|
||||||
* Can be called repeatedly.
|
|
||||||
*
|
|
||||||
* \param ctx The cipher context used for the CMAC operation.
|
|
||||||
* \param input The buffer holding the input data.
|
|
||||||
* \param ilen The length of the input data.
|
|
||||||
*
|
|
||||||
* \return \c 0 on success.
|
|
||||||
* \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA
|
|
||||||
* if parameter verification fails.
|
|
||||||
*/
|
|
||||||
int mbedtls_cipher_cmac_update( mbedtls_cipher_context_t *ctx,
|
|
||||||
const unsigned char *input, size_t ilen );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief This function finishes the CMAC operation, and writes
|
|
||||||
* the result to the output buffer.
|
|
||||||
*
|
|
||||||
* It is called after mbedtls_cipher_cmac_update().
|
|
||||||
* It can be followed by mbedtls_cipher_cmac_reset() and
|
|
||||||
* mbedtls_cipher_cmac_update(), or mbedtls_cipher_free().
|
|
||||||
*
|
|
||||||
* \param ctx The cipher context used for the CMAC operation.
|
|
||||||
* \param output The output buffer for the CMAC checksum result.
|
|
||||||
*
|
|
||||||
* \return \c 0 on success.
|
|
||||||
* \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA
|
|
||||||
* if parameter verification fails.
|
|
||||||
*/
|
|
||||||
int mbedtls_cipher_cmac_finish( mbedtls_cipher_context_t *ctx,
|
|
||||||
unsigned char *output );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief This function prepares the authentication of another
|
|
||||||
* message with the same key as the previous CMAC
|
|
||||||
* operation.
|
|
||||||
*
|
|
||||||
* It is called after mbedtls_cipher_cmac_finish()
|
|
||||||
* and before mbedtls_cipher_cmac_update().
|
|
||||||
*
|
|
||||||
* \param ctx The cipher context used for the CMAC operation.
|
|
||||||
*
|
|
||||||
* \return \c 0 on success.
|
|
||||||
* \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA
|
|
||||||
* if parameter verification fails.
|
|
||||||
*/
|
|
||||||
int mbedtls_cipher_cmac_reset( mbedtls_cipher_context_t *ctx );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief This function calculates the full generic CMAC
|
|
||||||
* on the input buffer with the provided key.
|
|
||||||
*
|
|
||||||
* The function allocates the context, performs the
|
|
||||||
* calculation, and frees the context.
|
|
||||||
*
|
|
||||||
* The CMAC result is calculated as
|
|
||||||
* output = generic CMAC(cmac key, input buffer).
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* \param cipher_info The cipher information.
|
|
||||||
* \param key The CMAC key.
|
|
||||||
* \param keylen The length of the CMAC key in bits.
|
|
||||||
* \param input The buffer holding the input data.
|
|
||||||
* \param ilen The length of the input data.
|
|
||||||
* \param output The buffer for the generic CMAC result.
|
|
||||||
*
|
|
||||||
* \return \c 0 on success.
|
|
||||||
* \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA
|
|
||||||
* if parameter verification fails.
|
|
||||||
*/
|
|
||||||
int mbedtls_cipher_cmac( const mbedtls_cipher_info_t *cipher_info,
|
|
||||||
const unsigned char *key, size_t keylen,
|
|
||||||
const unsigned char *input, size_t ilen,
|
|
||||||
unsigned char *output );
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_AES_C)
|
|
||||||
/**
|
|
||||||
* \brief This function implements the AES-CMAC-PRF-128 pseudorandom
|
|
||||||
* function, as defined in
|
|
||||||
* <em>RFC-4615: The Advanced Encryption Standard-Cipher-based
|
|
||||||
* Message Authentication Code-Pseudo-Random Function-128
|
|
||||||
* (AES-CMAC-PRF-128) Algorithm for the Internet Key
|
|
||||||
* Exchange Protocol (IKE).</em>
|
|
||||||
*
|
|
||||||
* \param key The key to use.
|
|
||||||
* \param key_len The key length in Bytes.
|
|
||||||
* \param input The buffer holding the input data.
|
|
||||||
* \param in_len The length of the input data in Bytes.
|
|
||||||
* \param output The buffer holding the generated 16 Bytes of
|
|
||||||
* pseudorandom output.
|
|
||||||
*
|
|
||||||
* \return \c 0 on success.
|
|
||||||
*/
|
|
||||||
int mbedtls_aes_cmac_prf_128( const unsigned char *key, size_t key_len,
|
|
||||||
const unsigned char *input, size_t in_len,
|
|
||||||
unsigned char output[16] );
|
|
||||||
#endif /* MBEDTLS_AES_C */
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_SELF_TEST) && ( defined(MBEDTLS_AES_C) || defined(MBEDTLS_DES_C) )
|
|
||||||
/**
|
|
||||||
* \brief The CMAC checkup routine.
|
|
||||||
*
|
|
||||||
* \return \c 0 on success.
|
|
||||||
* \return \c 1 on failure.
|
|
||||||
*/
|
|
||||||
int mbedtls_cmac_self_test( int verbose );
|
|
||||||
#endif /* MBEDTLS_SELF_TEST && ( MBEDTLS_AES_C || MBEDTLS_DES_C ) */
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* MBEDTLS_CMAC_H */
|
|
|
@ -1,49 +0,0 @@
|
||||||
/**
|
|
||||||
* \file config.h
|
|
||||||
*
|
|
||||||
* \brief Configuration options (set of defines)
|
|
||||||
*
|
|
||||||
* This set of compile-time options may be used to enable
|
|
||||||
* or disable features selectively, and reduce the global
|
|
||||||
* memory footprint.
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* Copyright (C) 2006-2018, ARM Limited, All Rights Reserved
|
|
||||||
* SPDX-License-Identifier: GPL-2.0
|
|
||||||
*
|
|
||||||
* This program 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 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*
|
|
||||||
* This file is part of mbed TLS (https://tls.mbed.org)
|
|
||||||
*/
|
|
||||||
|
|
||||||
/////////////////////////////////////
|
|
||||||
// modified 13 nov 2018 by shchmue // -> pared down to essentials
|
|
||||||
/////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef MBEDTLS_CONFIG_H
|
|
||||||
#define MBEDTLS_CONFIG_H
|
|
||||||
|
|
||||||
#define MBEDTLS_HAVE_ASM
|
|
||||||
|
|
||||||
#define MBEDTLS_AES_C
|
|
||||||
|
|
||||||
#define MBEDTLS_CIPHER_C
|
|
||||||
#define MBEDTLS_CMAC_C
|
|
||||||
|
|
||||||
#define MBEDTLS_CIPHER_MODE_CTR
|
|
||||||
|
|
||||||
#include "check_config.h"
|
|
||||||
|
|
||||||
#endif /* MBEDTLS_CONFIG_H */
|
|
|
@ -1,64 +0,0 @@
|
||||||
/**
|
|
||||||
* \file platform_util.h
|
|
||||||
*
|
|
||||||
* \brief Common and shared functions used by multiple modules in the Mbed TLS
|
|
||||||
* library.
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* Copyright (C) 2018, Arm Limited, All Rights Reserved
|
|
||||||
* SPDX-License-Identifier: GPL-2.0
|
|
||||||
*
|
|
||||||
* This program 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 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*
|
|
||||||
* This file is part of Mbed TLS (https://tls.mbed.org)
|
|
||||||
*/
|
|
||||||
#ifndef MBEDTLS_PLATFORM_UTIL_H
|
|
||||||
#define MBEDTLS_PLATFORM_UTIL_H
|
|
||||||
|
|
||||||
#include <stddef.h>
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Securely zeroize a buffer
|
|
||||||
*
|
|
||||||
* The function is meant to wipe the data contained in a buffer so
|
|
||||||
* that it can no longer be recovered even if the program memory
|
|
||||||
* is later compromised. Call this function on sensitive data
|
|
||||||
* stored on the stack before returning from a function, and on
|
|
||||||
* sensitive data stored on the heap before freeing the heap
|
|
||||||
* object.
|
|
||||||
*
|
|
||||||
* It is extremely difficult to guarantee that calls to
|
|
||||||
* mbedtls_platform_zeroize() are not removed by aggressive
|
|
||||||
* compiler optimizations in a portable way. For this reason, Mbed
|
|
||||||
* TLS provides the configuration option
|
|
||||||
* MBEDTLS_PLATFORM_ZEROIZE_ALT, which allows users to configure
|
|
||||||
* mbedtls_platform_zeroize() to use a suitable implementation for
|
|
||||||
* their platform and needs
|
|
||||||
*
|
|
||||||
* \param buf Buffer to be zeroized
|
|
||||||
* \param len Length of the buffer in bytes
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void mbedtls_platform_zeroize( void *buf, size_t len );
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* MBEDTLS_PLATFORM_UTIL_H */
|
|
4
source/mbedtls/lib/.gitignore
vendored
4
source/mbedtls/lib/.gitignore
vendored
|
@ -1,4 +0,0 @@
|
||||||
*.o
|
|
||||||
libmbed*
|
|
||||||
*.sln
|
|
||||||
*.vcxproj
|
|
|
@ -1,181 +0,0 @@
|
||||||
option(USE_STATIC_MBEDTLS_LIBRARY "Build mbed TLS static library." ON)
|
|
||||||
option(USE_SHARED_MBEDTLS_LIBRARY "Build mbed TLS shared library." OFF)
|
|
||||||
option(LINK_WITH_PTHREAD "Explicitly link mbed TLS library to pthread." OFF)
|
|
||||||
|
|
||||||
set(src_crypto
|
|
||||||
aes.c
|
|
||||||
aesni.c
|
|
||||||
arc4.c
|
|
||||||
aria.c
|
|
||||||
asn1parse.c
|
|
||||||
asn1write.c
|
|
||||||
base64.c
|
|
||||||
bignum.c
|
|
||||||
blowfish.c
|
|
||||||
camellia.c
|
|
||||||
ccm.c
|
|
||||||
chacha20.c
|
|
||||||
chachapoly.c
|
|
||||||
cipher.c
|
|
||||||
cipher_wrap.c
|
|
||||||
cmac.c
|
|
||||||
ctr_drbg.c
|
|
||||||
des.c
|
|
||||||
dhm.c
|
|
||||||
ecdh.c
|
|
||||||
ecdsa.c
|
|
||||||
ecjpake.c
|
|
||||||
ecp.c
|
|
||||||
ecp_curves.c
|
|
||||||
entropy.c
|
|
||||||
entropy_poll.c
|
|
||||||
error.c
|
|
||||||
gcm.c
|
|
||||||
havege.c
|
|
||||||
hkdf.c
|
|
||||||
hmac_drbg.c
|
|
||||||
md.c
|
|
||||||
md2.c
|
|
||||||
md4.c
|
|
||||||
md5.c
|
|
||||||
md_wrap.c
|
|
||||||
memory_buffer_alloc.c
|
|
||||||
nist_kw.c
|
|
||||||
oid.c
|
|
||||||
padlock.c
|
|
||||||
pem.c
|
|
||||||
pk.c
|
|
||||||
pk_wrap.c
|
|
||||||
pkcs12.c
|
|
||||||
pkcs5.c
|
|
||||||
pkparse.c
|
|
||||||
pkwrite.c
|
|
||||||
platform.c
|
|
||||||
platform_util.c
|
|
||||||
poly1305.c
|
|
||||||
ripemd160.c
|
|
||||||
rsa.c
|
|
||||||
rsa_internal.c
|
|
||||||
sha1.c
|
|
||||||
sha256.c
|
|
||||||
sha512.c
|
|
||||||
threading.c
|
|
||||||
timing.c
|
|
||||||
version.c
|
|
||||||
version_features.c
|
|
||||||
xtea.c
|
|
||||||
)
|
|
||||||
|
|
||||||
set(src_x509
|
|
||||||
certs.c
|
|
||||||
pkcs11.c
|
|
||||||
x509.c
|
|
||||||
x509_create.c
|
|
||||||
x509_crl.c
|
|
||||||
x509_crt.c
|
|
||||||
x509_csr.c
|
|
||||||
x509write_crt.c
|
|
||||||
x509write_csr.c
|
|
||||||
)
|
|
||||||
|
|
||||||
set(src_tls
|
|
||||||
debug.c
|
|
||||||
net_sockets.c
|
|
||||||
ssl_cache.c
|
|
||||||
ssl_ciphersuites.c
|
|
||||||
ssl_cli.c
|
|
||||||
ssl_cookie.c
|
|
||||||
ssl_srv.c
|
|
||||||
ssl_ticket.c
|
|
||||||
ssl_tls.c
|
|
||||||
)
|
|
||||||
|
|
||||||
if(CMAKE_COMPILER_IS_GNUCC)
|
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-declarations -Wmissing-prototypes")
|
|
||||||
endif(CMAKE_COMPILER_IS_GNUCC)
|
|
||||||
|
|
||||||
if(CMAKE_COMPILER_IS_CLANG)
|
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-declarations -Wmissing-prototypes -Wdocumentation -Wno-documentation-deprecated-sync -Wunreachable-code")
|
|
||||||
endif(CMAKE_COMPILER_IS_CLANG)
|
|
||||||
|
|
||||||
if(WIN32)
|
|
||||||
set(libs ${libs} ws2_32)
|
|
||||||
endif(WIN32)
|
|
||||||
|
|
||||||
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
|
||||||
SET(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
|
|
||||||
SET(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
|
|
||||||
SET(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
|
|
||||||
SET(CMAKE_CXX_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(HAIKU)
|
|
||||||
set(libs ${libs} network)
|
|
||||||
endif(HAIKU)
|
|
||||||
|
|
||||||
if(USE_PKCS11_HELPER_LIBRARY)
|
|
||||||
set(libs ${libs} pkcs11-helper)
|
|
||||||
endif(USE_PKCS11_HELPER_LIBRARY)
|
|
||||||
|
|
||||||
if(ENABLE_ZLIB_SUPPORT)
|
|
||||||
set(libs ${libs} ${ZLIB_LIBRARIES})
|
|
||||||
endif(ENABLE_ZLIB_SUPPORT)
|
|
||||||
|
|
||||||
if(LINK_WITH_PTHREAD)
|
|
||||||
set(libs ${libs} pthread)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if (NOT USE_STATIC_MBEDTLS_LIBRARY AND NOT USE_SHARED_MBEDTLS_LIBRARY)
|
|
||||||
message(FATAL_ERROR "Need to choose static or shared mbedtls build!")
|
|
||||||
endif(NOT USE_STATIC_MBEDTLS_LIBRARY AND NOT USE_SHARED_MBEDTLS_LIBRARY)
|
|
||||||
|
|
||||||
if(USE_STATIC_MBEDTLS_LIBRARY AND USE_SHARED_MBEDTLS_LIBRARY)
|
|
||||||
set(mbedtls_static_target "mbedtls_static")
|
|
||||||
set(mbedx509_static_target "mbedx509_static")
|
|
||||||
set(mbedcrypto_static_target "mbedcrypto_static")
|
|
||||||
elseif(USE_STATIC_MBEDTLS_LIBRARY)
|
|
||||||
set(mbedtls_static_target "mbedtls")
|
|
||||||
set(mbedx509_static_target "mbedx509")
|
|
||||||
set(mbedcrypto_static_target "mbedcrypto")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(USE_STATIC_MBEDTLS_LIBRARY)
|
|
||||||
add_library(${mbedcrypto_static_target} STATIC ${src_crypto})
|
|
||||||
set_target_properties(${mbedcrypto_static_target} PROPERTIES OUTPUT_NAME mbedcrypto)
|
|
||||||
target_link_libraries(${mbedcrypto_static_target} ${libs})
|
|
||||||
|
|
||||||
add_library(${mbedx509_static_target} STATIC ${src_x509})
|
|
||||||
set_target_properties(${mbedx509_static_target} PROPERTIES OUTPUT_NAME mbedx509)
|
|
||||||
target_link_libraries(${mbedx509_static_target} ${libs} ${mbedcrypto_static_target})
|
|
||||||
|
|
||||||
add_library(${mbedtls_static_target} STATIC ${src_tls})
|
|
||||||
set_target_properties(${mbedtls_static_target} PROPERTIES OUTPUT_NAME mbedtls)
|
|
||||||
target_link_libraries(${mbedtls_static_target} ${libs} ${mbedx509_static_target})
|
|
||||||
|
|
||||||
install(TARGETS ${mbedtls_static_target} ${mbedx509_static_target} ${mbedcrypto_static_target}
|
|
||||||
DESTINATION ${LIB_INSTALL_DIR}
|
|
||||||
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
|
|
||||||
endif(USE_STATIC_MBEDTLS_LIBRARY)
|
|
||||||
|
|
||||||
if(USE_SHARED_MBEDTLS_LIBRARY)
|
|
||||||
add_library(mbedcrypto SHARED ${src_crypto})
|
|
||||||
set_target_properties(mbedcrypto PROPERTIES VERSION 2.13.0 SOVERSION 3)
|
|
||||||
target_link_libraries(mbedcrypto ${libs})
|
|
||||||
|
|
||||||
add_library(mbedx509 SHARED ${src_x509})
|
|
||||||
set_target_properties(mbedx509 PROPERTIES VERSION 2.13.0 SOVERSION 0)
|
|
||||||
target_link_libraries(mbedx509 ${libs} mbedcrypto)
|
|
||||||
|
|
||||||
add_library(mbedtls SHARED ${src_tls})
|
|
||||||
set_target_properties(mbedtls PROPERTIES VERSION 2.13.0 SOVERSION 12)
|
|
||||||
target_link_libraries(mbedtls ${libs} mbedx509)
|
|
||||||
|
|
||||||
install(TARGETS mbedtls mbedx509 mbedcrypto
|
|
||||||
DESTINATION ${LIB_INSTALL_DIR}
|
|
||||||
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
|
|
||||||
endif(USE_SHARED_MBEDTLS_LIBRARY)
|
|
||||||
|
|
||||||
add_custom_target(lib DEPENDS mbedcrypto mbedx509 mbedtls)
|
|
||||||
if(USE_STATIC_MBEDTLS_LIBRARY AND USE_SHARED_MBEDTLS_LIBRARY)
|
|
||||||
add_dependencies(lib mbedcrypto_static mbedx509_static mbedtls_static)
|
|
||||||
endif()
|
|
|
@ -1,46 +0,0 @@
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
.SUFFIXES:
|
|
||||||
#---------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
ifeq ($(strip $(DEVKITPRO)),)
|
|
||||||
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/devkitpro")
|
|
||||||
endif
|
|
||||||
|
|
||||||
TOPDIR ?= $(CURDIR)
|
|
||||||
include $(DEVKITPRO)/libnx/switch_rules
|
|
||||||
|
|
||||||
# Also see "include/mbedtls/config.h"
|
|
||||||
|
|
||||||
ARCH := -march=armv8-a+crypto -mtune=cortex-a57 -mtp=soft -fPIE
|
|
||||||
CFLAGS := -g -Wall -O3 -ffunction-sections $(ARCH) $(DEFINES)
|
|
||||||
CFLAGS += -I ../include -D__SWITCH__
|
|
||||||
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11
|
|
||||||
ASFLAGS := -g $(ARCH)
|
|
||||||
LDFLAGS ?= -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
|
|
||||||
|
|
||||||
|
|
||||||
OBJS_CRYPTO= aes.o cipher.o cipher_wrap.o \
|
|
||||||
cmac.o platform_util.o
|
|
||||||
|
|
||||||
.SILENT:
|
|
||||||
|
|
||||||
.PHONY: all static clean
|
|
||||||
|
|
||||||
all: static
|
|
||||||
|
|
||||||
static: libmbedcrypto.a
|
|
||||||
|
|
||||||
# crypto
|
|
||||||
libmbedcrypto.a: $(OBJS_CRYPTO)
|
|
||||||
echo " AR $@"
|
|
||||||
$(AR) -rc $@ $(OBJS_CRYPTO)
|
|
||||||
echo " RL $@"
|
|
||||||
$(AR) -s $@
|
|
||||||
|
|
||||||
|
|
||||||
.c.o:
|
|
||||||
echo " CC $<"
|
|
||||||
$(CC) $(CFLAGS) $(LDFLAGS) -c $<
|
|
||||||
|
|
||||||
clean:
|
|
||||||
rm -f *.o libmbed*
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -1,69 +0,0 @@
|
||||||
/*
|
|
||||||
* Common and shared functions used by multiple modules in the Mbed TLS
|
|
||||||
* library.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2018, Arm Limited, All Rights Reserved
|
|
||||||
* SPDX-License-Identifier: GPL-2.0
|
|
||||||
*
|
|
||||||
* This program 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 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*
|
|
||||||
* This file is part of Mbed TLS (https://tls.mbed.org)
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
|
||||||
#include "mbedtls/config.h"
|
|
||||||
#else
|
|
||||||
#include MBEDTLS_CONFIG_FILE
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "mbedtls/platform_util.h"
|
|
||||||
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#if !defined(MBEDTLS_PLATFORM_ZEROIZE_ALT)
|
|
||||||
/*
|
|
||||||
* This implementation should never be optimized out by the compiler
|
|
||||||
*
|
|
||||||
* This implementation for mbedtls_platform_zeroize() was inspired from Colin
|
|
||||||
* Percival's blog article at:
|
|
||||||
*
|
|
||||||
* http://www.daemonology.net/blog/2014-09-04-how-to-zero-a-buffer.html
|
|
||||||
*
|
|
||||||
* It uses a volatile function pointer to the standard memset(). Because the
|
|
||||||
* pointer is volatile the compiler expects it to change at
|
|
||||||
* any time and will not optimize out the call that could potentially perform
|
|
||||||
* other operations on the input buffer instead of just setting it to 0.
|
|
||||||
* Nevertheless, as pointed out by davidtgoldblatt on Hacker News
|
|
||||||
* (refer to http://www.daemonology.net/blog/2014-09-05-erratum.html for
|
|
||||||
* details), optimizations of the following form are still possible:
|
|
||||||
*
|
|
||||||
* if( memset_func != memset )
|
|
||||||
* memset_func( buf, 0, len );
|
|
||||||
*
|
|
||||||
* Note that it is extremely difficult to guarantee that
|
|
||||||
* mbedtls_platform_zeroize() will not be optimized out by aggressive compilers
|
|
||||||
* in a portable way. For this reason, Mbed TLS also provides the configuration
|
|
||||||
* option MBEDTLS_PLATFORM_ZEROIZE_ALT, which allows users to configure
|
|
||||||
* mbedtls_platform_zeroize() to use a suitable implementation for their
|
|
||||||
* platform and needs.
|
|
||||||
*/
|
|
||||||
static void * (* const volatile memset_func)( void *, int, size_t ) = memset;
|
|
||||||
|
|
||||||
void mbedtls_platform_zeroize( void *buf, size_t len )
|
|
||||||
{
|
|
||||||
memset_func( buf, 0, len );
|
|
||||||
}
|
|
||||||
#endif /* MBEDTLS_PLATFORM_ZEROIZE_ALT */
|
|
113
source/sha256.c
113
source/sha256.c
|
@ -1,113 +0,0 @@
|
||||||
/* Based on linux source code */
|
|
||||||
/*
|
|
||||||
* sha256_base.h - core logic for SHA-256 implementations
|
|
||||||
*
|
|
||||||
* Copyright (C) 2015 Linaro Ltd <ard.biesheuvel@linaro.org>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License version 2 as
|
|
||||||
* published by the Free Software Foundation.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
#include "sha256.h"
|
|
||||||
|
|
||||||
#define unlikely(x) __builtin_expect(!!(x), 0)
|
|
||||||
|
|
||||||
void sha256_block_data_order (uint32_t *ctx, const void *in, size_t num);
|
|
||||||
|
|
||||||
int sha256_init(struct sha256_state *sctx)
|
|
||||||
{
|
|
||||||
sctx->state[0] = SHA256_H0;
|
|
||||||
sctx->state[1] = SHA256_H1;
|
|
||||||
sctx->state[2] = SHA256_H2;
|
|
||||||
sctx->state[3] = SHA256_H3;
|
|
||||||
sctx->state[4] = SHA256_H4;
|
|
||||||
sctx->state[5] = SHA256_H5;
|
|
||||||
sctx->state[6] = SHA256_H6;
|
|
||||||
sctx->state[7] = SHA256_H7;
|
|
||||||
sctx->count = 0;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int sha256_update(struct sha256_state *sctx,
|
|
||||||
const void *data,
|
|
||||||
size_t len)
|
|
||||||
{
|
|
||||||
const u8 *data8 = (const u8 *)data;
|
|
||||||
unsigned int len32 = (unsigned int)len;
|
|
||||||
unsigned int partial = sctx->count % SHA256_BLOCK_SIZE;
|
|
||||||
|
|
||||||
sctx->count += len32;
|
|
||||||
|
|
||||||
if (unlikely((partial + len32) >= SHA256_BLOCK_SIZE)) {
|
|
||||||
int blocks;
|
|
||||||
|
|
||||||
if (partial) {
|
|
||||||
int p = SHA256_BLOCK_SIZE - partial;
|
|
||||||
|
|
||||||
memcpy(sctx->buf + partial, data8, p);
|
|
||||||
data8 += p;
|
|
||||||
len32 -= p;
|
|
||||||
|
|
||||||
sha256_block_data_order(sctx->state, sctx->buf, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
blocks = len32 / SHA256_BLOCK_SIZE;
|
|
||||||
len32 %= SHA256_BLOCK_SIZE;
|
|
||||||
|
|
||||||
if (blocks) {
|
|
||||||
sha256_block_data_order(sctx->state, data8, blocks);
|
|
||||||
data8 += blocks * SHA256_BLOCK_SIZE;
|
|
||||||
}
|
|
||||||
partial = 0;
|
|
||||||
}
|
|
||||||
if (len32)
|
|
||||||
memcpy(sctx->buf + partial, data8, len32);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int sha256_finalize(struct sha256_state *sctx)
|
|
||||||
{
|
|
||||||
const int bit_offset = SHA256_BLOCK_SIZE - sizeof(u64);
|
|
||||||
u64 *bits = (u64 *)(sctx->buf + bit_offset);
|
|
||||||
unsigned int partial = sctx->count % SHA256_BLOCK_SIZE;
|
|
||||||
|
|
||||||
sctx->buf[partial++] = 0x80;
|
|
||||||
if (partial > bit_offset) {
|
|
||||||
memset(sctx->buf + partial, 0x0, SHA256_BLOCK_SIZE - partial);
|
|
||||||
partial = 0;
|
|
||||||
|
|
||||||
sha256_block_data_order(sctx->state, sctx->buf, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
memset(sctx->buf + partial, 0x0, bit_offset - partial);
|
|
||||||
*bits = __builtin_bswap64(sctx->count << 3);
|
|
||||||
sha256_block_data_order(sctx->state, sctx->buf, 1);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int sha256_finish(struct sha256_state *sctx, void *out)
|
|
||||||
{
|
|
||||||
unsigned int digest_size = 32;
|
|
||||||
u32 *digest = (u32 *)out;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
// Switch: misalignment shouldn't be a problem here...
|
|
||||||
for (i = 0; digest_size > 0; i++, digest_size -= sizeof(u32))
|
|
||||||
*digest++ = __builtin_bswap32(sctx->state[i]);
|
|
||||||
|
|
||||||
*sctx = (struct sha256_state){};
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
|
@ -1,36 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
/* Based on linux source code */
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <switch/types.h>
|
|
||||||
|
|
||||||
#define SHA256_DIGEST_SIZE 32
|
|
||||||
#define SHA256_BLOCK_SIZE 64
|
|
||||||
|
|
||||||
#define SHA256_H0 0x6a09e667UL
|
|
||||||
#define SHA256_H1 0xbb67ae85UL
|
|
||||||
#define SHA256_H2 0x3c6ef372UL
|
|
||||||
#define SHA256_H3 0xa54ff53aUL
|
|
||||||
#define SHA256_H4 0x510e527fUL
|
|
||||||
#define SHA256_H5 0x9b05688cUL
|
|
||||||
#define SHA256_H6 0x1f83d9abUL
|
|
||||||
#define SHA256_H7 0x5be0cd19UL
|
|
||||||
|
|
||||||
struct sha256_state {
|
|
||||||
u32 state[SHA256_DIGEST_SIZE / 4];
|
|
||||||
u64 count;
|
|
||||||
u8 buf[SHA256_BLOCK_SIZE];
|
|
||||||
};
|
|
||||||
|
|
||||||
int sha256_init(struct sha256_state *sctx);
|
|
||||||
int sha256_update(struct sha256_state *sctx, const void *data, size_t len);
|
|
||||||
int sha256_finalize(struct sha256_state *sctx);
|
|
||||||
int sha256_finish(struct sha256_state *sctx, void *out);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
|
@ -1,163 +0,0 @@
|
||||||
.section .text.sha256_armv8, "ax", %progbits
|
|
||||||
.align 5
|
|
||||||
.arch armv8-a+crypto
|
|
||||||
|
|
||||||
# SHA256 assembly implementation for ARMv8 AArch64 (based on linux source code)
|
|
||||||
|
|
||||||
.global sha256_block_data_order
|
|
||||||
.type sha256_block_data_order,%function
|
|
||||||
sha256_block_data_order:
|
|
||||||
|
|
||||||
.Lsha256prolog:
|
|
||||||
|
|
||||||
stp x29, x30, [sp,#-64]!
|
|
||||||
mov x29, sp
|
|
||||||
adr x3, .LKConstant256
|
|
||||||
str q8, [sp, #16]
|
|
||||||
ld1 {v16.4s-v19.4s}, [x3], #64
|
|
||||||
ld1 {v0.4s}, [x0], #16
|
|
||||||
ld1 {v20.4s-v23.4s}, [x3], #64
|
|
||||||
add x2, x1, x2, lsl #6
|
|
||||||
ld1 {v1.4s}, [x0]
|
|
||||||
ld1 {v24.4s-v27.4s}, [x3], #64
|
|
||||||
sub x0, x0, #16
|
|
||||||
str q9, [sp, #32]
|
|
||||||
str q10, [sp, #48]
|
|
||||||
ld1 {v28.4s-v31.4s}, [x3], #64
|
|
||||||
|
|
||||||
.Lsha256loop:
|
|
||||||
|
|
||||||
ld1 {v5.16b-v8.16b}, [x1], #64
|
|
||||||
mov v2.16b, v0.16b
|
|
||||||
mov v3.16b, v1.16b
|
|
||||||
|
|
||||||
rev32 v5.16b, v5.16b
|
|
||||||
rev32 v6.16b, v6.16b
|
|
||||||
add v9.4s, v5.4s, v16.4s
|
|
||||||
rev32 v7.16b, v7.16b
|
|
||||||
add v10.4s, v6.4s, v17.4s
|
|
||||||
mov v4.16b, v2.16b
|
|
||||||
sha256h q2, q3, v9.4s
|
|
||||||
sha256h2 q3, q4, v9.4s
|
|
||||||
sha256su0 v5.4s, v6.4s
|
|
||||||
rev32 v8.16b, v8.16b
|
|
||||||
add v9.4s, v7.4s, v18.4s
|
|
||||||
mov v4.16b, v2.16b
|
|
||||||
sha256h q2, q3, v10.4s
|
|
||||||
sha256h2 q3, q4, v10.4s
|
|
||||||
sha256su0 v6.4s, v7.4s
|
|
||||||
sha256su1 v5.4s, v7.4s, v8.4s
|
|
||||||
add v10.4s, v8.4s, v19.4s
|
|
||||||
mov v4.16b, v2.16b
|
|
||||||
sha256h q2, q3, v9.4s
|
|
||||||
sha256h2 q3, q4, v9.4s
|
|
||||||
sha256su0 v7.4s, v8.4s
|
|
||||||
sha256su1 v6.4s, v8.4s, v5.4s
|
|
||||||
add v9.4s, v5.4s, v20.4s
|
|
||||||
mov v4.16b, v2.16b
|
|
||||||
sha256h q2, q3, v10.4s
|
|
||||||
sha256h2 q3, q4, v10.4s
|
|
||||||
sha256su0 v8.4s, v5.4s
|
|
||||||
sha256su1 v7.4s, v5.4s, v6.4s
|
|
||||||
add v10.4s, v6.4s, v21.4s
|
|
||||||
mov v4.16b, v2.16b
|
|
||||||
sha256h q2, q3, v9.4s
|
|
||||||
sha256h2 q3, q4, v9.4s
|
|
||||||
sha256su0 v5.4s, v6.4s
|
|
||||||
sha256su1 v8.4s, v6.4s, v7.4s
|
|
||||||
add v9.4s, v7.4s, v22.4s
|
|
||||||
mov v4.16b, v2.16b
|
|
||||||
sha256h q2, q3, v10.4s
|
|
||||||
sha256h2 q3, q4, v10.4s
|
|
||||||
sha256su0 v6.4s, v7.4s
|
|
||||||
sha256su1 v5.4s, v7.4s, v8.4s
|
|
||||||
add v10.4s, v8.4s, v23.4s
|
|
||||||
mov v4.16b, v2.16b
|
|
||||||
sha256h q2, q3, v9.4s
|
|
||||||
sha256h2 q3, q4, v9.4s
|
|
||||||
sha256su0 v7.4s, v8.4s
|
|
||||||
sha256su1 v6.4s, v8.4s, v5.4s
|
|
||||||
add v9.4s, v5.4s, v24.4s
|
|
||||||
mov v4.16b, v2.16b
|
|
||||||
sha256h q2, q3, v10.4s
|
|
||||||
sha256h2 q3, q4, v10.4s
|
|
||||||
sha256su0 v8.4s, v5.4s
|
|
||||||
sha256su1 v7.4s, v5.4s, v6.4s
|
|
||||||
add v10.4s, v6.4s, v25.4s
|
|
||||||
mov v4.16b, v2.16b
|
|
||||||
sha256h q2, q3, v9.4s
|
|
||||||
sha256h2 q3, q4, v9.4s
|
|
||||||
sha256su0 v5.4s, v6.4s
|
|
||||||
sha256su1 v8.4s, v6.4s, v7.4s
|
|
||||||
add v9.4s, v7.4s, v26.4s
|
|
||||||
mov v4.16b, v2.16b
|
|
||||||
sha256h q2, q3, v10.4s
|
|
||||||
sha256h2 q3, q4, v10.4s
|
|
||||||
sha256su0 v6.4s, v7.4s
|
|
||||||
sha256su1 v5.4s, v7.4s, v8.4s
|
|
||||||
add v10.4s, v8.4s, v27.4s
|
|
||||||
mov v4.16b, v2.16b
|
|
||||||
sha256h q2, q3, v9.4s
|
|
||||||
sha256h2 q3, q4, v9.4s
|
|
||||||
sha256su0 v7.4s, v8.4s
|
|
||||||
sha256su1 v6.4s, v8.4s, v5.4s
|
|
||||||
add v9.4s, v5.4s, v28.4s
|
|
||||||
mov v4.16b, v2.16b
|
|
||||||
sha256h q2, q3, v10.4s
|
|
||||||
sha256h2 q3, q4, v10.4s
|
|
||||||
sha256su0 v8.4s, v5.4s
|
|
||||||
sha256su1 v7.4s, v5.4s, v6.4s
|
|
||||||
add v10.4s, v6.4s, v29.4s
|
|
||||||
mov v4.16b, v2.16b
|
|
||||||
sha256h q2, q3, v9.4s
|
|
||||||
sha256h2 q3, q4, v9.4s
|
|
||||||
sha256su1 v8.4s, v6.4s, v7.4s
|
|
||||||
add v9.4s, v7.4s, v30.4s
|
|
||||||
mov v4.16b, v2.16b
|
|
||||||
sha256h q2, q3, v10.4s
|
|
||||||
sha256h2 q3, q4, v10.4s
|
|
||||||
add v10.4s, v8.4s, v31.4s
|
|
||||||
mov v4.16b, v2.16b
|
|
||||||
sha256h q2, q3, v9.4s
|
|
||||||
sha256h2 q3, q4, v9.4s
|
|
||||||
mov v4.16b, v2.16b
|
|
||||||
sha256h q2, q3, v10.4s
|
|
||||||
sha256h2 q3, q4, v10.4s
|
|
||||||
cmp x1, x2
|
|
||||||
add v1.4s, v1.4s, v3.4s
|
|
||||||
add v0.4s, v0.4s, v2.4s
|
|
||||||
b.ne .Lsha256loop
|
|
||||||
|
|
||||||
.Lsha256epilog:
|
|
||||||
|
|
||||||
st1 {v0.4s,v1.4s}, [x0]
|
|
||||||
ldr q10, [sp, #48]
|
|
||||||
ldr q9, [sp, #32]
|
|
||||||
ldr q8, [sp, #16]
|
|
||||||
ldr x29, [sp], #64
|
|
||||||
ret
|
|
||||||
|
|
||||||
.align 5
|
|
||||||
.LKConstant256:
|
|
||||||
.word 0x428a2f98,0x71374491,0xb5c0fbcf,0xe9b5dba5
|
|
||||||
.word 0x3956c25b,0x59f111f1,0x923f82a4,0xab1c5ed5
|
|
||||||
.word 0xd807aa98,0x12835b01,0x243185be,0x550c7dc3
|
|
||||||
.word 0x72be5d74,0x80deb1fe,0x9bdc06a7,0xc19bf174
|
|
||||||
.word 0xe49b69c1,0xefbe4786,0x0fc19dc6,0x240ca1cc
|
|
||||||
.word 0x2de92c6f,0x4a7484aa,0x5cb0a9dc,0x76f988da
|
|
||||||
.word 0x983e5152,0xa831c66d,0xb00327c8,0xbf597fc7
|
|
||||||
.word 0xc6e00bf3,0xd5a79147,0x06ca6351,0x14292967
|
|
||||||
.word 0x27b70a85,0x2e1b2138,0x4d2c6dfc,0x53380d13
|
|
||||||
.word 0x650a7354,0x766a0abb,0x81c2c92e,0x92722c85
|
|
||||||
.word 0xa2bfe8a1,0xa81a664b,0xc24b8b70,0xc76c51a3
|
|
||||||
.word 0xd192e819,0xd6990624,0xf40e3585,0x106aa070
|
|
||||||
.word 0x19a4c116,0x1e376c08,0x2748774c,0x34b0bcb5
|
|
||||||
.word 0x391c0cb3,0x4ed8aa4a,0x5b9cca4f,0x682e6ff3
|
|
||||||
.word 0x748f82ee,0x78a5636f,0x84c87814,0x8cc70208
|
|
||||||
.word 0x90befffa,0xa4506ceb,0xbef9a3f7,0xc67178f2
|
|
||||||
|
|
||||||
.size sha256_block_data_order,.-sha256_block_data_order
|
|
||||||
.align 2
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue