Skip to content

Commit

Permalink
working single / multi threaded ESP32 SSH server signature w/SHA256 HW
Browse files Browse the repository at this point in the history
  • Loading branch information
gojimmypi committed Feb 16, 2024
1 parent 1ab775d commit f2c97da
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/

// #define MY_ZERO_FORCE
#define MY_FIXED_VALUES
// #define MY_FIXED_VALUES
const char* newval = "";
const char* TAG = "ssh";
#ifdef HAVE_CONFIG_H
Expand Down Expand Up @@ -570,6 +570,10 @@ static HandshakeInfo* HandshakeInfoNew(void* heap)
newHs->dhGexMaxSz = WOLFSSH_DEFAULT_GEXDH_MAX;
#endif
}
else {
WLOG(WS_LOG_DEBUG, "HandshakeInfoNew: Failed to allocation %d bytes\n",
(int)sizeof(HandshakeInfo));
}

return newHs;
}
Expand Down Expand Up @@ -761,6 +765,7 @@ WOLFSSH* SshInit(WOLFSSH* ssh, WOLFSSH_CTX* ctx)
HandshakeInfo* handshake;
WC_RNG* rng;
void* heap;
int err;

WLOG(WS_LOG_DEBUG, "Entering SshInit()");

Expand All @@ -770,10 +775,16 @@ WOLFSSH* SshInit(WOLFSSH* ssh, WOLFSSH_CTX* ctx)

handshake = HandshakeInfoNew(heap);
rng = (WC_RNG*)WMALLOC(sizeof(WC_RNG), heap, DYNTYPE_RNG);
if (handshake == NULL || rng == NULL) {
WLOG(WS_LOG_DEBUG, "SshInit: Cannot allocate memory.\n");
}

if (handshake == NULL || rng == NULL || wc_InitRng(rng) != 0) {
err = wc_InitRng(rng);
if (err != 0) {
WLOG(WS_LOG_DEBUG, "SshInit: wc_InitRng failed. err = %d\n", err);
}

WLOG(WS_LOG_DEBUG, "SshInit: Cannot allocate memory.\n");
if (handshake == NULL || rng == NULL || err != 0) {
WFREE(handshake, heap, DYNTYPE_HS);
WFREE(rng, heap, DYNTYPE_RNG);
WFREE(ssh, heap, DYNTYPE_SSH);
Expand Down
8 changes: 8 additions & 0 deletions src/ssh.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
#include <wolfssl/wolfcrypt/error-crypt.h>
#include <wolfssl/wolfcrypt/random.h>

#ifdef DEBUG_WOLFSSL
#include <wolfssl/wolfcrypt/logging.h>
#endif

#ifdef NO_INLINE
#include <wolfssh/misc.h>
#else
Expand Down Expand Up @@ -154,6 +158,10 @@ WOLFSSH* wolfSSH_new(WOLFSSH_CTX* ctx)
}

ssh = (WOLFSSH*)WMALLOC(sizeof(WOLFSSH), heap, DYNTYPE_SSH);
if (ssh == NULL) {
WOLFSSL_MSG_EX("wolfSSH_new failed to allocate %d bytes.",
(int)sizeof(WOLFSSH));
}
ssh = SshInit(ssh, ctx);

WLOG(WS_LOG_DEBUG, "Leaving wolfSSH_new(), ssh = %p", ssh);
Expand Down

0 comments on commit f2c97da

Please sign in to comment.