Start optionally using the SHA implementation from the existing crypto API #44

Merged
jordan merged 5 commits from lda/Cytoplasm:opt-ssl-for-sha into master 2024-08-24 17:06:05 +00:00
2 changed files with 46 additions and 1 deletions

View file

@ -28,6 +28,27 @@
#include <limits.h>
/* TODO: Verify LibreSSL support later */
lda marked this conversation as resolved Outdated

If you just say #if (TLS_IMPL == TLS_OPENSSL) and get rid of the LibreSSL check, then this will only be applied with OpenSSL, which you verified to work. We can then merge this and add back LibreSSL support later after we verify it is working.

If you just say `#if (TLS_IMPL == TLS_OPENSSL)` and get rid of the LibreSSL check, then this will only be applied with OpenSSL, which you verified to work. We can then merge this and add back LibreSSL support later after we verify it is working.
#if TLS_IMPL == TLS_OPENSSL
#include <openssl/sha.h>
unsigned char *
Sha1(char *str)
{
unsigned char *digest;
if (!str)
{
return NULL;
}
digest = Malloc(20 + 1);
SHA1((unsigned char *) str, strlen(str), digest);
digest[20] = '\0';
return digest;
}
#else
#define LOAD32H(x, y) \
{ \
x = ((uint32_t)((y)[0] & 255) << 24) | \
@ -264,3 +285,4 @@ Sha1(char *str)
return out;
}
#endif

View file

@ -21,14 +21,36 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include <Sha.h>
#include <Memory.h>
#include <Sha.h>
#include <stdio.h>
#include <string.h>
#include <limits.h>
/* TODO: Verify LibreSSL support later */
#if TLS_IMPL == TLS_OPENSSL
#include <openssl/sha.h>
unsigned char *
Sha256(char *str)
{
unsigned char *digest;
if (!str)
{
return NULL;
}
digest = Malloc(32 + 1);
SHA256((unsigned char *) str, strlen(str), digest);
digest[32] = '\0';
return digest;
}
#else
#define GET_UINT32(x) \
(((uint32_t)(x)[0] << 24) | \
((uint32_t)(x)[1] << 16) | \
@ -230,3 +252,4 @@ Sha256(char *str)
return out;
}
#endif