Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev Add self-tests for 3des and blowfish too.



details:   https://anonhg.NetBSD.org/src/rev/c32e15ea295e
branches:  trunk
changeset: 934043:c32e15ea295e
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Thu Jun 04 19:54:53 2020 +0000

description:
Add self-tests for 3des and blowfish too.

Nobody should use these on new disks but it is good to have them so
we don't break decrypting old disks.

diffstat:

 sys/dev/cgd.c |  161 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 158 insertions(+), 3 deletions(-)

diffs (189 lines):

diff -r ff6093bbc672 -r c32e15ea295e sys/dev/cgd.c
--- a/sys/dev/cgd.c     Thu Jun 04 19:53:55 2020 +0000
+++ b/sys/dev/cgd.c     Thu Jun 04 19:54:53 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cgd.c,v 1.125 2020/04/13 08:05:02 maxv Exp $ */
+/* $NetBSD: cgd.c,v 1.126 2020/06/04 19:54:53 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cgd.c,v 1.125 2020/04/13 08:05:02 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cgd.c,v 1.126 2020/06/04 19:54:53 riastradh Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -180,6 +180,117 @@
        0
 };
 
+static const uint8_t selftest_aes_cbc_key[32] = {
+       0x27, 0x18, 0x28, 0x18, 0x28, 0x45, 0x90, 0x45,
+       0x23, 0x53, 0x60, 0x28, 0x74, 0x71, 0x35, 0x26,
+       0x62, 0x49, 0x77, 0x57, 0x24, 0x70, 0x93, 0x69,
+       0x99, 0x59, 0x57, 0x49, 0x66, 0x96, 0x76, 0x27,
+};
+
+static const uint8_t selftest_aes_cbc_128_ptxt[64] = {
+       0x27, 0xa7, 0x47, 0x9b, 0xef, 0xa1, 0xd4, 0x76,
+       0x48, 0x9f, 0x30, 0x8c, 0xd4, 0xcf, 0xa6, 0xe2,
+       0xa9, 0x6e, 0x4b, 0xbe, 0x32, 0x08, 0xff, 0x25,
+       0x28, 0x7d, 0xd3, 0x81, 0x96, 0x16, 0xe8, 0x9c,
+       0xc7, 0x8c, 0xf7, 0xf5, 0xe5, 0x43, 0x44, 0x5f,
+       0x83, 0x33, 0xd8, 0xfa, 0x7f, 0x56, 0x00, 0x00,
+       0x05, 0x27, 0x9f, 0xa5, 0xd8, 0xb5, 0xe4, 0xad,
+       0x40, 0xe7, 0x36, 0xdd, 0xb4, 0xd3, 0x54, 0x12,
+};
+
+static const uint8_t selftest_aes_cbc_128_ctxt[64] = { /* blkno=1 */
+       0x93, 0x94, 0x56, 0x36, 0x83, 0xbc, 0xff, 0xa4,
+       0xe0, 0x24, 0x34, 0x12, 0xbe, 0xfa, 0xb0, 0x7d,
+       0x88, 0x1e, 0xc5, 0x57, 0x55, 0x23, 0x05, 0x0c,
+       0x69, 0xa5, 0xc1, 0xda, 0x64, 0xee, 0x74, 0x10,
+       0xc2, 0xc5, 0xe6, 0x66, 0xd6, 0xa7, 0x49, 0x1c,
+       0x9d, 0x40, 0xb5, 0x0c, 0x9b, 0x6e, 0x1c, 0xe6,
+       0xb1, 0x7a, 0x1c, 0xe7, 0x5a, 0xfe, 0xf9, 0x2a,
+       0x78, 0xfa, 0xb7, 0x7b, 0x08, 0xdf, 0x8e, 0x51,
+};
+
+static const uint8_t selftest_aes_cbc_256_ptxt[64] = {
+       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,
+       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,
+};
+
+static const uint8_t selftest_aes_cbc_256_ctxt[64] = { /* blkno=0xffff */
+       0x6c, 0xa3, 0x15, 0x17, 0x51, 0x90, 0xe9, 0x69,
+       0x08, 0x36, 0x7b, 0xa6, 0xbb, 0xd1, 0x0b, 0x9e,
+       0xcd, 0x6b, 0x1e, 0xaf, 0xb6, 0x2e, 0x62, 0x7d,
+       0x8e, 0xde, 0xf0, 0xed, 0x0d, 0x44, 0xe7, 0x31,
+       0x26, 0xcf, 0xd5, 0x0b, 0x3e, 0x95, 0x59, 0x89,
+       0xdf, 0x5d, 0xd6, 0x9a, 0x00, 0x66, 0xcc, 0x7f,
+       0x45, 0xd3, 0x06, 0x58, 0xed, 0xef, 0x49, 0x47,
+       0x87, 0x89, 0x17, 0x7d, 0x08, 0x56, 0x50, 0xe1,
+};
+
+static const uint8_t selftest_3des_cbc_key[24] = {
+       0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+       0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+       0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+};
+
+static const uint8_t selftest_3des_cbc_ptxt[64] = {
+       0x27, 0xa7, 0x47, 0x9b, 0xef, 0xa1, 0xd4, 0x76,
+       0x48, 0x9f, 0x30, 0x8c, 0xd4, 0xcf, 0xa6, 0xe2,
+       0xa9, 0x6e, 0x4b, 0xbe, 0x32, 0x08, 0xff, 0x25,
+       0x28, 0x7d, 0xd3, 0x81, 0x96, 0x16, 0xe8, 0x9c,
+       0xc7, 0x8c, 0xf7, 0xf5, 0xe5, 0x43, 0x44, 0x5f,
+       0x83, 0x33, 0xd8, 0xfa, 0x7f, 0x56, 0x00, 0x00,
+       0x05, 0x27, 0x9f, 0xa5, 0xd8, 0xb5, 0xe4, 0xad,
+       0x40, 0xe7, 0x36, 0xdd, 0xb4, 0xd3, 0x54, 0x12,
+};
+
+static const uint8_t selftest_3des_cbc_ctxt[64] = {
+       0xa2, 0xfe, 0x81, 0xaa, 0x10, 0x6c, 0xea, 0xb9,
+       0x11, 0x58, 0x1f, 0x29, 0xb5, 0x86, 0x71, 0x56,
+       0xe9, 0x25, 0x1d, 0x07, 0xb1, 0x69, 0x59, 0x6c,
+       0x96, 0x80, 0xf7, 0x54, 0x38, 0xaa, 0xa7, 0xe4,
+       0xe8, 0x81, 0xf5, 0x00, 0xbb, 0x1c, 0x00, 0x3c,
+       0xba, 0x38, 0x45, 0x97, 0x4c, 0xcf, 0x84, 0x14,
+       0x46, 0x86, 0xd9, 0xf4, 0xc5, 0xe2, 0xf0, 0x54,
+       0xde, 0x41, 0xf6, 0xa1, 0xef, 0x1b, 0x0a, 0xea,
+};
+
+static const uint8_t selftest_bf_cbc_key[56] = {
+       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,
+       0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
+       0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
+       0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
+};
+
+static const uint8_t selftest_bf_cbc_ptxt[64] = {
+       0x27, 0xa7, 0x47, 0x9b, 0xef, 0xa1, 0xd4, 0x76,
+       0x48, 0x9f, 0x30, 0x8c, 0xd4, 0xcf, 0xa6, 0xe2,
+       0xa9, 0x6e, 0x4b, 0xbe, 0x32, 0x08, 0xff, 0x25,
+       0x28, 0x7d, 0xd3, 0x81, 0x96, 0x16, 0xe8, 0x9c,
+       0xc7, 0x8c, 0xf7, 0xf5, 0xe5, 0x43, 0x44, 0x5f,
+       0x83, 0x33, 0xd8, 0xfa, 0x7f, 0x56, 0x00, 0x00,
+       0x05, 0x27, 0x9f, 0xa5, 0xd8, 0xb5, 0xe4, 0xad,
+       0x40, 0xe7, 0x36, 0xdd, 0xb4, 0xd3, 0x54, 0x12,
+};
+
+static const uint8_t selftest_bf_cbc_ctxt[64] = {
+       0xec, 0xa2, 0xc0, 0x0e, 0xa9, 0x7f, 0x04, 0x1e,
+       0x2e, 0x4f, 0x64, 0x07, 0x67, 0x3e, 0xf4, 0x58,
+       0x61, 0x5f, 0xd3, 0x50, 0x5e, 0xd3, 0x4d, 0x34,
+       0xa0, 0x53, 0xbe, 0x47, 0x75, 0x69, 0x3b, 0x1f,
+       0x86, 0xf2, 0xae, 0x8b, 0xb7, 0x91, 0xda, 0xd4,
+       0x2b, 0xa5, 0x47, 0x9b, 0x7d, 0x13, 0x30, 0xdd,
+       0x7b, 0xad, 0x86, 0x57, 0x51, 0x11, 0x74, 0x42,
+       0xb8, 0xbf, 0x69, 0x17, 0x20, 0x0a, 0xf7, 0xda,
+};
+
 const struct selftest_params selftests[] = {
        {
                .alg = "aes-xts",
@@ -202,7 +313,51 @@
                .key  = selftest_aes_xts_512_key,
                .ptxt = selftest_aes_xts_512_ptxt,
                .ctxt = selftest_aes_xts_512_ctxt
-       }
+       },
+       {
+               .alg = "aes-cbc",
+               .blocksize = 16,
+               .secsize = 512,
+               .blkno = 1,
+               .keylen = 128,
+               .txtlen = sizeof(selftest_aes_cbc_128_ptxt),
+               .key  = selftest_aes_cbc_key,
+               .ptxt = selftest_aes_cbc_128_ptxt,
+               .ctxt = selftest_aes_cbc_128_ctxt,
+       },
+       {
+               .alg = "aes-cbc",
+               .blocksize = 16,
+               .secsize = 512,
+               .blkno = 0xffff,
+               .keylen = 256,
+               .txtlen = sizeof(selftest_aes_cbc_256_ptxt),
+               .key  = selftest_aes_cbc_key,
+               .ptxt = selftest_aes_cbc_256_ptxt,
+               .ctxt = selftest_aes_cbc_256_ctxt,
+       },
+       {
+               .alg = "3des-cbc",
+               .blocksize = 8,
+               .secsize = 512,
+               .blkno = 1,
+               .keylen = 192,  /* 168 + 3*8 parity bits */
+               .txtlen = sizeof(selftest_3des_cbc_ptxt),
+               .key  = selftest_3des_cbc_key,
+               .ptxt = selftest_3des_cbc_ptxt,
+               .ctxt = selftest_3des_cbc_ctxt,
+       },
+       {
+               .alg = "blowfish-cbc",
+               .blocksize = 8,
+               .secsize = 512,
+               .blkno = 1,
+               .keylen = 448,
+               .txtlen = sizeof(selftest_bf_cbc_ptxt),
+               .key  = selftest_bf_cbc_key,
+               .ptxt = selftest_bf_cbc_ptxt,
+               .ctxt = selftest_bf_cbc_ctxt,
+       },
 };
 
 static int cgd_match(device_t, cfdata_t, void *);



Home | Main Index | Thread Index | Old Index