summaryrefslogtreecommitdiff
path: root/examples/vrfy.sig
diff options
context:
space:
mode:
authorwilliam <william@25tandclement.com>2014-09-22 15:37:29 -0700
committerwilliam <william@25tandclement.com>2014-09-22 15:37:29 -0700
commit920118b13d4ec90c5b36a682bc002868b8fff877 (patch)
treec7e5e6691cd3d87353d6334082c849bc1c4a903d /examples/vrfy.sig
parentd4914b31664e771ae93b88f6f83fb24c616b20fd (diff)
downloadluaossl-920118b13d4ec90c5b36a682bc002868b8fff877.tar.gz
luaossl-920118b13d4ec90c5b36a682bc002868b8fff877.tar.bz2
luaossl-920118b13d4ec90c5b36a682bc002868b8fff877.zip
make default key algorithm in self.x509 and vrfy.sig examples depend on whether EC is supported locally
Diffstat (limited to 'examples/vrfy.sig')
-rwxr-xr-xexamples/vrfy.sig19
1 files changed, 17 insertions, 2 deletions
diff --git a/examples/vrfy.sig b/examples/vrfy.sig
index cf60995..258490a 100755
--- a/examples/vrfy.sig
+++ b/examples/vrfy.sig
@@ -3,15 +3,30 @@
3-- Example public-key signature verification. 3-- Example public-key signature verification.
4-- 4--
5 5
6local keytype = ...
7
8local openssl = require"openssl"
6local pkey = require"openssl.pkey" 9local pkey = require"openssl.pkey"
7local digest = require"openssl.digest" 10local digest = require"openssl.digest"
8 11
9-- generate a public/private key pair 12-- generate a public/private key pair
10local key = pkey.new{ type = "EC", curve = "prime192v1" } 13local function genkey(type)
14 type = string.upper(type or (not openssl.NO_EC and "EC") or "RSA")
15
16 if type == "RSA" then
17 return pkey.new{ type = "RSA", bits = 1024 }, "sha256"
18 elseif type == "DSA" then
19 return pkey.new{ type = "DSA", bits = 1024 }, "dss1"
20 else
21 return pkey.new{ type = "EC", curve = "prime192v1" }, "ecdsa-with-SHA1"
22 end
23end
24
25local key, hash = genkey(keytype)
11 26
12-- digest our message using an appropriate digest ("ecdsa-with-SHA1" for EC; 27-- digest our message using an appropriate digest ("ecdsa-with-SHA1" for EC;
13-- "dss1" for DSA; and "sha1", "sha256", etc for RSA). 28-- "dss1" for DSA; and "sha1", "sha256", etc for RSA).
14local data = digest.new"ecdsa-with-SHA1" 29local data = digest.new(hash)
15data:update(... or "hello world") 30data:update(... or "hello world")
16 31
17-- generate a signature for our data 32-- generate a signature for our data