-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
78 additions
and
30 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 |
---|---|---|
|
@@ -7,3 +7,4 @@ | |
ifeq ($(USE_OPENSSL),) | ||
SRCS += sha/sha1.c | ||
endif | ||
SRCS += sha/wrap.c |
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,26 @@ | ||
/** | ||
* @file re_sha.h Interface to SHA (Secure Hash Standard) functions | ||
* | ||
* Copyright (C) 2010 Creytiv.com | ||
*/ | ||
|
||
/* this file is in the public domain */ | ||
|
||
/** SHA-1 Context */ | ||
typedef struct { | ||
uint32_t state[5]; /**< Context state */ | ||
uint32_t count[2]; /**< Counter */ | ||
uint8_t buffer[64]; /**< SHA-1 buffer */ | ||
} SHA1_CTX; | ||
|
||
/** SHA-1 Context (OpenSSL compat) */ | ||
typedef SHA1_CTX SHA_CTX; | ||
|
||
/** SHA-1 Digest size in bytes */ | ||
#define SHA1_DIGEST_SIZE 20 | ||
/** SHA-1 Digest size in bytes (OpenSSL compat) */ | ||
#define SHA_DIGEST_LENGTH SHA1_DIGEST_SIZE | ||
|
||
void SHA1_Init(SHA1_CTX* context); | ||
void SHA1_Update(SHA1_CTX* context, const void *p, size_t len); | ||
void SHA1_Final(uint8_t digest[SHA1_DIGEST_SIZE], SHA1_CTX* context); |
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,33 @@ | ||
/** | ||
* @file wrap.c SHA wrappers | ||
* | ||
* Copyright (C) 2022 Sebastian Reimers <hallo@studio-link.de> | ||
*/ | ||
|
||
#include <re_types.h> | ||
#ifdef USE_OPENSSL | ||
#include <openssl/sha.h> | ||
#else | ||
#include "sha.h" | ||
#endif | ||
#include <re_sha.h> | ||
|
||
|
||
/** | ||
* Calculate the SHA1 hash from a buffer | ||
* | ||
* @param d Data buffer (input) | ||
* @param n Number of input bytes | ||
* @param md Calculated SHA1 hash (output) | ||
*/ | ||
void sha1(const uint8_t *d, size_t n, uint8_t *md) | ||
{ | ||
#ifdef USE_OPENSSL | ||
(void)SHA1(d, n, md); | ||
#else | ||
SHA_CTX ctx; | ||
SHA1_Init(&ctx); | ||
SHA1_Update(&ctx, d, n); | ||
SHA1_Final(md, &ctx); | ||
#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