Skip to content

Instantly share code, notes, and snippets.

@paulsc
Created October 20, 2022 10:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulsc/01f122d80fb8e981dabd5a44a7933722 to your computer and use it in GitHub Desktop.
Save paulsc/01f122d80fb8e981dabd5a44a7933722 to your computer and use it in GitHub Desktop.
def verify(self, m, s):
if len(s) != self.bits//8:
raise Exception('incorrect signature length')
s = int.from_bytes(s, 'big')
k = pow(s, self.e, self.n)
k = int.to_bytes(k, self.bits//8, 'big')
if k[0] != 0x00:
raise Exception('incorrect prefix')
if k[1] != 0x01:
raise Exception('incorrect prefix')
padding, digest_info = k[2:].split(b'\x00', 1)
if len(padding) < 8:
raise Exception('invalid padding length')
if padding != b'\xff'*len(padding):
raise Exception('invalid padding content')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment