mirror of
https://github.com/libssh2/libssh2.git
synced 2025-11-20 02:42:09 +03:00
Abstracted OpenSSL calls out of hostkey.c (#294)
This commit is contained in:
@@ -184,9 +184,15 @@ _libssh2_ed25519_verify(libssh2_ed25519_ctx *ctx, const uint8_t *s,
|
|||||||
size_t s_len, const uint8_t *m, size_t m_len);
|
size_t s_len, const uint8_t *m, size_t m_len);
|
||||||
|
|
||||||
int
|
int
|
||||||
_libssh2_ed25519_new_private(libssh2_ed25519_ctx **ec_ctx,
|
_libssh2_ed25519_new_private(libssh2_ed25519_ctx **ed_ctx,
|
||||||
LIBSSH2_SESSION *session,
|
LIBSSH2_SESSION *session,
|
||||||
const char *filename, const uint8_t *passphrase);
|
const char *filename, const uint8_t *passphrase);
|
||||||
|
|
||||||
|
int
|
||||||
|
_libssh2_ed25519_new_public(libssh2_ed25519_ctx **ed_ctx,
|
||||||
|
LIBSSH2_SESSION *session,
|
||||||
|
const char *raw_pub_key, const uint8_t key_len);
|
||||||
|
|
||||||
int
|
int
|
||||||
_libssh2_ed25519_sign(libssh2_ed25519_ctx *ctx, LIBSSH2_SESSION *session,
|
_libssh2_ed25519_sign(libssh2_ed25519_ctx *ctx, LIBSSH2_SESSION *session,
|
||||||
uint8_t **out_sig, size_t *out_sig_len,
|
uint8_t **out_sig, size_t *out_sig_len,
|
||||||
|
|||||||
@@ -795,9 +795,8 @@ hostkey_method_ssh_ed25519_init(LIBSSH2_SESSION * session,
|
|||||||
size_t hostkey_data_len,
|
size_t hostkey_data_len,
|
||||||
void **abstract)
|
void **abstract)
|
||||||
{
|
{
|
||||||
const unsigned char *s;
|
const char *s;
|
||||||
unsigned long len, key_len;
|
unsigned long len, key_len;
|
||||||
EVP_PKEY *public_key = NULL;
|
|
||||||
libssh2_ed25519_ctx *ctx = NULL;
|
libssh2_ed25519_ctx *ctx = NULL;
|
||||||
|
|
||||||
if(*abstract) {
|
if(*abstract) {
|
||||||
@@ -823,17 +822,10 @@ hostkey_method_ssh_ed25519_init(LIBSSH2_SESSION * session,
|
|||||||
key_len = _libssh2_ntohu32(s);
|
key_len = _libssh2_ntohu32(s);
|
||||||
s += 4;
|
s += 4;
|
||||||
|
|
||||||
public_key = EVP_PKEY_new_raw_public_key(EVP_PKEY_ED25519, NULL, (const unsigned char*)s, key_len);
|
if(_libssh2_ed25519_new_public(&ctx, session, s, key_len) != 0) {
|
||||||
if(public_key == NULL) {
|
return -1;
|
||||||
return _libssh2_error(session, LIBSSH2_ERROR_PROTO, "could not create ED25519 public key");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx = _libssh2_ed25519_new_ctx();
|
|
||||||
if(ctx == NULL) {
|
|
||||||
return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, "could not alloc public/private key");
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx->public_key = public_key;
|
|
||||||
*abstract = ctx;
|
*abstract = ctx;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -1774,6 +1774,37 @@ _libssh2_ed25519_new_private_frommemory(libssh2_ed25519_ctx ** ed_ctx,
|
|||||||
filedata, filedata_len, passphrase);
|
filedata, filedata_len, passphrase);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
_libssh2_ed25519_new_public(libssh2_ed25519_ctx ** ed_ctx,
|
||||||
|
LIBSSH2_SESSION * session,
|
||||||
|
const char *raw_pub_key, const uint8_t key_len)
|
||||||
|
{
|
||||||
|
libssh2_ed25519_ctx *ctx = NULL;
|
||||||
|
EVP_PKEY *public_key = NULL;
|
||||||
|
|
||||||
|
if(ed_ctx == NULL)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
public_key = EVP_PKEY_new_raw_public_key(EVP_PKEY_ED25519, NULL, (const unsigned char*)raw_pub_key, key_len);
|
||||||
|
if(public_key == NULL) {
|
||||||
|
return _libssh2_error(session, LIBSSH2_ERROR_PROTO, "could not create ED25519 public key");
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx = _libssh2_ed25519_new_ctx();
|
||||||
|
if(ctx == NULL) {
|
||||||
|
return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, "could not alloc public/private key");
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx->public_key = public_key;
|
||||||
|
|
||||||
|
if(ed_ctx != NULL)
|
||||||
|
*ed_ctx = ctx;
|
||||||
|
else if(ctx != NULL)
|
||||||
|
_libssh2_ed25519_free(ctx);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* LIBSSH2_ED25519 */
|
#endif /* LIBSSH2_ED25519 */
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|||||||
Reference in New Issue
Block a user