EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new(pkey, NULL);
g_assert(pctx != NULL);
g_assert(EVP_PKEY_verify_init(pctx) == 1);
+ g_assert(EVP_PKEY_CTX_set_rsa_padding(pctx, RSA_PKCS1_PADDING) == 1);
+ g_assert(EVP_PKEY_CTX_set_signature_md(pctx, EVP_sha256()) == 1);
ret = EVP_PKEY_verify(pctx, signature->str, signature->len, data, sz);
g_assert(pctx != NULL);
g_assert(EVP_PKEY_sign_init(pctx) == 1);
+ g_assert(EVP_PKEY_CTX_set_rsa_padding(pctx, RSA_PKCS1_PADDING) == 1);
+ g_assert(EVP_PKEY_CTX_set_signature_md(pctx, EVP_sha256()) == 1);
size_t slen = signature->allocated;
ret = EVP_PKEY_sign(pctx, signature->str, &slen, data, sz);
local privkey = 'testkey.sec'
local data = 'test.data'
local signature = 'test.sig'
+ local signature_bytes = 'test.sig_bytes'
local test_dir = string.gsub(debug.getinfo(1).source, "^@(.+/)[^/]+$", "%1")
local rsa_key, rsa_sig
h:update(d)
local sig = rsa.sign_memory(rsa_key, h:bin())
assert_not_nil(sig)
- sig:save(string.format('%s/%s', test_dir, signature), true)
+ sig:save(string.format('%s/%s', test_dir, signature_bytes), true)
+ local sig_actual = string.format('%s\n', sig:base64(80, 'lf'))
+ local sig_expected = io.open(string.format('%s/%s', test_dir, signature), "rb"):read "*a"
+ assert_equal(sig_actual, sig_expected)
end)
test("RSA verify", function()
h:update(d)
rsa_key = rsa_pubkey.load(string.format('%s/%s', test_dir, pubkey))
assert_not_nil(rsa_key)
- rsa_sig = rsa_signature.load(string.format('%s/%s', test_dir, signature))
+ rsa_sig = rsa_signature.load(string.format('%s/%s', test_dir, signature_bytes))
assert_not_nil(rsa_sig)
assert_true(rsa.verify_memory(rsa_key, rsa_sig, h:bin()))
end)
test("RSA keypair + sign + verify", function()
local sk, pk = rsa.keypair()
- local sig = rsa.sign_memory(sk, "test")
- assert_true(rsa.verify_memory(pk, sig, "test"))
- assert_false(rsa.verify_memory(pk, sig, "test1"))
+ local sig = rsa.sign_memory(sk, "test_012345678901234567890123456")
+ assert_true(rsa.verify_memory(pk, sig, "test_012345678901234567890123456"))
+ assert_false(rsa.verify_memory(pk, sig, "blah_012345678901234567890123456"))
-- Overwrite
sk, pk = rsa.keypair()
- assert_false(rsa.verify_memory(pk, sig, "test"))
+ assert_false(rsa.verify_memory(pk, sig, "test_012345678901234567890123456"))
end)
test("RSA-2048 keypair + sign + verify", function()
local sk, pk = rsa.keypair(2048)
- local sig = rsa.sign_memory(sk, "test")
- assert_true(rsa.verify_memory(pk, sig, "test"))
- assert_false(rsa.verify_memory(pk, sig, "test1"))
+ local sig = rsa.sign_memory(sk, "test_012345678901234567890123456")
+ assert_true(rsa.verify_memory(pk, sig, "test_012345678901234567890123456"))
+ assert_false(rsa.verify_memory(pk, sig, "blah_012345678901234567890123456"))
-- Overwrite
sk, pk = rsa.keypair(2048)
- assert_false(rsa.verify_memory(pk, sig, "test"))
+ assert_false(rsa.verify_memory(pk, sig, "test_012345678901234567890123456"))
end)
end)