diff options
author | Joe Crayne <joe@jerkface.net> | 2019-11-14 16:45:14 -0500 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2019-11-14 16:45:14 -0500 |
commit | b42c0d847a785487f3222b0d5360746d25d3209c (patch) | |
tree | 11ef85e3e4577eb047227f9938761bdac94a1309 /tests | |
parent | 76bf7e08bccbb1a3a689068016b8a9c29d1e060e (diff) |
Cv25519 encryption.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test-cv25519.hs | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/tests/test-cv25519.hs b/tests/test-cv25519.hs new file mode 100644 index 0000000..faf2573 --- /dev/null +++ b/tests/test-cv25519.hs | |||
@@ -0,0 +1,110 @@ | |||
1 | {-# LANGUAGE QuasiQuotes #-} | ||
2 | {-# LANGUAGE ExistentialQuantification #-} | ||
3 | {-# LANGUAGE OverloadedStrings #-} | ||
4 | |||
5 | import Control.Arrow | ||
6 | import Control.Monad | ||
7 | import Data.Binary | ||
8 | import Data.Binary.Get | ||
9 | import Data.ByteString (ByteString) | ||
10 | import Data.Bits | ||
11 | import qualified Data.ByteArray as BA | ||
12 | import qualified Data.ByteString.Char8 as B8 | ||
13 | import qualified Data.ByteString as BS | ||
14 | import qualified Data.ByteString.Lazy as BL | ||
15 | import Data.Char | ||
16 | import Text.Show.Pretty | ||
17 | import Numeric | ||
18 | import Data.Int | ||
19 | |||
20 | import Data.OpenPGP.Internal | ||
21 | import Data.OpenPGP.Util | ||
22 | import Data.OpenPGP.Util.Base | ||
23 | import Data.OpenPGP as OpenPGP | ||
24 | import Crypto.Cipher.SBox | ||
25 | import Data.OpenPGP.Util.Ed25519 (zeroExtend,zeroPad) | ||
26 | import qualified Crypto.PubKey.Curve25519 as Cv25519 | ||
27 | import Crypto.Error | ||
28 | import Crypto.Cipher.AES | ||
29 | import Crypto.Cipher.Types | ||
30 | import Data.OpenPGP.Util.DecryptSecretKey -- (withS2K, simpleUnCFB, Enciphered(..)) | ||
31 | |||
32 | import Data.OpenPGP.Util.Cv25519 | ||
33 | |||
34 | msg :: ByteString | ||
35 | msg = [bytes| | ||
36 | 84 5e 03 c2 69 bf c6 b5 ad 64 55 12 01 07 40 ed | ||
37 | 3a 49 32 b5 2b 4e f5 c8 b1 3d 25 8c 73 c6 bc f3 | ||
38 | 16 c2 4d ed 23 3c ef ac 01 df ff ea 8a 38 75 30 | ||
39 | ab 5e d2 7b eb 5c 1f 7d 65 9d 7b 84 b4 5e fb b9 | ||
40 | 43 81 29 d4 e9 ba 0d 08 34 be 95 40 9d 57 0c 85 | ||
41 | 0d 94 4c fe 42 21 a0 23 d9 70 3d a2 03 ec 0a d1 | ||
42 | |||
43 | d2 70 01 95 06 62 3d 1b 66 ba 5b 67 b8 a7 2a b7 | ||
44 | 86 0b 28 94 18 c5 3b ef fc 2f e2 5d 87 78 80 9e | ||
45 | 89 dc c7 e7 87 14 b8 bc 8c 9f 93 2f bb 2b c3 7c | ||
46 | 3c da c5 32 32 bf 58 3f fa 7f 1c 53 b7 14 63 b7 | ||
47 | 1c 2e d6 29 c8 8e 15 a8 48 6d 97 a9 35 49 21 c7 | ||
48 | 73 20 b4 00 4e db 80 04 30 4a df 59 77 79 22 aa | ||
49 | 0c 7c 08 a1 d0 d6 a7 30 9d e9 59 8d 2d 9f e8 c4 | ||
50 | 0c 2b | ||
51 | |] | ||
52 | |||
53 | keyring :: ByteString | ||
54 | keyring = | ||
55 | [bytes| | ||
56 | 94 58 04 5d c8 7f 7e 16 09 2b 06 01 04 01 da 47 | ||
57 | 0f 01 01 07 40 bb a7 dc 2a e0 b0 ef 05 d1 69 07 | ||
58 | 31 b3 91 0d c9 69 38 6f 3f 97 e6 19 45 cb 6c 76 | ||
59 | 3b 15 29 f5 e5 00 01 00 96 eb 2a 5c d5 5b 65 25 | ||
60 | e9 dd ed b8 58 1c e9 1e 75 f2 26 92 9d 9f 35 d7 | ||
61 | 35 a7 65 e5 41 44 f5 f5 11 a4 b4 18 47 75 79 20 | ||
62 | 54 2e 20 3c 67 75 79 40 65 78 61 6d 70 6c 65 2e | ||
63 | 63 6f 6d 3e 88 90 04 13 16 08 00 38 16 21 04 00 | ||
64 | 7d a7 19 91 02 5a 09 bd da 46 78 38 ed ab 61 d8 | ||
65 | 66 c7 02 05 02 5d c8 7f 7e 02 1b 03 05 0b 09 08 | ||
66 | 07 02 06 15 0a 09 08 0b 02 04 16 02 03 01 02 1e | ||
67 | 01 02 17 80 00 0a 09 10 38 ed ab 61 d8 66 c7 02 | ||
68 | 3e d4 00 ff 7a 88 a3 af cd 96 bd 46 b4 31 76 3c | ||
69 | 40 35 1c ef 0b 0b 1d e2 66 03 7e 22 4c 32 34 f7 | ||
70 | db dd 20 98 00 ff 55 20 65 55 ed 70 a4 a0 03 58 | ||
71 | c3 1c 0a 12 63 b5 5c 3f f8 18 de 62 c8 0b e7 85 | ||
72 | 37 ee 8c 7a 2a 0d 9c 5d 04 5d c8 7f 7e 12 0a 2b | ||
73 | 06 01 04 01 97 55 01 05 01 01 07 40 71 8a c9 e8 | ||
74 | 0d cf 0d d0 16 10 c2 26 50 f1 f4 1c 49 b4 af 4d | ||
75 | aa 0e 06 2b 35 8c 1e 86 79 8c 25 31 03 01 08 07 | ||
76 | 00 00 ff 68 a2 f7 b1 31 2c 6a 09 82 f2 55 a2 44 | ||
77 | cb d4 a1 0d 62 ef f0 77 18 68 d9 6c 86 c1 b2 c7 | ||
78 | e1 4d 40 12 28 88 78 04 18 16 08 00 20 16 21 04 | ||
79 | 00 7d a7 19 91 02 5a 09 bd da 46 78 38 ed ab 61 | ||
80 | d8 66 c7 02 05 02 5d c8 7f 7e 02 1b 0c 00 0a 09 | ||
81 | 10 38 ed ab 61 d8 66 c7 02 86 10 01 00 83 99 5d | ||
82 | 74 90 f5 4a b5 74 bc 07 77 7a f7 25 14 3e 5e bf | ||
83 | ae 52 99 0c 01 05 0b 4b 57 ee 95 02 1b 01 00 eb | ||
84 | db e4 27 95 f9 a4 4f bc f0 ce cc 44 33 90 ab 42 | ||
85 | 0f aa ca 06 89 ce 48 f1 85 27 62 05 73 e3 03 | ||
86 | |] | ||
87 | |||
88 | |||
89 | expected_result = CompressedDataPacket | ||
90 | { compression_algorithm = ZLIB | ||
91 | , message = Message [ LiteralDataPacket | ||
92 | { format = 'b' | ||
93 | , filename = "secret-message.txt" | ||
94 | , timestamp = 1573421489 | ||
95 | , content = "This is a secret that will be encrypted.\n"} | ||
96 | ] | ||
97 | } | ||
98 | |||
99 | main = do | ||
100 | let Message [asym,encdta] = decode (BL.fromStrict msg) | ||
101 | Message | ||
102 | [ master -- ---Secret 007DA71991025A09BDDA467838EDAB61D866C702 Ed25519 | ||
103 | , uid -- UserID "Guy T. <guy@example.com>" | ||
104 | , uidsig -- Signature ^ signed: 38EDAB61D866C702 ["vouch-sign"] | ||
105 | , ecdhkey -- SecretKey 8CF3B7D9CDCA47086F3C509AC269BFC6B5AD6455 ECC | ||
106 | , ecdhsig -- Signature ^ signed: 38EDAB61D866C702 ["encrypt"] | ||
107 | ] = decode (BL.fromStrict keyring) | ||
108 | m = decryptMessage ecdhkey asym encdta | ||
109 | print m | ||
110 | putStrLn $ "decrypt cv25519: " ++ show (m == Just [expected_result]) | ||