/* * hostkey_method_ssh_ed25519_init * * Initialize the server hostkey working area with e/n pair */ static int hostkey_method_ssh_ed25519_init(LIBSSH2_SESSION * session, const unsigned char *hostkey_data, size_t hostkey_data_len, void **abstract) { const unsigned char *s; unsigned long len, key_len; EVP_PKEY *public_key = NULL; libssh2_ed25519_ctx *ctx = NULL; if(*abstract) { hostkey_method_ssh_ed25519_dtor(session, abstract); *abstract = NULL; } if(hostkey_data_len < 15) { return -1; } s = hostkey_data; len = _libssh2_ntohu32(s); s += 4; if(len != 11 || strncmp((char *) s, "ssh-ed25519", 11) != 0) { return -1; } s += 11; //public key key_len = _libssh2_ntohu32(s); s += 4; public_key = EVP_PKEY_new_raw_public_key(EVP_PKEY_ED25519, NULL, (const unsigned char*)s, key_len); if(public_key == NULL) { return _libssh2_error(session, LIBSSH2_ERROR_PROTO, "could not create ED25519 public key"); } ctx = LIBSSH2_CALLOC(session, sizeof(libssh2_ed25519_ctx)); if(ctx == NULL) { return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, "could not alloc public/private key"); } ctx->public_key = public_key; *abstract = ctx; return 0; }
static int test_set_get_raw_keys_int(int tst, int pub) { int ret = 0; unsigned char buf[80]; unsigned char *in; size_t inlen, len = 0; EVP_PKEY *pkey; /* Check if this algorithm supports public keys */ if (keys[tst].pub == NULL) return 1; memset(buf, 0, sizeof(buf)); if (pub) { inlen = strlen(keys[tst].pub); in = (unsigned char *)keys[tst].pub; pkey = EVP_PKEY_new_raw_public_key(keys[tst].type, NULL, in, inlen); } else { inlen = strlen(keys[tst].priv); in = (unsigned char *)keys[tst].priv; pkey = EVP_PKEY_new_raw_private_key(keys[tst].type, NULL, in, inlen); } if (!TEST_ptr(pkey) || (!pub && !TEST_true(EVP_PKEY_get_raw_private_key(pkey, NULL, &len))) || (pub && !TEST_true(EVP_PKEY_get_raw_public_key(pkey, NULL, &len))) || !TEST_true(len == inlen) || (!pub && !TEST_true(EVP_PKEY_get_raw_private_key(pkey, buf, &len))) || (pub && !TEST_true(EVP_PKEY_get_raw_public_key(pkey, buf, &len))) || !TEST_mem_eq(in, inlen, buf, len)) goto done; ret = 1; done: EVP_PKEY_free(pkey); return ret; }