Skip to content

A peer-to-peer stack for code collaboration

Add some cryptography related functions. (#121)

James Haydon41b41941bc43
diff --git a/rad/crypto.rad b/rad/crypto.rad
new file mode 100644
index 0000000..025cbed
--- /dev/null
+++ b/rad/crypto.rad
@@ -0,0 +1,22 @@
+(define sign-from-file!
+ (lambda (keys-file msg)
+ (define ks (read (read-file! keys-file)))
+ (define sig (gen-signature! (lookup :private-key ks) msg))
+ {:message msg
+ :signature sig
+ :key (lookup :public-key ks)}))
+
+(document 'sign-from-file!
+ '(("keys-file" string)
+ ("msg" string))
+ "Create a signed message using a key-pair stored in a file. The file should contain output as generated by 'gen-key-pair!'.")
+
+(define verify-signed-message
+ (lambda (sig-msg)
+ (verify-signature (lookup :key sig-msg)
+ (lookup :signature sig-msg)
+ (lookup :message sig-msg))))
+
+(document 'verify-signed-message
+ '(("sig-msg" signed-message))
+ "Verify the signature of a signed message.")