Changeset View
Changeset View
Standalone View
Standalone View
dev/cgd/t_cgd_aes.c
/* $NetBSD: t_cgd_aes.c,v 1.6 2017/01/13 21:30:39 christos Exp $ */ | /* $NetBSD: t_cgd_aes.c,v 1.8 2020/08/15 10:03:10 mlelstv Exp $ */ | ||||
/*- | /*- | ||||
* Copyright (c) 2016 The NetBSD Foundation, Inc. | * Copyright (c) 2016 The NetBSD Foundation, Inc. | ||||
* Copyright (c) 2007 The Institute of Electrical and Electronics Engineers, Inc | * Copyright (c) 2007 The Institute of Electrical and Electronics Engineers, Inc | ||||
* All rights reserved. | * All rights reserved. | ||||
* | * | ||||
* This code is derived from software contributed to The NetBSD Foundation | * This code is derived from software contributed to The NetBSD Foundation | ||||
* by Alexander Nasonov. | * by Alexander Nasonov. | ||||
* | * | ||||
▲ Show 20 Lines • Show All 74 Lines • ▼ Show 20 Lines | |||||
static const char aes_cbc_256_key[33] = { | static const char aes_cbc_256_key[33] = { | ||||
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, /* 01234567 */ | 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, /* 01234567 */ | ||||
0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, /* 89ABCDEF */ | 0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, /* 89ABCDEF */ | ||||
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, /* 01234567 */ | 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, /* 01234567 */ | ||||
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, /* 89abcdef */ | 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, /* 89abcdef */ | ||||
0 | 0 | ||||
}; | }; | ||||
static const uint8_t aes_cbc_ptxt[SECSIZE] = | static const uint8_t aes_cbc_ptxt[SECSIZE] __aligned(4) = | ||||
" abcdefghijklmnop" | " abcdefghijklmnop" | ||||
" abcdefghijklmnop" | " abcdefghijklmnop" | ||||
" abcdefghijklmnop" | " abcdefghijklmnop" | ||||
" abcdefghijklmnop" | " abcdefghijklmnop" | ||||
" abcdefghijklmnop" | " abcdefghijklmnop" | ||||
" abcdefghijklmnop" | " abcdefghijklmnop" | ||||
" abcdefghijklmnop" | " abcdefghijklmnop" | ||||
" abcdefghijklmnop" | " abcdefghijklmnop" | ||||
▲ Show 20 Lines • Show All 1,848 Lines • ▼ Show 20 Lines | static const char aes_xts_512_key[65] = { | ||||
0x02, 0x88, 0x41, 0x97, 0x16, 0x93, 0x99, 0x37, | 0x02, 0x88, 0x41, 0x97, 0x16, 0x93, 0x99, 0x37, | ||||
0x51, 0x05, 0x82, 0x09, 0x74, 0x94, 0x45, 0x92, | 0x51, 0x05, 0x82, 0x09, 0x74, 0x94, 0x45, 0x92, | ||||
0 | 0 | ||||
}; | }; | ||||
/* | /* | ||||
* Vector 4 from IEEE 1619/D16, blkno 0. | * Vector 4 from IEEE 1619/D16, blkno 0. | ||||
*/ | */ | ||||
static const uint8_t aes_xts_256_vec4_ptxt[SECSIZE] = { | static const uint8_t aes_xts_256_vec4_ptxt[SECSIZE] __aligned(4) = { | ||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | ||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, | ||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, | ||||
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, | ||||
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, | 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, | ||||
0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, | 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, | ||||
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, | 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, | ||||
0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, | 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, | ||||
▲ Show 20 Lines • Show All 120 Lines • ▼ Show 20 Lines | static const uint8_t aes_xts_256_vec4_ctxt[SECSIZE] = { | ||||
0xf2, 0x62, 0x73, 0x57, 0x79, 0xa4, 0x18, 0xf2, | 0xf2, 0x62, 0x73, 0x57, 0x79, 0xa4, 0x18, 0xf2, | ||||
0x0a, 0x28, 0x2d, 0xf9, 0x20, 0x14, 0x7b, 0xea, | 0x0a, 0x28, 0x2d, 0xf9, 0x20, 0x14, 0x7b, 0xea, | ||||
0xbe, 0x42, 0x1e, 0xe5, 0x31, 0x9d, 0x05, 0x68, | 0xbe, 0x42, 0x1e, 0xe5, 0x31, 0x9d, 0x05, 0x68, | ||||
}; | }; | ||||
/* | /* | ||||
* Vector 5 from IEEE 1619/D16, blkno 1. | * Vector 5 from IEEE 1619/D16, blkno 1. | ||||
*/ | */ | ||||
static const uint8_t aes_xts_256_vec5_ptxt[SECSIZE] = { | static const uint8_t aes_xts_256_vec5_ptxt[SECSIZE] __aligned(4) = { | ||||
0x27, 0xa7, 0x47, 0x9b, 0xef, 0xa1, 0xd4, 0x76, | 0x27, 0xa7, 0x47, 0x9b, 0xef, 0xa1, 0xd4, 0x76, | ||||
0x48, 0x9f, 0x30, 0x8c, 0xd4, 0xcf, 0xa6, 0xe2, | 0x48, 0x9f, 0x30, 0x8c, 0xd4, 0xcf, 0xa6, 0xe2, | ||||
0xa9, 0x6e, 0x4b, 0xbe, 0x32, 0x08, 0xff, 0x25, | 0xa9, 0x6e, 0x4b, 0xbe, 0x32, 0x08, 0xff, 0x25, | ||||
0x28, 0x7d, 0xd3, 0x81, 0x96, 0x16, 0xe8, 0x9c, | 0x28, 0x7d, 0xd3, 0x81, 0x96, 0x16, 0xe8, 0x9c, | ||||
0xc7, 0x8c, 0xf7, 0xf5, 0xe5, 0x43, 0x44, 0x5f, | 0xc7, 0x8c, 0xf7, 0xf5, 0xe5, 0x43, 0x44, 0x5f, | ||||
0x83, 0x33, 0xd8, 0xfa, 0x7f, 0x56, 0x00, 0x00, | 0x83, 0x33, 0xd8, 0xfa, 0x7f, 0x56, 0x00, 0x00, | ||||
0x05, 0x27, 0x9f, 0xa5, 0xd8, 0xb5, 0xe4, 0xad, | 0x05, 0x27, 0x9f, 0xa5, 0xd8, 0xb5, 0xe4, 0xad, | ||||
0x40, 0xe7, 0x36, 0xdd, 0xb4, 0xd3, 0x54, 0x12, | 0x40, 0xe7, 0x36, 0xdd, 0xb4, 0xd3, 0x54, 0x12, | ||||
▲ Show 20 Lines • Show All 120 Lines • ▼ Show 20 Lines | static const uint8_t aes_xts_256_vec5_ctxt[SECSIZE] = { | ||||
0xb7, 0xb1, 0xd7, 0x81, 0x8a, 0x4b, 0x75, 0x3d, | 0xb7, 0xb1, 0xd7, 0x81, 0x8a, 0x4b, 0x75, 0x3d, | ||||
0xfd, 0x2a, 0x89, 0xcc, 0xb4, 0x5e, 0x00, 0x1a, | 0xfd, 0x2a, 0x89, 0xcc, 0xb4, 0x5e, 0x00, 0x1a, | ||||
0x03, 0xa8, 0x67, 0xb1, 0x87, 0xf2, 0x25, 0xdd, | 0x03, 0xa8, 0x67, 0xb1, 0x87, 0xf2, 0x25, 0xdd, | ||||
}; | }; | ||||
/* | /* | ||||
* Vector 6 from IEEE 1619/D16, blkno 2. | * Vector 6 from IEEE 1619/D16, blkno 2. | ||||
*/ | */ | ||||
static const uint8_t aes_xts_256_vec6_ptxt[SECSIZE] = { | static const uint8_t aes_xts_256_vec6_ptxt[SECSIZE] __aligned(4) = { | ||||
0x26, 0x4d, 0x3c, 0xa8, 0x51, 0x21, 0x94, 0xfe, | 0x26, 0x4d, 0x3c, 0xa8, 0x51, 0x21, 0x94, 0xfe, | ||||
0xc3, 0x12, 0xc8, 0xc9, 0x89, 0x1f, 0x27, 0x9f, | 0xc3, 0x12, 0xc8, 0xc9, 0x89, 0x1f, 0x27, 0x9f, | ||||
0xef, 0xdd, 0x60, 0x8d, 0x0c, 0x02, 0x7b, 0x60, | 0xef, 0xdd, 0x60, 0x8d, 0x0c, 0x02, 0x7b, 0x60, | ||||
0x48, 0x3a, 0x3f, 0xa8, 0x11, 0xd6, 0x5e, 0xe5, | 0x48, 0x3a, 0x3f, 0xa8, 0x11, 0xd6, 0x5e, 0xe5, | ||||
0x9d, 0x52, 0xd9, 0xe4, 0x0e, 0xc5, 0x67, 0x2d, | 0x9d, 0x52, 0xd9, 0xe4, 0x0e, 0xc5, 0x67, 0x2d, | ||||
0x81, 0x53, 0x2b, 0x38, 0xb6, 0xb0, 0x89, 0xce, | 0x81, 0x53, 0x2b, 0x38, 0xb6, 0xb0, 0x89, 0xce, | ||||
0x95, 0x1f, 0x0f, 0x9c, 0x35, 0x59, 0x0b, 0x8b, | 0x95, 0x1f, 0x0f, 0x9c, 0x35, 0x59, 0x0b, 0x8b, | ||||
0x97, 0x8d, 0x17, 0x52, 0x13, 0xf3, 0x29, 0xbb, | 0x97, 0x8d, 0x17, 0x52, 0x13, 0xf3, 0x29, 0xbb, | ||||
▲ Show 20 Lines • Show All 120 Lines • ▼ Show 20 Lines | static const uint8_t aes_xts_256_vec6_ctxt[SECSIZE] = { | ||||
0xbe, 0xd0, 0x07, 0xff, 0x3e, 0x60, 0x5e, 0x01, | 0xbe, 0xd0, 0x07, 0xff, 0x3e, 0x60, 0x5e, 0x01, | ||||
0x4b, 0xcf, 0x51, 0x81, 0x38, 0xdc, 0x3a, 0x25, | 0x4b, 0xcf, 0x51, 0x81, 0x38, 0xdc, 0x3a, 0x25, | ||||
0xc5, 0xe2, 0x36, 0x17, 0x1a, 0x2d, 0x01, 0xd6, | 0xc5, 0xe2, 0x36, 0x17, 0x1a, 0x2d, 0x01, 0xd6, | ||||
}; | }; | ||||
/* | /* | ||||
* Vector 7 from IEEE 1619/D16, blkno 0xfd. | * Vector 7 from IEEE 1619/D16, blkno 0xfd. | ||||
*/ | */ | ||||
static const uint8_t aes_xts_256_vec7_ptxt[SECSIZE] = { | static const uint8_t aes_xts_256_vec7_ptxt[SECSIZE] __aligned(4) = { | ||||
0x8e, 0x41, 0xb7, 0x8c, 0x39, 0x0b, 0x5a, 0xf9, | 0x8e, 0x41, 0xb7, 0x8c, 0x39, 0x0b, 0x5a, 0xf9, | ||||
0xd7, 0x58, 0xbb, 0x21, 0x4a, 0x67, 0xe9, 0xf6, | 0xd7, 0x58, 0xbb, 0x21, 0x4a, 0x67, 0xe9, 0xf6, | ||||
0xbf, 0x77, 0x27, 0xb0, 0x9a, 0xc6, 0x12, 0x40, | 0xbf, 0x77, 0x27, 0xb0, 0x9a, 0xc6, 0x12, 0x40, | ||||
0x84, 0xc3, 0x76, 0x11, 0x39, 0x8f, 0xa4, 0x5d, | 0x84, 0xc3, 0x76, 0x11, 0x39, 0x8f, 0xa4, 0x5d, | ||||
0xaa, 0xd9, 0x48, 0x68, 0x60, 0x0e, 0xd3, 0x91, | 0xaa, 0xd9, 0x48, 0x68, 0x60, 0x0e, 0xd3, 0x91, | ||||
0xfb, 0x1a, 0xcd, 0x48, 0x57, 0xa9, 0x5b, 0x46, | 0xfb, 0x1a, 0xcd, 0x48, 0x57, 0xa9, 0x5b, 0x46, | ||||
0x6e, 0x62, 0xef, 0x9f, 0x4b, 0x37, 0x72, 0x44, | 0x6e, 0x62, 0xef, 0x9f, 0x4b, 0x37, 0x72, 0x44, | ||||
0xd1, 0xc1, 0x52, 0xe7, 0xb3, 0x0d, 0x73, 0x1a, | 0xd1, 0xc1, 0x52, 0xe7, 0xb3, 0x0d, 0x73, 0x1a, | ||||
▲ Show 20 Lines • Show All 120 Lines • ▼ Show 20 Lines | static const uint8_t aes_xts_256_vec7_ctxt[SECSIZE] = { | ||||
0xb2, 0xe1, 0x22, 0xdd, 0xfd, 0x1c, 0xbd, 0xd1, | 0xb2, 0xe1, 0x22, 0xdd, 0xfd, 0x1c, 0xbd, 0xd1, | ||||
0x1d, 0x1c, 0x0a, 0x67, 0x83, 0xe0, 0x11, 0xfc, | 0x1d, 0x1c, 0x0a, 0x67, 0x83, 0xe0, 0x11, 0xfc, | ||||
0x53, 0x6d, 0x63, 0xd0, 0x53, 0x26, 0x06, 0x37, | 0x53, 0x6d, 0x63, 0xd0, 0x53, 0x26, 0x06, 0x37, | ||||
}; | }; | ||||
/* | /* | ||||
* Vector 8 from IEEE 1619/D16, blkno 0xfe. | * Vector 8 from IEEE 1619/D16, blkno 0xfe. | ||||
*/ | */ | ||||
static const uint8_t aes_xts_256_vec8_ptxt[SECSIZE] = { | static const uint8_t aes_xts_256_vec8_ptxt[SECSIZE] __aligned(4) = { | ||||
0xd5, 0x5f, 0x68, 0x4f, 0x81, 0xf4, 0x42, 0x6e, | 0xd5, 0x5f, 0x68, 0x4f, 0x81, 0xf4, 0x42, 0x6e, | ||||
0x9f, 0xde, 0x92, 0xa5, 0xff, 0x02, 0xdf, 0x2a, | 0x9f, 0xde, 0x92, 0xa5, 0xff, 0x02, 0xdf, 0x2a, | ||||
0xc8, 0x96, 0xaf, 0x63, 0x96, 0x28, 0x88, 0xa9, | 0xc8, 0x96, 0xaf, 0x63, 0x96, 0x28, 0x88, 0xa9, | ||||
0x79, 0x10, 0xc1, 0x37, 0x9e, 0x20, 0xb0, 0xa3, | 0x79, 0x10, 0xc1, 0x37, 0x9e, 0x20, 0xb0, 0xa3, | ||||
0xb1, 0xdb, 0x61, 0x3f, 0xb7, 0xfe, 0x2e, 0x07, | 0xb1, 0xdb, 0x61, 0x3f, 0xb7, 0xfe, 0x2e, 0x07, | ||||
0x00, 0x43, 0x29, 0xea, 0x5c, 0x22, 0xbf, 0xd3, | 0x00, 0x43, 0x29, 0xea, 0x5c, 0x22, 0xbf, 0xd3, | ||||
0x3e, 0x3d, 0xbe, 0x4c, 0xf5, 0x8c, 0xc6, 0x08, | 0x3e, 0x3d, 0xbe, 0x4c, 0xf5, 0x8c, 0xc6, 0x08, | ||||
0xc2, 0xc2, 0x6c, 0x19, 0xa2, 0xe2, 0xfe, 0x22, | 0xc2, 0xc2, 0x6c, 0x19, 0xa2, 0xe2, 0xfe, 0x22, | ||||
▲ Show 20 Lines • Show All 120 Lines • ▼ Show 20 Lines | static const uint8_t aes_xts_256_vec8_ctxt[SECSIZE] = { | ||||
0x50, 0x62, 0x23, 0xbe, 0xa1, 0x6a, 0xf3, 0x5c, | 0x50, 0x62, 0x23, 0xbe, 0xa1, 0x6a, 0xf3, 0x5c, | ||||
0x88, 0x3a, 0xcc, 0xdb, 0xe1, 0x10, 0x4e, 0xef, | 0x88, 0x3a, 0xcc, 0xdb, 0xe1, 0x10, 0x4e, 0xef, | ||||
0x0c, 0xfd, 0xb5, 0x4e, 0x12, 0xfb, 0x23, 0x0a, | 0x0c, 0xfd, 0xb5, 0x4e, 0x12, 0xfb, 0x23, 0x0a, | ||||
}; | }; | ||||
/* | /* | ||||
* Vector 9 from IEEE 1619/D16, blkno 0xff. | * Vector 9 from IEEE 1619/D16, blkno 0xff. | ||||
*/ | */ | ||||
static const uint8_t aes_xts_256_vec9_ptxt[SECSIZE] = { | static const uint8_t aes_xts_256_vec9_ptxt[SECSIZE] __aligned(4) = { | ||||
0x72, 0xef, 0xc1, 0xeb, 0xfe, 0x1e, 0xe2, 0x59, | 0x72, 0xef, 0xc1, 0xeb, 0xfe, 0x1e, 0xe2, 0x59, | ||||
0x75, 0xa6, 0xeb, 0x3a, 0xa8, 0x58, 0x9d, 0xda, | 0x75, 0xa6, 0xeb, 0x3a, 0xa8, 0x58, 0x9d, 0xda, | ||||
0x2b, 0x26, 0x1f, 0x1c, 0x85, 0xbd, 0xab, 0x44, | 0x2b, 0x26, 0x1f, 0x1c, 0x85, 0xbd, 0xab, 0x44, | ||||
0x2a, 0x9e, 0x5b, 0x2d, 0xd1, 0xd7, 0xc3, 0x95, | 0x2a, 0x9e, 0x5b, 0x2d, 0xd1, 0xd7, 0xc3, 0x95, | ||||
0x7a, 0x16, 0xfc, 0x08, 0xe5, 0x26, 0xd4, 0xb1, | 0x7a, 0x16, 0xfc, 0x08, 0xe5, 0x26, 0xd4, 0xb1, | ||||
0x22, 0x3f, 0x1b, 0x12, 0x32, 0xa1, 0x1a, 0xf2, | 0x22, 0x3f, 0x1b, 0x12, 0x32, 0xa1, 0x1a, 0xf2, | ||||
0x74, 0xc3, 0xd7, 0x0d, 0xac, 0x57, 0xf8, 0x3e, | 0x74, 0xc3, 0xd7, 0x0d, 0xac, 0x57, 0xf8, 0x3e, | ||||
0x09, 0x83, 0xc4, 0x98, 0xf1, 0xa6, 0xf1, 0xae, | 0x09, 0x83, 0xc4, 0x98, 0xf1, 0xa6, 0xf1, 0xae, | ||||
▲ Show 20 Lines • Show All 909 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
const char imgpath[] = "aes-xts-512.img"; | const char imgpath[] = "aes-xts-512.img"; | ||||
const char *dkpath = "/dev/dk"; | const char *dkpath = "/dev/dk"; | ||||
const size_t dksize = 65536 * SECSIZE; /* Last blkno is 0xffff. */ | const size_t dksize = 65536 * SECSIZE; /* Last blkno is 0xffff. */ | ||||
int dkfd, cgdfd; | int dkfd, cgdfd; | ||||
rump_init(); | rump_init(); | ||||
RL(dkfd = open_disk(dkpath, imgpath, dksize)); | dkfd = open_disk(dkpath, imgpath, dksize); | ||||
if (dkfd == -1 && errno == ENOSPC) { | |||||
atf_tc_skip("not enough space"); | |||||
} else { | |||||
ATF_CHECK_MSG(dkfd != -1, "open_disk: %s", strerror(errno)); | |||||
} | |||||
RL(cgdfd = open_cgd(0)); | RL(cgdfd = open_cgd(0)); | ||||
RL(configure_cgd(cgdfd, dkpath, "aes-xts", "encblkno1", | RL(configure_cgd(cgdfd, dkpath, "aes-xts", "encblkno1", | ||||
aes_xts_512_key, sizeof(aes_xts_512_key))); | aes_xts_512_key, sizeof(aes_xts_512_key))); | ||||
CHECK_LIBC(write_testvec(cgdfd, &aes_xts_512_vectors[0]), -1); | CHECK_LIBC(write_testvec(cgdfd, &aes_xts_512_vectors[0]), -1); | ||||
CHECK_LIBC(write_testvec(cgdfd, &aes_xts_512_vectors[1]), -1); | CHECK_LIBC(write_testvec(cgdfd, &aes_xts_512_vectors[1]), -1); | ||||
Show All 30 Lines |