Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(350)

Side by Side Diff: third_party/tlslite/tlslite/utils/cryptomath.py

Issue 168903005: Ensure that RSA signatures have the correct length (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Small correction to README.chromium. Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « third_party/tlslite/tlslite/utils/RSAKey.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """cryptomath module 1 """cryptomath module
2 2
3 This module has basic math/crypto code.""" 3 This module has basic math/crypto code."""
4 4
5 import os 5 import os
6 import math 6 import math
7 import base64 7 import base64
8 import binascii 8 import binascii
9 9
10 # The sha module is deprecated in Python 2.6 10 # The sha module is deprecated in Python 2.6
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 122
123 def bytesToNumber(bytes): 123 def bytesToNumber(bytes):
124 total = 0L 124 total = 0L
125 multiplier = 1L 125 multiplier = 1L
126 for count in range(len(bytes)-1, -1, -1): 126 for count in range(len(bytes)-1, -1, -1):
127 byte = bytes[count] 127 byte = bytes[count]
128 total += multiplier * byte 128 total += multiplier * byte
129 multiplier *= 256 129 multiplier *= 256
130 return total 130 return total
131 131
132 def numberToBytes(n): 132 def numberToBytes(n, howManyBytes=None):
133 howManyBytes = numBytes(n) 133 if howManyBytes == None:
134 howManyBytes = numBytes(n)
134 bytes = createByteArrayZeros(howManyBytes) 135 bytes = createByteArrayZeros(howManyBytes)
135 for count in range(howManyBytes-1, -1, -1): 136 for count in range(howManyBytes-1, -1, -1):
136 bytes[count] = int(n % 256) 137 bytes[count] = int(n % 256)
137 n >>= 8 138 n >>= 8
138 return bytes 139 return bytes
139 140
140 def bytesToBase64(bytes): 141 def bytesToBase64(bytes):
141 s = bytesToString(bytes) 142 s = bytesToString(bytes)
142 return stringToBase64(s) 143 return stringToBase64(s)
143 144
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 if (q >= high): 403 if (q >= high):
403 q = getRandomNumber(low, high) 404 q = getRandomNumber(low, high)
404 q += 29 - (q % 30) 405 q += 29 - (q % 30)
405 #Ideas from Tom Wu's SRP code 406 #Ideas from Tom Wu's SRP code
406 #Do trial division on p and q before Rabin-Miller 407 #Do trial division on p and q before Rabin-Miller
407 if isPrime(q, 0, display=display): 408 if isPrime(q, 0, display=display):
408 p = (2 * q) + 1 409 p = (2 * q) + 1
409 if isPrime(p, display=display): 410 if isPrime(p, display=display):
410 if isPrime(q, display=display): 411 if isPrime(q, display=display):
411 return p 412 return p
OLDNEW
« no previous file with comments | « third_party/tlslite/tlslite/utils/RSAKey.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698