Subversion Repositories pub

Compare Revisions

No changes between revisions

Ignore whitespace Rev 181 → Rev 182

/relevation/ext/cryptopy-1.2.5.orig/crypto/entropy/__init__.py
0,0 → 1,8
""" crypto.entropy
 
Entropy package of CryptoPy
 
Copyright © (c) 2002 by Paul A. Lambert
Read LICENSE.txt for license information.
"""
 
/relevation/ext/cryptopy-1.2.5.orig/crypto/entropy/pagingEntropy.py
0,0 → 1,75
""" crypto.entropy.pagingEntropy
 
Uses variations in disk access time to generator entropy. A long string is
created that is bigger than available memory. Virtual memory access' create
random variations in retrieval time.
 
Just an experiment, not recommended for use at this time.
 
Copyright © (c) 2002 by Paul A. Lambert
Read LICENSE.txt for license information.
"""
import struct
 
class PagingEntropyCollector:
""" collect entropy from memory paging """
def __init__(self, memSize=500000000L): #? how should this be picked?
""" Initialize paging entropy collector,
memSize must be larger than allocated memory """
self.size = memSize
self.memBlock = self.size*chr(0) # long string of length self.size
self.index = 0
import random
self.rand = random.Random(1555551)
 
def randomBytes(self, numberOfBytes, secondsPerBit=.05):
byteString = ''
for b in range(numberOfBytes):
aByte = 0
for bit in range(8):
aByte = aByte << 1
aByte = aByte ^ self.collectBit(secondsPerBit)
byteString += chr(aByte)
return byteString
 
def collectBit(self, secondsPerBit=1.0):
""" Collect an entropy bit by jumping around a long string and
collecting the variation in time and number of samples per
time interval """
t1 = time()
count = 0
while (time()-t1) < secondsPerBit: # seconds per sample
# use random to sample various virtual memory locations
sample = self.memBlock[int(self.rand.random()*self.size)]
count += 1
randomBit = intToParity(count)^floatToParity(time()-t1)
return randomBit
 
def intToParity(integer):
s = struct.pack('i',integer)
parity = 0
for character in s:
byte = ord(character)
parity = parity^(0x01&(byte^(byte>>1)^(byte>>2)^(byte>>3)^(byte>>4)^(byte>>5)^(byte>>6)^(byte>>7)))
return parity
 
def floatToParity(float):
s = struct.pack('d',float)
parity = 0
for character in s:
byte = ord(character)
parity = parity^(0x01&(byte^(byte>>1)^(byte>>2)^(byte>>3)^(byte>>4)^(byte>>5)^(byte>>6)^(byte>>7)))
return parity
 
if __name__ == "__main__":
from binascii import b2a_hex
e = PagingEntropyCollector()
for i in range(20):
e.rand.seed(1) # make each sample set the same to allow examination of statistics
print b2a_hex( e.randomBytes(16) )
 
 
 
 
 
 
/relevation/ext/cryptopy-1.2.5.orig/crypto/entropy/prn_rijndael_test.py
0,0 → 1,31
#! /usr/bin/env python
""" crypto.entropy.prn_rijndael_test
 
Unit test for prn_rijndael
 
Copyright © (c) 2002 by Paul A. Lambert
Read LICENSE.txt for license information.
"""
 
from crypto.entropy.prn_rijndael import PRN_Rijndael
from binascii import b2a_hex
 
""" Not much of a test yet .... """
 
if __name__ == "__main__":
r = PRN_Rijndael()
for i in range(20):
print b2a_hex(r.getSomeBytes())
for i in range (20):
r.getBytes(i)
for i in range(40):
c=r.getBytes(i)
print b2a_hex(r.getBytes(i))
r.reseed(c)
 
 
 
 
 
 
 
/relevation/ext/cryptopy-1.2.5.orig/crypto/entropy/prn_rijndael.py
0,0 → 1,62
""" crypto.entropy.prn_rijndael
 
A Psudeo Random Number Generator based on Rijndael_256k_256b
The algorithm is based on Section 13.4 of:
"AES Proposal: Rijndael", Joan Daemen, Vincent Rijmen
 
Copyright © (c) 2002 by Paul A. Lambert
Read LICENSE.txt for license information.
"""
 
from crypto.cipher.rijndael import Rijndael
from crypto.cipher.base import noPadding
from binascii import b2a_hex
 
defaultSeed = "An arbirary 32 byte string!!!!!!" # can be changed by the truely paranoid
 
class PRN_Rijndael:
""" A Psudeo Random Number Generator based on Rijndael_256k_256b
The algorithm is based on Section 13.4 of:
"AES Proposal: Rijndael", Joan Daemen, Vincent Rijmen
"""
def __init__(self, seed=defaultSeed):
self.__algorithm = Rijndael(padding=noPadding(),keySize=32, blockSize=32)
self.reset()
self.reseed(seed)
 
def reset(self):
self.__algorithm.setKey(self.__algorithm.keySize*chr(0)) # set key to all zeros
self.__state = self.__algorithm.blockSize*chr(0) # a single block of zeros
 
def reseed(self,seed):
while len(seed) > 0 :
if len(seed) < self.__algorithm.blockSize:
block = seed + (self.__algorithm.blockSize-len(seed))*chr(0)
seed = ''
else:
block = seed[:self.__algorithm.blockSize]
seed = seed[self.__algorithm.blockSize:]
self.__algorithm.setKey( self.__algorithm.encrypt(block) )
 
def getBytes(self, numBytes):
""" Return a psuedo random byte string of length numBytes """
bytes = ''
while len(bytes)< numBytes :
bytes = bytes + self.getSomeBytes()
return bytes[:numBytes] # truncate to the requested length
 
def getSomeBytes(self):
""" Psuedo random bytes are generated 16 bytes at a time.
The state is updated by applying Rijndael using the Cipher
Key. The first 128 bits of the state are output as a “pseudorandom number”.
"""
self.__state = self.__algorithm.encrypt(self.__state)
return self.__state[:16]
 
 
 
 
 
 
 
 
/relevation/ext/cryptopy-1.2.5.orig/crypto/entropy/.
Property changes:
Added: bugtraq:number
+true
\ No newline at end of property