-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathaescbc.mpcl
54 lines (49 loc) · 1.55 KB
/
aescbc.mpcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// -*- go -*-
package main
import (
"crypto/cipher/cbc"
)
// Case #1: Encrypting 16 bytes (1 block) using AES-CBC with 128-bit key
//
// Key : 0x06a9214036b8a15b512e03d534120006
// IV : 0x3dafba429d9eb430b422da802c9fac41
// Plaintext : "Single block msg"
// Ciphertext: 0xe353779c1079aeb82708942dbe77181a
//
// Case #2: Encrypting 32 bytes (2 blocks) using AES-CBC with 128-bit key
//
// Key : 0xc286696d887c9aa0611bbb3e2025a45a
// IV : 0x562e17996d093d28ddb3ba695a2e6f58
// Plaintext : 0x000102030405060708090a0b0c0d0e0f
// 101112131415161718191a1b1c1d1e1f
// Ciphertext: 0xd296cd94c2cccf8a3a863028b5e1dc0a
//
// 7586602d253cfff91b8266bea6d61ab1
func main(g, e [16]byte) []byte {
key := []byte{
0x06, 0xa9, 0x21, 0x40, 0x36, 0xb8, 0xa1, 0x5b,
0x51, 0x2e, 0x03, 0xd5, 0x34, 0x12, 0x00, 0x06,
}
iv := []byte{
0x3d, 0xaf, 0xba, 0x42, 0x9d, 0x9e, 0xb4, 0x30,
0xb4, 0x22, 0xda, 0x80, 0x2c, 0x9f, 0xac, 0x41,
}
plain := []byte("Single block msg")
key2 := []byte{
0xc2, 0x86, 0x69, 0x6d, 0x88, 0x7c, 0x9a, 0xa0,
0x61, 0x1b, 0xbb, 0x3e, 0x20, 0x25, 0xa4, 0x5a,
}
iv2 := []byte{
0x56, 0x2e, 0x17, 0x99, 0x6d, 0x09, 0x3d, 0x28,
0xdd, 0xb3, 0xba, 0x69, 0x5a, 0x2e, 0x6f, 0x58,
}
plain2 := []byte{
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
}
//return cbc.EncryptAES128(key, iv, plain)
//return cbc.EncryptAES128(key2, iv2, plain2)
return cbc.EncryptAES128(g, iv, e)
}