Upgrade to RSA 3.4.2

This commit is contained in:
Jay Lee
2016-08-20 16:53:46 -04:00
parent 0e01a32c64
commit 2f306d1181
18 changed files with 856 additions and 667 deletions

View File

@@ -6,7 +6,7 @@
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,24 +14,24 @@
# See the License for the specific language governing permissions and
# limitations under the License.
'''Core mathematical operations.
"""Core mathematical operations.
This is the actual core RSA implementation, which is only defined
mathematically on integers.
'''
"""
from rsa._compat import is_integer
def assert_int(var, name):
def assert_int(var, name):
if is_integer(var):
return
raise TypeError('%s should be an integer, not %s' % (name, var.__class__))
def encrypt_int(message, ekey, n):
'''Encrypts a message using encryption key 'ekey', working modulo n'''
"""Encrypts a message using encryption key 'ekey', working modulo n"""
assert_int(message, 'message')
assert_int(ekey, 'ekey')
@@ -39,15 +39,15 @@ def encrypt_int(message, ekey, n):
if message < 0:
raise ValueError('Only non-negative numbers are supported')
if message > n:
raise OverflowError("The message %i is too long for n=%i" % (message, n))
return pow(message, ekey, n)
def decrypt_int(cyphertext, dkey, n):
'''Decrypts a cypher text using the decryption key 'dkey', working
modulo n'''
"""Decrypts a cypher text using the decryption key 'dkey', working modulo n"""
assert_int(cyphertext, 'cyphertext')
assert_int(dkey, 'dkey')
@@ -55,4 +55,3 @@ def decrypt_int(cyphertext, dkey, n):
message = pow(cyphertext, dkey, n)
return message