Loosely correlates with IsLowDERSignature() from script/interpreter.cpp Verifies that the S value in a DER signature is the lowest possible value. Used by BIP62 malleability fixes.
(sig)
| 866 | return CScript(r) |
| 867 | |
| 868 | def IsLowDERSignature(sig): |
| 869 | """ |
| 870 | Loosely correlates with IsLowDERSignature() from script/interpreter.cpp |
| 871 | Verifies that the S value in a DER signature is the lowest possible value. |
| 872 | Used by BIP62 malleability fixes. |
| 873 | """ |
| 874 | length_r = sig[3] |
| 875 | if isinstance(length_r, str): |
| 876 | length_r = int(struct.unpack('B', length_r)[0]) |
| 877 | length_s = sig[5 + length_r] |
| 878 | if isinstance(length_s, str): |
| 879 | length_s = int(struct.unpack('B', length_s)[0]) |
| 880 | s_val = list(struct.unpack(str(length_s) + 'B', sig[6 + length_r:6 + length_r + length_s])) |
| 881 | |
| 882 | # If the S value is above the order of the curve divided by two, its |
| 883 | # complement modulo the order could have been used instead, which is |
| 884 | # one byte shorter when encoded correctly. |
| 885 | max_mod_half_order = [ |
| 886 | 0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff, |
| 887 | 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, |
| 888 | 0x5d,0x57,0x6e,0x73,0x57,0xa4,0x50,0x1d, |
| 889 | 0xdf,0xe9,0x2f,0x46,0x68,0x1b,0x20,0xa0] |
| 890 | |
| 891 | return CompareBigEndian(s_val, [0]) > 0 and \ |
| 892 | CompareBigEndian(s_val, max_mod_half_order) <= 0 |
| 893 | |
| 894 | def CompareBigEndian(c1, c2): |
| 895 | """ |