-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from atsign-foundation/jeremy-refactor
feat: atchops refactor, ESP-IDF build static libraries, ESP-IDF project examples, repl example, lots of docs
- Loading branch information
Showing
102 changed files
with
2,490 additions
and
1,271 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
cmake_minimum_required(VERSION 3.19) | ||
|
||
set(EXTRA_COMPONENT_DIRS | ||
${CMAKE_SOURCE_DIR}/../../packages/atclient # match this to be the path to the root CMakeLists.txt of atclient package | ||
${CMAKE_SOURCE_DIR}/../../packages/atchops # match this to be the path to the root CMakeLists.txt of atchops package | ||
) | ||
|
||
include($ENV{IDF_PATH}/tools/cmake/project.cmake) | ||
|
||
project(atclient_esp32_source) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# atclient_esp32_source | ||
|
||
This example shows you how to use atclient/atchops in your own ESP-IDF project by providing the path to the source code. | ||
|
||
## How to Consume Via Source Code | ||
|
||
In `make/CMakeLists.txt`, be sure to add the atclient and atchops components to the REQUIRES list: | ||
|
||
```cmake | ||
idf_component_register( | ||
SRCS "main.c" | ||
REQUIRES mbedtls atclient atchops | ||
) | ||
``` | ||
|
||
In `./CMakeLists.txt`, add the path to the atclient and atchops source code via the EXTRA_COMPONENT_DIRS variable: | ||
|
||
```cmake | ||
set(EXTRA_COMPONENT_DIRS | ||
${CMAKE_SOURCE_DIR}/../../packages/atclient # match this to be the path to the root CMakeLists.txt of atclient package | ||
${CMAKE_SOURCE_DIR}/../../packages/atchops # match this to be the path to the root CMakeLists.txt of atchops package | ||
) | ||
``` | ||
|
||
## Running the Example | ||
|
||
To run the example, you will need the ESP-IDF toolchain installed. See [ESP-IDF's Getting Started Guide](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/index.html) for more information. Ensure that your ESP32 is plugged into your computer with a micro USB data cable. | ||
|
||
Running the example via `get_idf && idf.py build && idf.py flash monitor` will give you something similar to: | ||
|
||
```sh | ||
atchops_base64_encode: 0 | ||
src: Lemonade! | ||
dst: TGVtb25hZGUh | ||
dst bytes: | ||
54 47 56 74 62 32 35 68 5a 47 55 68 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma once | ||
|
||
typedef enum AESKeySize { | ||
AES_128 = 128, // not tested | ||
AES_192 = 192, // not tested | ||
AES_256 = 256, | ||
} AESKeySize; | ||
|
||
int atchops_aes_ctr_encrypt( | ||
const char *keybase64, | ||
const unsigned long keybase64len, | ||
const AESKeySize keybits, | ||
const unsigned char *iv, | ||
const unsigned long ivlen, | ||
const unsigned char *plaintext, | ||
const unsigned long plaintextlen, | ||
unsigned char *ciphertextbase64, | ||
const unsigned long ciphertextbase64len, | ||
unsigned long *ciphertextbase64olen); | ||
|
||
int atchops_aes_ctr_decrypt( | ||
const char *keybase64, | ||
const unsigned long keybase64len, | ||
const AESKeySize keybits, | ||
const unsigned char *iv, | ||
const unsigned long ivlen, | ||
const unsigned char *ciphertextbase64, | ||
const unsigned long ciphertextbase64len, | ||
unsigned char *plaintext, | ||
const unsigned long plaintextlen, | ||
unsigned long *plaintextolen); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#pragma once | ||
|
||
/** | ||
* @brief Base64 encode some bytes | ||
* | ||
* @param src src bytes that you want to encode | ||
* @param srclen the length of the src bytes | ||
* @param dst the buffer where the base64 encoded result will be | ||
* @param dstlen the buffer length | ||
* @param writtenlen the length of the result after operation | ||
* @return int 0 on success | ||
*/ | ||
int atchops_base64_encode(const unsigned char *src, const unsigned long srclen, unsigned char *dst, unsigned long dstlen, unsigned long *writtenlen); | ||
|
||
/** | ||
* @brief Base64 decode some bytes | ||
* | ||
* @param src src bytes that you want to decode | ||
* @param srclen the length of the src bytes | ||
* @param dst the buffer where the base64 decoded result will be | ||
* @param dstlen the buffer length | ||
* @param writtenlen the length of the result after operation | ||
* @return int 0 on success | ||
*/ | ||
int atchops_base64_decode(const unsigned char *src, const unsigned long srclen, unsigned char *dst, unsigned long dstlen, unsigned long *writtenlen); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#pragma once | ||
|
||
#include "sha.h" | ||
|
||
typedef struct rsa_param | ||
{ | ||
unsigned long len; // length of the number in bytes | ||
unsigned char *value; // hex byte array of the number | ||
} rsa_param; | ||
|
||
typedef struct atchops_rsa_publickey | ||
{ | ||
rsa_param n; // modulus | ||
rsa_param e; // public exponent | ||
} atchops_rsa_publickey; | ||
|
||
typedef struct atchops_rsa_privatekey | ||
{ | ||
rsa_param n; // modulus | ||
rsa_param e; // public exponent | ||
rsa_param d; // private exponent | ||
rsa_param p; // prime 1 | ||
rsa_param q; // prime 2 | ||
} atchops_rsa_privatekey; | ||
|
||
/** | ||
* @brief Populate a public key struct from a base64 string | ||
* | ||
* @param publickeybase64 a base64 string representing an RSA 2048 Public Key | ||
* @param publickeybase64len the length of the base64 string | ||
* @param publickeystruct the public key struct to populate | ||
* @return int 0 on success | ||
*/ | ||
int atchops_rsa_populate_publickey(const char *publickeybase64, const unsigned long publickeybase64len, atchops_rsa_publickey *publickeystruct); | ||
|
||
/** | ||
* @brief Populate a private key struct from a base64 string | ||
* | ||
* @param privatekeybase64 the base64 string representing an RSA 2048 Private Key | ||
* @param privatekeybase64len the length of the base64 string | ||
* @param privatekeystruct the private key struct to populate | ||
* @return int 0 on success | ||
*/ | ||
int atchops_rsa_populate_privatekey(const char *privatekeybase64, const unsigned long privatekeybase64len, atchops_rsa_privatekey *privatekeystruct); | ||
|
||
/** | ||
* @brief Sign a message with an RSA private key | ||
* | ||
* @param privatekeystruct the private key struct to use for signing, see atchops_rsa_populate_privatekey | ||
* @param mdtype the hash type to use, see atchops_md_type, e.g. ATCHOPS_MD_SHA256 | ||
* @param message the message to sign | ||
* @param messagelen the length of the message, most people use strlen() to find this length | ||
* @param signature the signature buffer to populate | ||
* @param signaturelen the length of the signature buffer | ||
* @param signatureolen the length of the signature buffer after signing | ||
* @return int 0 on success | ||
*/ | ||
int atchops_rsa_sign(atchops_rsa_privatekey privatekeystruct, atchops_md_type mdtype, const unsigned char *message, const unsigned long messagelen, unsigned char *signature, const unsigned long signaturelen, unsigned long *signatureolen); | ||
|
||
/** | ||
* @brief Encrypt bytes with an RSA public key | ||
* | ||
* @param publickeystruct the public key struct to use for encryption, see atchops_rsa_populate_publickey | ||
* @param plaintext the plaintext to encrypt | ||
* @param plaintextlen the length of the plaintext, most people use strlen() to find this length | ||
* @param ciphertext the ciphertext buffer to populate | ||
* @param ciphertextlen the length of the ciphertext buffer | ||
* @param ciphertextolen the length of the ciphertext buffer after encryption | ||
* @return int 0 on success | ||
*/ | ||
int atchops_rsa_encrypt(atchops_rsa_publickey publickeystruct, const unsigned char *plaintext, const unsigned long plaintextlen, unsigned char *ciphertext, const unsigned long ciphertextlen, unsigned long *ciphertextolen); | ||
|
||
/** | ||
* @brief Decrypt bytes with an RSA private key | ||
* | ||
* @param privatekeystruct the private key struct to use for decryption, see atchops_rsa_populate_privatekey | ||
* @param ciphertextbase64 the ciphertext to decrypt, base64 encoded | ||
* @param ciphertextbase64len the length of the ciphertext, most people use strlen() to find this length | ||
* @param plaintext the plaintext buffer to populate | ||
* @param plaintextlen the length of the plaintext buffer | ||
* @param plaintextolen the length of the plaintext buffer after decryption | ||
* @return int 0 on success | ||
*/ | ||
int atchops_rsa_decrypt(atchops_rsa_privatekey privatekeystruct, const unsigned char *ciphertextbase64, const unsigned long ciphertextbase64len, unsigned char *plaintext, const unsigned long plaintextlen, unsigned long *plaintextolen); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#pragma once | ||
|
||
typedef enum { | ||
ATCHOPS_MD_NONE=0, /**< None. */ | ||
ATCHOPS_MD_MD5, /**< The MD5 message digest. */ | ||
ATCHOPS_MD_SHA1, /**< The SHA-1 message digest. */ | ||
ATCHOPS_MD_SHA224, /**< The SHA-224 message digest. */ | ||
ATCHOPS_MD_SHA256, /**< The SHA-256 message digest. */ | ||
ATCHOPS_MD_SHA384, /**< The SHA-384 message digest. */ | ||
ATCHOPS_MD_SHA512, /**< The SHA-512 message digest. */ | ||
ATCHOPS_MD_RIPEMD160, | ||
} atchops_md_type; | ||
|
||
int atchops_sha_hash(atchops_md_type mdtype, const unsigned char *input, const unsigned long inputlen, unsigned char *output, unsigned long outputlen, unsigned long *outputolen); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#ifndef ATLOGGER_H | ||
#define ATLOGGER_H | ||
|
||
#include <stddef.h> | ||
|
||
int atlogger_log(const char *title, const char *message); | ||
int atlogger_logx(const char *title, const unsigned char *bytes, size_t byteslen); | ||
|
||
#endif // ATLOGGER_H |
Oops, something went wrong.