+test.ha (2773B)
1 // SPDX-License-Identifier: MPL-2.0 2 // (c) Hare authors <https://harelang.org> 3 4 use bytes; 5 6 @test fn oneblock() void = { 7 let key: [_]u8 = [ 8 0xfe, 0x7f, 0xec, 0x77, 0x1b, 0xa4, 0x28, 0xc7, 0xf8, 0x82, 9 0x62, 0x2b, 0xe7, 0x60, 0x59, 0xf5, 0x25, 0x71, 0xda, 0x8b, 10 0x8f, 0x72, 0x04, 0xe4, 0x38, 0xa2, 0xa5, 0x98, 0x45, 0x14, 11 0xff, 0xbe, 0xce, 0xf6, 0xaa, 0xcc, 0xe1, 0x86, 0xc2, 0x2b, 12 0x9e, 0x55, 0x86, 0x23, 0x71, 0x96, 0xa3, 0xb1, 0xa1, 0xf9, 13 0x11, 0x4d, 0x86, 0xf8, 0x7e, 0xd1, 0xae, 0x5a, 0x3d, 0x4a, 14 0x99, 0x65, 0xd0, 0xb1, 15 ]; 16 let sector1: [_]u8 = [ 17 0xe4, 0x60, 0xb0, 0x44, 0x7c, 0xc0, 0xbe, 0x63, 0xbb, 0x88, 18 0x62, 0xab, 0x6e, 0x49, 0xde, 0xea, 19 ]; 20 let crypto1: [_]u8 = [ 21 0x6f, 0x3c, 0x46, 0xd8, 0x36, 0x25, 0x7d, 0x70, 0x00, 0xc3, 22 0x94, 0x92, 0x48, 0x18, 0xa1, 0x67, 23 ]; 24 25 let result: [16]u8 = [0...]; 26 27 let b = xts(); 28 init(&b, key); 29 30 encrypt(&b, result, sector1, 1); 31 assert(bytes::equal(crypto1, result)); 32 33 decrypt(&b, result, crypto1, 1); 34 assert(bytes::equal(sector1, result)); 35 }; 36 37 @test fn multiblock() void = { 38 const key: [_]u8 = [ 39 0x61, 0x7f, 0x3d, 0x06, 0xa2, 0x18, 0x4b, 0x63, 0xd7, 0xad, 40 0xfa, 0x07, 0xe7, 0x57, 0x6c, 0x2a, 0xb7, 0xb4, 0xce, 0x55, 41 0x3d, 0x90, 0xd0, 0x87, 0xdf, 0xc6, 0xf4, 0x72, 0x4c, 0x54, 42 0xcd, 0xda, 0x93, 0x0b, 0xb5, 0x40, 0x4b, 0xab, 0x10, 0x85, 43 0x6b, 0xf7, 0x45, 0xc7, 0xda, 0x5e, 0x6e, 0x69, 0xdf, 0x68, 44 0xdd, 0xb8, 0xdd, 0xd9, 0xc2, 0xe6, 0x85, 0x2e, 0x25, 0x7a, 45 0xb4, 0xfc, 0x97, 0x20, 46 ]; 47 const sector11: [_]u8 = [ 48 0xc9, 0x41, 0xae, 0x7d, 0x5c, 0x0b, 0xa5, 0xb1, 0x31, 0xee, 49 0x2e, 0x4b, 0xf8, 0x74, 0x29, 0xc5, 0x39, 0x9b, 0xfe, 0x2e, 50 0x51, 0xb8, 0xab, 0xaa, 0x72, 0x49, 0x04, 0x43, 0x2a, 0x4d, 51 0x50, 0xdc, 52 ]; 53 const crypto11: [_]u8 = [ 54 0x30, 0xa3, 0x8f, 0x05, 0x49, 0x1e, 0x4d, 0xda, 0x47, 0x44, 55 0xae, 0xff, 0x7f, 0x4d, 0x4e, 0xb5, 0xca, 0xb2, 0xfc, 0xa9, 56 0x70, 0x55, 0x1a, 0x05, 0xa1, 0x2a, 0xd8, 0x34, 0x6f, 0x9b, 57 0x02, 0xc0, 58 ]; 59 const sector14: [_]u8 = [ 60 0x2e, 0x95, 0x4d, 0xa7, 0x1f, 0xfb, 0xd3, 0xc8, 0x8e, 0x6f, 61 0x07, 0xab, 0x75, 0x53, 0xfc, 0x87, 0x05, 0xe8, 0xe8, 0x5a, 62 0x47, 0xbc, 0xc9, 0x12, 0x0c, 0xc4, 0x09, 0x30, 0x86, 0x91, 63 0xcc, 0xfa, 64 ]; 65 const crypto14: [_]u8 = [ 66 0xa1, 0xf8, 0xd6, 0x35, 0xcd, 0x1e, 0xbe, 0xb7, 0x64, 0xcb, 67 0xbe, 0x2c, 0x58, 0xb1, 0xc0, 0xd2, 0x4e, 0x8a, 0x9e, 0x09, 68 0x76, 0x08, 0xf7, 0x28, 0x94, 0xaf, 0xf8, 0x20, 0x1c, 0xbb, 69 0x02, 0x9c, 70 ]; 71 72 let result: [32]u8 = [0...]; 73 74 let b = xts(); 75 init(&b, key); 76 77 encrypt(&b, result, sector11, 11); 78 assert(bytes::equal(crypto11, result)); 79 encrypt(&b, result, sector14, 14); 80 assert(bytes::equal(crypto14, result)); 81 82 decrypt(&b, result, crypto11, 11); 83 assert(bytes::equal(sector11, result)); 84 decrypt(&b, result, crypto14, 14); 85 assert(bytes::equal(sector14, result)); 86 };