-
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 #22 from atsign-foundation/jeremy-changes
feat: sha library & small changes
- Loading branch information
Showing
11 changed files
with
116 additions
and
66 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,22 @@ | ||
#pragma once | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
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(const char *input, size_t inputlen, unsigned char **output, atchops_md_type mdtype); | ||
|
||
#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
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,43 @@ | ||
#include <stdlib.h> | ||
#include <mbedtls/md.h> | ||
#include <mbedtls/md5.h> | ||
#include "at_chops/sha.h" | ||
|
||
int atchops_sha_hash(const char *input, size_t inputlen, unsigned char **output, atchops_md_type mdtype) | ||
{ | ||
int ret = 1; | ||
|
||
mbedtls_md_context_t md_ctx; | ||
mbedtls_md_init(&md_ctx); | ||
|
||
mbedtls_md_type_t md_type = mdtype; // TODO dynamic | ||
|
||
ret = mbedtls_md_setup(&md_ctx, mbedtls_md_info_from_type(md_type), 0); | ||
if (ret != 0) | ||
goto ret; | ||
|
||
ret = mbedtls_md_starts(&md_ctx); | ||
if (ret != 0) | ||
goto ret; | ||
|
||
ret = mbedtls_md_update(&md_ctx, input, inputlen); | ||
if (ret != 0) | ||
goto ret; | ||
|
||
const size_t hashlen = mbedtls_md_get_size(mbedtls_md_info_from_type(md_type)); | ||
// printf("hashlen: %lu\n", hashlen); | ||
unsigned char *hash = malloc(sizeof(unsigned char) * hashlen); | ||
|
||
*output = hash; | ||
|
||
ret = mbedtls_md_finish(&md_ctx, hash); | ||
if (ret != 0) | ||
goto ret; | ||
|
||
mbedtls_md_free(&md_ctx); | ||
|
||
goto ret; | ||
ret: { | ||
return ret; | ||
} | ||
} |
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