MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / DecodeDSA_Signature

Function DecodeDSA_Signature

extra/yassl/taocrypt/src/asn.cpp:1195–1253  ·  view source on GitHub ↗

put sequence encoded dsa signature into decoded in 2 20 byte integers

Source from the content-addressed store, hash-verified

1193
1194// put sequence encoded dsa signature into decoded in 2 20 byte integers
1195word32 DecodeDSA_Signature(byte* decoded, const byte* encoded, word32 sz)
1196{
1197 Source source(encoded, sz);
1198
1199 if (source.next() != (SEQUENCE | CONSTRUCTED)) {
1200 source.SetError(SEQUENCE_E);
1201 return 0;
1202 }
1203
1204 GetLength(source); // total
1205
1206 // r
1207 if (source.next() != INTEGER) {
1208 source.SetError(INTEGER_E);
1209 return 0;
1210 }
1211 word32 rLen = GetLength(source);
1212 if (rLen != 20) {
1213 if (rLen == 21) { // zero at front, eat
1214 source.next();
1215 --rLen;
1216 }
1217 else if (rLen == 19) { // add zero to front so 20 bytes
1218 decoded[0] = 0;
1219 decoded++;
1220 }
1221 else {
1222 source.SetError(DSA_SZ_E);
1223 return 0;
1224 }
1225 }
1226 memcpy(decoded, source.get_buffer() + source.get_index(), rLen);
1227 source.advance(rLen);
1228
1229 // s
1230 if (source.next() != INTEGER) {
1231 source.SetError(INTEGER_E);
1232 return 0;
1233 }
1234 word32 sLen = GetLength(source);
1235 if (sLen != 20) {
1236 if (sLen == 21) {
1237 source.next(); // zero at front, eat
1238 --sLen;
1239 }
1240 else if (sLen == 19) {
1241 decoded[rLen] = 0; // add zero to front so 20 bytes
1242 decoded++;
1243 }
1244 else {
1245 source.SetError(DSA_SZ_E);
1246 return 0;
1247 }
1248 }
1249 memcpy(decoded + rLen, source.get_buffer() + source.get_index(), sLen);
1250 source.advance(sLen);
1251
1252 return 40;

Callers 4

dsa_testFunction · 0.85
asn.cppFile · 0.85
readMethod · 0.85
ProcessMethod · 0.85

Calls 6

GetLengthFunction · 0.85
get_indexMethod · 0.80
advanceMethod · 0.80
nextMethod · 0.45
SetErrorMethod · 0.45
get_bufferMethod · 0.45

Tested by 1

dsa_testFunction · 0.68