| OLD | NEW |
| 1 """Abstract class for RSA.""" | 1 """Abstract class for RSA.""" |
| 2 | 2 |
| 3 from cryptomath import * | 3 from cryptomath import * |
| 4 | 4 |
| 5 | 5 |
| 6 class RSAKey: | 6 class RSAKey: |
| 7 """This is an abstract base class for RSA keys. | 7 """This is an abstract base class for RSA keys. |
| 8 | 8 |
| 9 Particular implementations of RSA keys, such as | 9 Particular implementations of RSA keys, such as |
| 10 L{OpenSSL_RSAKey.OpenSSL_RSAKey}, | 10 L{OpenSSL_RSAKey.OpenSSL_RSAKey}, |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 @rtype: L{array.array} of unsigned bytes. | 110 @rtype: L{array.array} of unsigned bytes. |
| 111 @return: A PKCS1 signature on the passed-in data. | 111 @return: A PKCS1 signature on the passed-in data. |
| 112 """ | 112 """ |
| 113 if not self.hasPrivateKey(): | 113 if not self.hasPrivateKey(): |
| 114 raise AssertionError() | 114 raise AssertionError() |
| 115 paddedBytes = self._addPKCS1Padding(bytes, 1) | 115 paddedBytes = self._addPKCS1Padding(bytes, 1) |
| 116 m = bytesToNumber(paddedBytes) | 116 m = bytesToNumber(paddedBytes) |
| 117 if m >= self.n: | 117 if m >= self.n: |
| 118 raise ValueError() | 118 raise ValueError() |
| 119 c = self._rawPrivateKeyOp(m) | 119 c = self._rawPrivateKeyOp(m) |
| 120 sigBytes = numberToBytes(c) | 120 sigBytes = numberToBytes(c, numBytes(self.n)) |
| 121 return sigBytes | 121 return sigBytes |
| 122 | 122 |
| 123 def verify(self, sigBytes, bytes): | 123 def verify(self, sigBytes, bytes): |
| 124 """Verify the passed-in bytes with the signature. | 124 """Verify the passed-in bytes with the signature. |
| 125 | 125 |
| 126 This verifies a PKCS1 signature on the passed-in data. | 126 This verifies a PKCS1 signature on the passed-in data. |
| 127 | 127 |
| 128 @type sigBytes: L{array.array} of unsigned bytes | 128 @type sigBytes: L{array.array} of unsigned bytes |
| 129 @param sigBytes: A PKCS1 signature. | 129 @param sigBytes: A PKCS1 signature. |
| 130 | 130 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 else: | 255 else: |
| 256 raise AssertionError() | 256 raise AssertionError() |
| 257 | 257 |
| 258 #NOTE: To be proper, we should add [0,blockType]. However, | 258 #NOTE: To be proper, we should add [0,blockType]. However, |
| 259 #the zero is lost when the returned padding is converted | 259 #the zero is lost when the returned padding is converted |
| 260 #to a number, so we don't even bother with it. Also, | 260 #to a number, so we don't even bother with it. Also, |
| 261 #adding it would cause a misalignment in verify() | 261 #adding it would cause a misalignment in verify() |
| 262 padding = createByteArraySequence([blockType] + pad + [0]) | 262 padding = createByteArraySequence([blockType] + pad + [0]) |
| 263 paddedBytes = padding + bytes | 263 paddedBytes = padding + bytes |
| 264 return paddedBytes | 264 return paddedBytes |
| OLD | NEW |