@@ -135,18 +135,24 @@ function extractSecretAndContext(params, mode) {
135135}
136136
137137function deriveKeyAndNonce ( params , mode ) {
138+ var padSize = params . padSize || PAD_SIZE ;
138139 var salt = extractSalt ( params . salt ) ;
139140 var s = extractSecretAndContext ( params , mode ) ;
140141 var prk = HKDF_extract ( salt , s . secret ) ;
141- var keyinfo = 'aesgcm' ;
142- if ( params . padSize === 2 ) {
143- keyinfo = 'aesgcm128' ;
144- } else if ( params . padSize && params . padSize !== 1 ) {
142+ var keyInfo ;
143+ var nonceInfo ;
144+ if ( padSize === 1 ) {
145+ keyInfo = 'Content-Encoding: aesgcm128' ;
146+ nonceInfo = 'Content-Encoding: nonce' ;
147+ } else if ( padSize === 2 ) {
148+ keyInfo = info ( 'aesgcm128' , s . context ) ;
149+ nonceInfo = info ( 'nonce' , s . context ) ;
150+ } else {
145151 throw new Error ( 'Unable to set context for padSize ' + params . padSize ) ;
146152 }
147153 var result = {
148- key : HKDF_expand ( prk , info ( keyinfo , s . context ) , KEY_LENGTH ) ,
149- nonce : HKDF_expand ( prk , info ( 'nonce' , s . context ) , NONCE_LENGTH )
154+ key : HKDF_expand ( prk , keyInfo , KEY_LENGTH ) ,
155+ nonce : HKDF_expand ( prk , nonceInfo , NONCE_LENGTH )
150156 } ;
151157 keylog ( 'key' , result . key ) ;
152158 keylog ( 'nonce base' , result . nonce ) ;
0 commit comments