Skip to content

Commit

Permalink
test Unwrap
Browse files Browse the repository at this point in the history
  • Loading branch information
5HT committed Jul 5, 2023
1 parent b9d8cfe commit 8106557
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions lib/sec.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
defmodule CA.CRYPTO do


def testCMSX509() do
{_,base} = :file.read_file "priv/encrypted.txt"
[_,s] = :string.split base, "\n\n" # S/MIME
Expand Down Expand Up @@ -50,11 +49,11 @@ defmodule CA.CRYPTO do

def shared(pub, key, scheme), do: :crypto.compute_key(:ecdh, pub, key, scheme)

def testKDF() do
{maximK,key} = privat "maxim"
def test____() do
{maximK,_} = privat "maxim"
{maximP,_} = public "maxim"

Check warning on line 54 in lib/sec.ex

View workflow job for this annotation

GitHub Actions / build

variable "maximP" is unused (if the variable is not meant to be used, prefix it with an underscore)
scheme = :prime256v1
kdf = <<246, 12, 141, 164, 154, 173, 117, 144, 14, 3, 156, 213, 42, 25, 211, 160, 130,
43, 51, 242, 75, 160, 175, 11, 167, 76, 177, 17, 211, 75, 146, 200>>
kdf = <<72, 107, 155, 26, 72, 48, 84, 17, 196, 223, 216, 171, 80, 69, 237, 114, 43, 195, 185, 109, 228, 129, 171, 72, 73, 223, 122, 52, 129, 156, 101, 121>>

Check warning on line 56 in lib/sec.ex

View workflow job for this annotation

GitHub Actions / build

variable "kdf" is unused (if the variable is not meant to be used, prefix it with an underscore)
unwrapped = <<91, 14, 167, 227, 231, 214, 163, 73, 170, 246, 181, 226, 189, 201, 124, 243, 41,

Check warning on line 57 in lib/sec.ex

View workflow job for this annotation

GitHub Actions / build

variable "unwrapped" is unused (if the variable is not meant to be used, prefix it with an underscore)
106, 120, 60, 134, 166, 142, 197, 183, 120, 127, 214, 23, 232, 212, 134>>
encryptedKey = <<10, 165, 23, 245, 67, 211, 61, 126, 224, 151, 243, 132, 154, 31, 124, 254, 125,
Expand All @@ -69,9 +68,22 @@ defmodule CA.CRYPTO do
unwrap = :aes_kw.unwrap(encryptedKey, sharedKey)

Check warning on line 68 in lib/sec.ex

View workflow job for this annotation

GitHub Actions / build

variable "unwrap" is unused (if the variable is not meant to be used, prefix it with an underscore)
end

def testKDF() do
end

def testUnwrap() do
kdf = <<217, 187, 27, 152, 7, 7, 119, 110, 226, 226, 88, 211, 48, 219, 93, 90, 130, 76,
194, 66, 49, 125, 14, 88, 130, 54, 175, 10, 251, 201, 59, 67>>
encryptedKey = <<153, 198, 198, 10, 57, 65, 242, 44, 238, 159, 74, 127, 47, 28, 195, 207, 104,
237, 99, 111, 180, 187, 238, 154, 135, 218, 93, 103, 133, 48, 50, 24, 174,
236, 118, 37, 235, 232, 143, 54>>
unwrap = :aes_kw.unwrap(encryptedKey, kdf)

Check warning on line 80 in lib/sec.ex

View workflow job for this annotation

GitHub Actions / build

variable "unwrap" is unused (if the variable is not meant to be used, prefix it with an underscore)
end

def testDecode() do
data = <<166, 245, 116, 20, 75, 138, 18, 153, 192, 25, 85, 227, 145, 0, 179, 32, 21, 20, 219, 137, 54, 9, 34, 190, 159, 1, 108, 168, 64, 10, 128, 42>>
iv = <<188, 9, 9, 162, 138, 88, 113, 80, 1, 38, 17, 80, 198, 172, 209, 69>>
data = <<166, 245, 116, 20, 75, 138, 18, 153, 192, 25, 85, 227, 145, 0, 179,
32, 21, 20, 219, 137, 54, 9, 34, 190, 159, 1, 108, 168, 64, 10, 128, 42>>
iv = <<188, 9, 9, 162, 138, 88, 113, 80, 1, 38, 17, 80, 198, 172, 209, 69>>
unwrap = <<234, 54, 248, 92, 153, 222, 78, 126, 242, 118, 211, 164, 72, 164, 19, 75,
213, 214, 12, 239, 142, 196, 130, 222, 64, 91, 2, 208, 144, 112, 15, 92>>
decryptCBC(data, unwrap, iv)
Expand Down

0 comments on commit 8106557

Please sign in to comment.