A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/openpgpjs/openpgpjs/commit/357d49f7e9fa3268bf39fdda5a45feba898dfd68 below:

OP-01-026 Errors in EMSA-PKCS1-v1_5 decoding routine (High) and OP-01… · openpgpjs/openpgpjs@357d49f · GitHub

@@ -91,7 +91,6 @@ module.exports = {

91 91

result += message;

92 92

return result;

93 93

},

94 - 95 94

/**

96 95

* decodes a EME-PKCS1-v1_5 padding (See {@link http://tools.ietf.org/html/rfc4880#section-13.1.2|RFC 4880 13.1.2})

97 96

* @param {String} message EME-PKCS1 padded message

@@ -110,53 +109,47 @@ module.exports = {

110 109

},

111 110 112 111

emsa: {

113 - 114 112

/**

115 113

* create a EMSA-PKCS1-v1_5 padding (See {@link http://tools.ietf.org/html/rfc4880#section-13.1.3|RFC 4880 13.1.3})

116 114

* @param {Integer} algo Hash algorithm type used

117 -

* @param {String} data Data to be hashed

118 -

* @param {Integer} keylength Key size of the public mpi in bytes

119 -

* @returns {String} Hashcode with pkcs1padding as string

115 +

* @param {String} M message to be encoded

116 +

* @param {Integer} emLen intended length in octets of the encoded message

117 +

* @returns {String} encoded message

120 118

*/

121 -

encode: function(algo, data, keylength) {

122 -

var data2 = "";

123 -

data2 += String.fromCharCode(0x00);

124 -

data2 += String.fromCharCode(0x01);

119 +

encode: function(algo, M, emLen) {

125 120

var i;

126 -

for (i = 0; i < (keylength - hash_headers[algo].length - 3 -

127 -

hash.getHashByteLength(algo)); i++)

128 - 129 -

data2 += String.fromCharCode(0xff);

130 - 131 -

data2 += String.fromCharCode(0x00);

132 - 133 -

for (i = 0; i < hash_headers[algo].length; i++)

134 -

data2 += String.fromCharCode(hash_headers[algo][i]);

135 - 136 -

data2 += hash.digest(algo, data);

137 -

return new BigInteger(util.hexstrdump(data2), 16);

138 -

},

139 - 140 -

/**

141 -

* extract the hash out of an EMSA-PKCS1-v1.5 padding (See {@link http://tools.ietf.org/html/rfc4880#section-13.1.3|RFC 4880 13.1.3})

142 -

* @param {String} data Hash in pkcs1 encoding

143 -

* @returns {String} The hash as string

144 -

*/

145 -

decode: function(algo, data) {

146 -

var i = 0;

147 -

if (data.charCodeAt(0) === 0) i++;

148 -

else if (data.charCodeAt(0) != 1) return -1;

149 -

else i++;

150 - 151 -

while (data.charCodeAt(i) == 0xFF) i++;

152 -

if (data.charCodeAt(i++) !== 0) return -1;

153 -

var j = 0;

154 -

for (j = 0; j < hash_headers[algo].length && j + i < data.length; j++) {

155 -

if (data.charCodeAt(j + i) != hash_headers[algo][j]) return -1;

121 +

// Apply the hash function to the message M to produce a hash value H

122 +

var H = hash.digest(algo, M);

123 +

if (H.length !== hash.getHashByteLength(algo)) {

124 +

throw new Error('Invalid hash length');

125 +

}

126 +

// produce an ASN.1 DER value for the hash function used.

127 +

// Let T be the full hash prefix

128 +

var T = '';

129 +

for (i = 0; i < hash_headers[algo].length; i++) {

130 +

T += String.fromCharCode(hash_headers[algo][i]);

131 +

}

132 +

// add hash value to prefix

133 +

T += H;

134 +

// and let tLen be the length in octets of T

135 +

var tLen = T.length;

136 +

if (emLen < tLen + 11) {

137 +

throw new Error('Intended encoded message length too short');

138 +

}

139 +

// an octet string PS consisting of emLen - tLen - 3 octets with hexadecimal value 0xFF

140 +

// The length of PS will be at least 8 octets

141 +

var PS = '';

142 +

for (i = 0; i < (emLen - tLen - 3); i++) {

143 +

PS += String.fromCharCode(0xff);

156 144

}

157 -

i += j;

158 -

if (data.substring(i).length < hash.getHashByteLength(algo)) return -1;

159 -

return data.substring(i);

145 +

// Concatenate PS, the hash prefix T, and other padding to form the

146 +

// encoded message EM as EM = 0x00 || 0x01 || PS || 0x00 || T.

147 +

var EM = String.fromCharCode(0x00) +

148 +

String.fromCharCode(0x01) +

149 +

PS +

150 +

String.fromCharCode(0x00) +

151 +

T;

152 +

return new BigInteger(util.hexstrdump(EM), 16);

160 153

}

161 154

}

162 155

};


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4