-
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 #9 from atsign-foundation/jeremy-rsa2048
feat: RSA MVP
- Loading branch information
Showing
20 changed files
with
1,091 additions
and
33 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
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
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,13 @@ | ||
#pragma once | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
void printx(unsigned char *data, size_t len); | ||
|
||
void copy(unsigned char *dst, unsigned char *src, size_t len); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#pragma once | ||
|
||
#ifdef BUILD_MBEDTLS | ||
#ifdef __cplusplus | ||
extern "C" | ||
{ | ||
#endif | ||
|
||
#include <ctype.h> | ||
|
||
typedef struct rsa_param { | ||
size_t len; | ||
unsigned char *value; // hex byte array of the number | ||
} rsa_param; | ||
|
||
typedef struct { | ||
rsa_param n_param; // modulus | ||
rsa_param e_param; // public exponent | ||
} atchops_rsa2048_publickey; | ||
|
||
typedef struct { | ||
rsa_param n_param; // modulus | ||
rsa_param e_param; // public exponent | ||
rsa_param d_param; // private exponent | ||
rsa_param p_param; // prime 1 | ||
rsa_param q_param; // prime 2 | ||
} atchops_rsa2048_privatekey; | ||
|
||
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; | ||
|
||
/** | ||
* @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 size_t publickeybase64len, atchops_rsa2048_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 size_t privatekeybase64len, atchops_rsa2048_privatekey *privatekeystruct); | ||
|
||
/** | ||
* @brief Sign a message with an RSA 2048 Private Key | ||
* | ||
* @param privatekeystruct the private key struct to use for signing | ||
* @param mdtype the message digest type to use | ||
* @param signature the signature to populate. Pass in a pointer to a pointer to an unsigned char array. The pointer will be reassigned to the newly allocated array. | ||
* @param signaturelen the output length of the signature | ||
* @param message the message to sign | ||
* @param messagelen the length of the message | ||
* @return int 0 on success | ||
*/ | ||
int atchops_rsa_sign(atchops_rsa2048_privatekey privatekeystruct, atchops_md_type mdtype, unsigned char **signature, size_t *signaturelen, const unsigned char *message, const size_t messagelen); | ||
|
||
// todo | ||
// int atchops_rsa2048_verify(atchops_rsa2048_publickey *publickeystruct, const unsigned char *signature, const size_t signaturelen, ); | ||
|
||
// todo comments | ||
int atchops_rsa_encrypt(atchops_rsa2048_publickey publickeystruct, const char *plaintext, const size_t plaintextlen, char **ciphertext, size_t *ciphertextolen); | ||
|
||
// todo comments | ||
int atchops_rsa_decrypt(atchops_rsa2048_privatekey privatekeystruct, const char *ciphertextbase64encoded, const size_t ciphertextbase64encodedlen, char **plaintext, size_t *plaintextolen); | ||
#ifdef __cplusplus | ||
} | ||
#endif | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
# python3 tool.py -p desktop -f mbedtls clean | ||
python3 tool.py -p desktop -f mbedtls build | ||
python3 tool.py -p desktop -f mbedtls test |
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,31 @@ | ||
|
||
#ifdef __cplusplus | ||
extern "C" | ||
{ | ||
#endif | ||
|
||
#include <stdio.h> | ||
#include "byteutil.h" | ||
|
||
void printx(unsigned char *data, size_t len) | ||
{ | ||
// TODO check len here, error handle return an int | ||
for (size_t i = 0; i < len; i++) | ||
{ | ||
printf("%02x ", data[i]); | ||
} | ||
printf("\n"); | ||
} | ||
|
||
void copy(unsigned char *dst, unsigned char *src, size_t len) | ||
{ | ||
// TODO: check len here, error handle return an int | ||
for (size_t i = 0; i < len; i++) | ||
{ | ||
dst[i] = src[i]; | ||
} | ||
} | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
Oops, something went wrong.