diff options
author | Johan Hedberg <johan.hedberg@intel.com> | 2014-12-30 02:50:41 -0500 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2014-12-30 02:54:34 -0500 |
commit | fb2969a3a9a66a93f4c39e0c9f96e8bbb18e37a1 (patch) | |
tree | 45c98ad99da229589faf71eddcc65c0ae1678712 /net/bluetooth | |
parent | cfc4198e714fcee1a68c558d243e7e4f8de85577 (diff) |
Bluetooth: Add LE Secure Connections tests for SMP
This patch adds SMP self-tests for the Secure Connections crypto
functions. The sample data has been taken from the core specification.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Diffstat (limited to 'net/bluetooth')
-rw-r--r-- | net/bluetooth/smp.c | 186 |
1 files changed, 186 insertions, 0 deletions
diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c index f76c6d02b5b8..3a4333b5801a 100644 --- a/net/bluetooth/smp.c +++ b/net/bluetooth/smp.c | |||
@@ -3100,6 +3100,162 @@ static int __init test_s1(struct crypto_blkcipher *tfm_aes) | |||
3100 | return 0; | 3100 | return 0; |
3101 | } | 3101 | } |
3102 | 3102 | ||
3103 | static int __init test_f4(struct crypto_hash *tfm_cmac) | ||
3104 | { | ||
3105 | const u8 u[32] = { | ||
3106 | 0xe6, 0x9d, 0x35, 0x0e, 0x48, 0x01, 0x03, 0xcc, | ||
3107 | 0xdb, 0xfd, 0xf4, 0xac, 0x11, 0x91, 0xf4, 0xef, | ||
3108 | 0xb9, 0xa5, 0xf9, 0xe9, 0xa7, 0x83, 0x2c, 0x5e, | ||
3109 | 0x2c, 0xbe, 0x97, 0xf2, 0xd2, 0x03, 0xb0, 0x20 }; | ||
3110 | const u8 v[32] = { | ||
3111 | 0xfd, 0xc5, 0x7f, 0xf4, 0x49, 0xdd, 0x4f, 0x6b, | ||
3112 | 0xfb, 0x7c, 0x9d, 0xf1, 0xc2, 0x9a, 0xcb, 0x59, | ||
3113 | 0x2a, 0xe7, 0xd4, 0xee, 0xfb, 0xfc, 0x0a, 0x90, | ||
3114 | 0x9a, 0xbb, 0xf6, 0x32, 0x3d, 0x8b, 0x18, 0x55 }; | ||
3115 | const u8 x[16] = { | ||
3116 | 0xab, 0xae, 0x2b, 0x71, 0xec, 0xb2, 0xff, 0xff, | ||
3117 | 0x3e, 0x73, 0x77, 0xd1, 0x54, 0x84, 0xcb, 0xd5 }; | ||
3118 | const u8 z = 0x00; | ||
3119 | const u8 exp[16] = { | ||
3120 | 0x2d, 0x87, 0x74, 0xa9, 0xbe, 0xa1, 0xed, 0xf1, | ||
3121 | 0x1c, 0xbd, 0xa9, 0x07, 0xf1, 0x16, 0xc9, 0xf2 }; | ||
3122 | u8 res[16]; | ||
3123 | int err; | ||
3124 | |||
3125 | err = smp_f4(tfm_cmac, u, v, x, z, res); | ||
3126 | if (err) | ||
3127 | return err; | ||
3128 | |||
3129 | if (memcmp(res, exp, 16)) | ||
3130 | return -EINVAL; | ||
3131 | |||
3132 | return 0; | ||
3133 | } | ||
3134 | |||
3135 | static int __init test_f5(struct crypto_hash *tfm_cmac) | ||
3136 | { | ||
3137 | const u8 w[32] = { | ||
3138 | 0x98, 0xa6, 0xbf, 0x73, 0xf3, 0x34, 0x8d, 0x86, | ||
3139 | 0xf1, 0x66, 0xf8, 0xb4, 0x13, 0x6b, 0x79, 0x99, | ||
3140 | 0x9b, 0x7d, 0x39, 0x0a, 0xa6, 0x10, 0x10, 0x34, | ||
3141 | 0x05, 0xad, 0xc8, 0x57, 0xa3, 0x34, 0x02, 0xec }; | ||
3142 | const u8 n1[16] = { | ||
3143 | 0xab, 0xae, 0x2b, 0x71, 0xec, 0xb2, 0xff, 0xff, | ||
3144 | 0x3e, 0x73, 0x77, 0xd1, 0x54, 0x84, 0xcb, 0xd5 }; | ||
3145 | const u8 n2[16] = { | ||
3146 | 0xcf, 0xc4, 0x3d, 0xff, 0xf7, 0x83, 0x65, 0x21, | ||
3147 | 0x6e, 0x5f, 0xa7, 0x25, 0xcc, 0xe7, 0xe8, 0xa6 }; | ||
3148 | const u8 a1[7] = { 0xce, 0xbf, 0x37, 0x37, 0x12, 0x56, 0x00 }; | ||
3149 | const u8 a2[7] = { 0xc1, 0xcf, 0x2d, 0x70, 0x13, 0xa7, 0x00 }; | ||
3150 | const u8 exp_ltk[16] = { | ||
3151 | 0x38, 0x0a, 0x75, 0x94, 0xb5, 0x22, 0x05, 0x98, | ||
3152 | 0x23, 0xcd, 0xd7, 0x69, 0x11, 0x79, 0x86, 0x69 }; | ||
3153 | const u8 exp_mackey[16] = { | ||
3154 | 0x20, 0x6e, 0x63, 0xce, 0x20, 0x6a, 0x3f, 0xfd, | ||
3155 | 0x02, 0x4a, 0x08, 0xa1, 0x76, 0xf1, 0x65, 0x29 }; | ||
3156 | u8 mackey[16], ltk[16]; | ||
3157 | int err; | ||
3158 | |||
3159 | err = smp_f5(tfm_cmac, w, n1, n2, a1, a2, mackey, ltk); | ||
3160 | if (err) | ||
3161 | return err; | ||
3162 | |||
3163 | if (memcmp(mackey, exp_mackey, 16)) | ||
3164 | return -EINVAL; | ||
3165 | |||
3166 | if (memcmp(ltk, exp_ltk, 16)) | ||
3167 | return -EINVAL; | ||
3168 | |||
3169 | return 0; | ||
3170 | } | ||
3171 | |||
3172 | static int __init test_f6(struct crypto_hash *tfm_cmac) | ||
3173 | { | ||
3174 | const u8 w[16] = { | ||
3175 | 0x20, 0x6e, 0x63, 0xce, 0x20, 0x6a, 0x3f, 0xfd, | ||
3176 | 0x02, 0x4a, 0x08, 0xa1, 0x76, 0xf1, 0x65, 0x29 }; | ||
3177 | const u8 n1[16] = { | ||
3178 | 0xab, 0xae, 0x2b, 0x71, 0xec, 0xb2, 0xff, 0xff, | ||
3179 | 0x3e, 0x73, 0x77, 0xd1, 0x54, 0x84, 0xcb, 0xd5 }; | ||
3180 | const u8 n2[16] = { | ||
3181 | 0xcf, 0xc4, 0x3d, 0xff, 0xf7, 0x83, 0x65, 0x21, | ||
3182 | 0x6e, 0x5f, 0xa7, 0x25, 0xcc, 0xe7, 0xe8, 0xa6 }; | ||
3183 | const u8 r[16] = { | ||
3184 | 0xc8, 0x0f, 0x2d, 0x0c, 0xd2, 0x42, 0xda, 0x08, | ||
3185 | 0x54, 0xbb, 0x53, 0xb4, 0x3b, 0x34, 0xa3, 0x12 }; | ||
3186 | const u8 io_cap[3] = { 0x02, 0x01, 0x01 }; | ||
3187 | const u8 a1[7] = { 0xce, 0xbf, 0x37, 0x37, 0x12, 0x56, 0x00 }; | ||
3188 | const u8 a2[7] = { 0xc1, 0xcf, 0x2d, 0x70, 0x13, 0xa7, 0x00 }; | ||
3189 | const u8 exp[16] = { | ||
3190 | 0x61, 0x8f, 0x95, 0xda, 0x09, 0x0b, 0x6c, 0xd2, | ||
3191 | 0xc5, 0xe8, 0xd0, 0x9c, 0x98, 0x73, 0xc4, 0xe3 }; | ||
3192 | u8 res[16]; | ||
3193 | int err; | ||
3194 | |||
3195 | err = smp_f6(tfm_cmac, w, n1, n2, r, io_cap, a1, a2, res); | ||
3196 | if (err) | ||
3197 | return err; | ||
3198 | |||
3199 | if (memcmp(res, exp, 16)) | ||
3200 | return -EINVAL; | ||
3201 | |||
3202 | return 0; | ||
3203 | } | ||
3204 | |||
3205 | static int __init test_g2(struct crypto_hash *tfm_cmac) | ||
3206 | { | ||
3207 | const u8 u[32] = { | ||
3208 | 0xe6, 0x9d, 0x35, 0x0e, 0x48, 0x01, 0x03, 0xcc, | ||
3209 | 0xdb, 0xfd, 0xf4, 0xac, 0x11, 0x91, 0xf4, 0xef, | ||
3210 | 0xb9, 0xa5, 0xf9, 0xe9, 0xa7, 0x83, 0x2c, 0x5e, | ||
3211 | 0x2c, 0xbe, 0x97, 0xf2, 0xd2, 0x03, 0xb0, 0x20 }; | ||
3212 | const u8 v[32] = { | ||
3213 | 0xfd, 0xc5, 0x7f, 0xf4, 0x49, 0xdd, 0x4f, 0x6b, | ||
3214 | 0xfb, 0x7c, 0x9d, 0xf1, 0xc2, 0x9a, 0xcb, 0x59, | ||
3215 | 0x2a, 0xe7, 0xd4, 0xee, 0xfb, 0xfc, 0x0a, 0x90, | ||
3216 | 0x9a, 0xbb, 0xf6, 0x32, 0x3d, 0x8b, 0x18, 0x55 }; | ||
3217 | const u8 x[16] = { | ||
3218 | 0xab, 0xae, 0x2b, 0x71, 0xec, 0xb2, 0xff, 0xff, | ||
3219 | 0x3e, 0x73, 0x77, 0xd1, 0x54, 0x84, 0xcb, 0xd5 }; | ||
3220 | const u8 y[16] = { | ||
3221 | 0xcf, 0xc4, 0x3d, 0xff, 0xf7, 0x83, 0x65, 0x21, | ||
3222 | 0x6e, 0x5f, 0xa7, 0x25, 0xcc, 0xe7, 0xe8, 0xa6 }; | ||
3223 | const u32 exp_val = 0x2f9ed5ba % 1000000; | ||
3224 | u32 val; | ||
3225 | int err; | ||
3226 | |||
3227 | err = smp_g2(tfm_cmac, u, v, x, y, &val); | ||
3228 | if (err) | ||
3229 | return err; | ||
3230 | |||
3231 | if (val != exp_val) | ||
3232 | return -EINVAL; | ||
3233 | |||
3234 | return 0; | ||
3235 | } | ||
3236 | |||
3237 | static int __init test_h6(struct crypto_hash *tfm_cmac) | ||
3238 | { | ||
3239 | const u8 w[16] = { | ||
3240 | 0x9b, 0x7d, 0x39, 0x0a, 0xa6, 0x10, 0x10, 0x34, | ||
3241 | 0x05, 0xad, 0xc8, 0x57, 0xa3, 0x34, 0x02, 0xec }; | ||
3242 | const u8 key_id[4] = { 0x72, 0x62, 0x65, 0x6c }; | ||
3243 | const u8 exp[16] = { | ||
3244 | 0x99, 0x63, 0xb1, 0x80, 0xe2, 0xa9, 0xd3, 0xe8, | ||
3245 | 0x1c, 0xc9, 0x6d, 0xe7, 0x02, 0xe1, 0x9a, 0x2d }; | ||
3246 | u8 res[16]; | ||
3247 | int err; | ||
3248 | |||
3249 | err = smp_h6(tfm_cmac, w, key_id, res); | ||
3250 | if (err) | ||
3251 | return err; | ||
3252 | |||
3253 | if (memcmp(res, exp, 16)) | ||
3254 | return -EINVAL; | ||
3255 | |||
3256 | return 0; | ||
3257 | } | ||
3258 | |||
3103 | static int __init run_selftests(struct crypto_blkcipher *tfm_aes, | 3259 | static int __init run_selftests(struct crypto_blkcipher *tfm_aes, |
3104 | struct crypto_hash *tfm_cmac) | 3260 | struct crypto_hash *tfm_cmac) |
3105 | { | 3261 | { |
@@ -3123,6 +3279,36 @@ static int __init run_selftests(struct crypto_blkcipher *tfm_aes, | |||
3123 | return err; | 3279 | return err; |
3124 | } | 3280 | } |
3125 | 3281 | ||
3282 | err = test_f4(tfm_cmac); | ||
3283 | if (err) { | ||
3284 | BT_ERR("smp_f4 test failed"); | ||
3285 | return err; | ||
3286 | } | ||
3287 | |||
3288 | err = test_f5(tfm_cmac); | ||
3289 | if (err) { | ||
3290 | BT_ERR("smp_f5 test failed"); | ||
3291 | return err; | ||
3292 | } | ||
3293 | |||
3294 | err = test_f6(tfm_cmac); | ||
3295 | if (err) { | ||
3296 | BT_ERR("smp_f6 test failed"); | ||
3297 | return err; | ||
3298 | } | ||
3299 | |||
3300 | err = test_g2(tfm_cmac); | ||
3301 | if (err) { | ||
3302 | BT_ERR("smp_g2 test failed"); | ||
3303 | return err; | ||
3304 | } | ||
3305 | |||
3306 | err = test_h6(tfm_cmac); | ||
3307 | if (err) { | ||
3308 | BT_ERR("smp_h6 test failed"); | ||
3309 | return err; | ||
3310 | } | ||
3311 | |||
3126 | BT_INFO("SMP test passed"); | 3312 | BT_INFO("SMP test passed"); |
3127 | 3313 | ||
3128 | return 0; | 3314 | return 0; |