| 1 | package ccmscip-go gomod github.com/cloudsoda/go-smb2 . `github.com/cloudsoda/go-smb2/internal/crypto/ccm`/ |
| 2 | |
| 3 | import ( |
| 4 | "bytesscip-go gomod github.com/golang/go/src go1.22 bytes/" |
| 5 | "crypto/aesscip-go gomod github.com/golang/go/src go1.22 `crypto/aes`/" |
| 6 | "testingscip-go gomod github.com/golang/go/src go1.22 testing/" |
| 7 | ) |
| 8 | |
| 9 | // run examples defined in Appendix C. |
| 10 | func Testscip-go gomod github.com/cloudsoda/go-smb2 . `github.com/cloudsoda/go-smb2/internal/crypto/ccm`/Test().(t *testingscip-go gomod github.com/golang/go/src go1.22 testing/.Tscip-go gomod github.com/golang/go/src go1.22 testing/T#) { |
| 11 | C4A := make([]byte, 524288/8) |
| 12 | for i := range C4A { |
| 13 | C4A[i] = byte(i) |
| 14 | } |
| 15 | |
| 16 | examples := []struct { |
| 17 | Key []byte |
| 18 | Nonce []byte |
| 19 | Data []byte |
| 20 | PlainText []byte |
| 21 | CipherText []byte |
| 22 | TagLen int |
| 23 | }{ |
| 24 | { // C.1 |
| 25 | []byte{0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f}, |
| 26 | []byte{0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16}, |
| 27 | []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}, |
| 28 | []byte{0x20, 0x21, 0x22, 0x23}, |
| 29 | []byte{0x71, 0x62, 0x01, 0x5b, 0x4d, 0xac, 0x25, 0x5d}, |
| 30 | 4, |
| 31 | }, |
| 32 | { // C.2 |
| 33 | []byte{0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f}, |
| 34 | []byte{0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17}, |
| 35 | []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, |
| 36 | []byte{0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, |
| 37 | []byte{0xd2, 0xa1, 0xf0, 0xe0, 0x51, 0xea, 0x5f, 0x62, 0x08, 0x1a, 0x77, 0x92, 0x07, 0x3d, 0x59, 0x3d, 0x1f, 0xc6, 0x4f, 0xbf, 0xac, 0xcd}, |
| 38 | 6, |
| 39 | }, |
| 40 | { // C.3 |
| 41 | []byte{0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f}, |
| 42 | []byte{0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b}, |
| 43 | []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13}, |
| 44 | []byte{0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37}, |
| 45 | |
| 46 | []byte{0xe3, 0xb2, 0x01, 0xa9, 0xf5, 0xb7, 0x1a, 0x7a, 0x9b, 0x1c, 0xea, 0xec, 0xcd, 0x97, 0xe7, 0x0b, 0x61, 0x76, 0xaa, 0xd9, 0xa4, 0x42, 0x8a, 0xa5, 0x48, 0x43, 0x92, 0xfb, 0xc1, 0xb0, 0x99, 0x51}, |
| 47 | 8, |
| 48 | }, |
| 49 | { // C.4 |
| 50 | []byte{0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f}, |
| 51 | []byte{0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c}, |
| 52 | C4A, |
| 53 | []byte{0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f}, |
| 54 | |
| 55 | []byte{0x69, 0x91, 0x5d, 0xad, 0x1e, 0x84, 0xc6, 0x37, 0x6a, 0x68, 0xc2, 0x96, 0x7e, 0x4d, 0xab, 0x61, 0x5a, 0xe0, 0xfd, 0x1f, 0xae, 0xc4, 0x4c, 0xc4, 0x84, 0x82, 0x85, 0x29, 0x46, 0x3c, 0xcf, 0x72, 0xb4, 0xac, 0x6b, 0xec, 0x93, 0xe8, 0x59, 0x8e, 0x7f, 0x0d, 0xad, 0xbc, 0xea, 0x5b}, |
| 56 | 14, |
| 57 | }, |
| 58 | } |
| 59 | |
| 60 | for _, ex := range examples { |
| 61 | c, err := aesscip-go gomod github.com/golang/go/src go1.22 `crypto/aes`/.NewCipherscip-go gomod github.com/golang/go/src go1.22 `crypto/aes`/NewCipher().(ex.Key) |
| 62 | if err != nil { |
| 63 | t.Fatalscip-go gomod github.com/golang/go/src go1.22 testing/common#Fatal().(err) |
| 64 | } |
| 65 | |
| 66 | ccm, err := NewCCMWithNonceAndTagSizesscip-go gomod github.com/cloudsoda/go-smb2 . `github.com/cloudsoda/go-smb2/internal/crypto/ccm`/NewCCMWithNonceAndTagSizes().(c, len(ex.Nonce), ex.TagLen) |
| 67 | if err != nil { |
| 68 | t.Logscip-go gomod github.com/golang/go/src go1.22 testing/common#Log().(err) |
| 69 | } |
| 70 | |
| 71 | CipherText := ccm.Sealscip-go gomod github.com/golang/go/src go1.22 `crypto/cipher`/AEAD#Seal().(nil, ex.Nonce, ex.PlainText, ex.Data) |
| 72 | |
| 73 | if !bytesscip-go gomod github.com/golang/go/src go1.22 bytes/.Equalscip-go gomod github.com/golang/go/src go1.22 bytes/Equal().(ex.CipherText, CipherText) { |
| 74 | t.Logscip-go gomod github.com/golang/go/src go1.22 testing/common#Log().(err) |
| 75 | } |
| 76 | |
| 77 | PlainText, err := ccm.Openscip-go gomod github.com/golang/go/src go1.22 `crypto/cipher`/AEAD#Open().(nil, ex.Nonce, ex.CipherText, ex.Data) |
| 78 | if err != nil { |
| 79 | t.Fatalscip-go gomod github.com/golang/go/src go1.22 testing/common#Fatal().(err) |
| 80 | } |
| 81 | |
| 82 | if !bytesscip-go gomod github.com/golang/go/src go1.22 bytes/.Equalscip-go gomod github.com/golang/go/src go1.22 bytes/Equal().(ex.PlainText, PlainText) { |
| 83 | t.Logscip-go gomod github.com/golang/go/src go1.22 testing/common#Log().(err) |
| 84 | } |
| 85 | } |
| 86 | } |