@@ -23,6 +23,53 @@ function define_tests() {
23
23
"X448" : new Uint8Array ( [ 240 , 246 , 197 , 241 , 127 , 148 , 244 , 41 , 30 , 171 , 113 , 120 , 134 , 109 , 55 , 236 , 137 , 6 , 221 , 108 , 81 , 65 , 67 , 220 , 133 , 190 , 124 , 242 , 141 , 239 , 243 , 155 , 114 , 110 , 15 , 109 , 207 , 129 , 14 , 181 , 148 , 220 , 169 , 123 , 72 , 130 , 189 , 68 , 196 , 62 , 167 , 220 , 103 , 244 , 154 , 78 ] )
24
24
} ;
25
25
26
+ var kSmallOrderPoint = {
27
+ "X25519" : [
28
+ { order : "0" , vector : new Uint8Array ( [ 48 , 42 , 48 , 5 , 6 , 3 , 43 , 101 , 110 , 3 , 33 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ) } ,
29
+ { order : "1" , vector : new Uint8Array ( [ 48 , 42 , 48 , 5 , 6 , 3 , 43 , 101 , 110 , 3 , 33 , 0 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ) } ,
30
+ { order : "8" , vector : new Uint8Array ( [ 48 , 42 , 48 , 5 , 6 , 3 , 43 , 101 , 110 , 3 , 33 , 0 , 224 , 235 , 122 , 124 , 59 , 65 , 184 , 174 , 22 , 86 , 227 , 250 , 241 , 159 , 196 , 106 , 218 , 9 , 141 , 235 , 156 , 50 , 177 , 253 , 134 , 98 , 5 , 22 , 95 , 73 , 184 , 0 ] ) } ,
31
+ { order : "p-1 (order 2)" , vector : new Uint8Array ( [ 48 , 42 , 48 , 5 , 6 , 3 , 43 , 101 , 110 , 3 , 33 , 0 , 236 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 127 ] ) } ,
32
+ { order : "p (=0, order 4)" , vector : new Uint8Array ( [ 48 , 42 , 48 , 5 , 6 , 3 , 43 , 101 , 110 , 3 , 33 , 0 , 237 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 127 ] ) } ,
33
+ { order : "p+1 (=1, order 1)" , vector : new Uint8Array ( [ 48 , 42 , 48 , 5 , 6 , 3 , 43 , 101 , 110 , 3 , 33 , 0 , 238 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 127 ] ) } ,
34
+ ] ,
35
+ "X448" : [
36
+ { order : "0" , vector : new Uint8Array ( [ 48 , 66 , 48 , 5 , 6 , 3 , 43 , 101 , 111 , 3 , 57 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ) } ,
37
+ { order : "1" , vector : new Uint8Array ( [ 48 , 66 , 48 , 5 , 6 , 3 , 43 , 101 , 111 , 3 , 57 , 0 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ) } ,
38
+ { order : "p-1 (order 2)" , vector : new Uint8Array ( [ 48 , 66 , 48 , 5 , 6 , 3 , 43 , 101 , 111 , 3 , 57 , 0 , 254 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 254 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 ] ) } ,
39
+ { order : "p (=0, order 4)" , vector : new Uint8Array ( [ 48 , 66 , 48 , 5 , 6 , 3 , 43 , 101 , 111 , 3 , 57 , 0 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 254 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 ] ) } ,
40
+ { order : "p+1 (=1, order 1)" , vector : new Uint8Array ( [ 48 , 66 , 48 , 5 , 6 , 3 , 43 , 101 , 111 , 3 , 57 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 ] ) } ,
41
+ ]
42
+ } ;
43
+
44
+ // Verify the derive functions perform checks against the all-zero value results,
45
+ // ensuring small-order points are rejected.
46
+ // https://www.rfc-editor.org/rfc/rfc7748#section-6.1
47
+ // TODO: The spec states that the check must be done on use, but there is discussion about doing it on import.
48
+ // https://github.com/WICG/webcrypto-secure-curves/pull/13
49
+ Object . keys ( kSmallOrderPoint ) . forEach ( function ( algorithmName ) {
50
+ kSmallOrderPoint [ algorithmName ] . forEach ( function ( test ) {
51
+ promise_test ( async ( ) => {
52
+ let derived ;
53
+ let privateKey = await subtle . importKey ( "pkcs8" , pkcs8 [ algorithmName ] ,
54
+ { name : algorithmName } ,
55
+ false , [ "deriveBits" , "deriveKey" ] ) ;
56
+ let publicKey = await subtle . importKey ( "spki" , test . vector ,
57
+ { name : algorithmName } ,
58
+ false , [ ] )
59
+ try {
60
+ derived = await subtle . deriveKey ( { name : algorithmName , public : publicKey } , privateKey ,
61
+ { name : "HMAC" , hash : "SHA-256" , length : 256 } , true ,
62
+ [ "sign" , "verify" ] ) ;
63
+ } catch ( err ) {
64
+ assert_false ( privateKey === undefined , "Private key should be valid." ) ;
65
+ assert_false ( publicKey === undefined , "Public key should be valid." ) ;
66
+ assert_equals ( err . name , "OperationError" , "Should throw correct error, not " + err . name + ": " + err . message + "." ) ;
67
+ }
68
+ assert_equals ( derived , undefined , "Operation succeeded, but should not have." ) ;
69
+ } , algorithmName + " key derivation checks for all-zero value result with a key of order " + test . order ) ;
70
+ } ) ;
71
+ } ) ;
72
+
26
73
return importKeys ( pkcs8 , spki , sizes )
27
74
. then ( function ( results ) {
28
75
publicKeys = results . publicKeys ;
0 commit comments