Readme typo fix, sha512 benchmark, comment fix, better random for ECC

This commit is contained in:
HelloZeroNet 2015-01-13 10:56:47 +01:00
parent 4b02417b61
commit 6424c82887
4 changed files with 24 additions and 5 deletions

View file

@ -11,7 +11,7 @@ Decentralized websites using Bitcoin crypto and BitTorrent network
- Fast and works offline: You can access the site even if your internet is gone.
## How does it works?
## How does it work?
- After starting `zeronet.py` you will be able to visit zeronet sites using http://127.0.0.1:43110/{zeronet_address} (eg. http://127.0.0.1:43110/1EU1tbG9oC1A8jz2ouVwGZyQ5asrNsE4Vr).
- When you visit a new zeronet site, it's trying to find peers using BitTorrent network and download the site files (html, css, js...) from them.
- Each visited sites become also served by You.

View file

@ -9,6 +9,15 @@ def sha1sum(file, blocksize=65536):
return hash.hexdigest()
def sha512sum(file, blocksize=65536):
if hasattr(file, "endswith"): # Its a string open it
file = open(file, "rb")
hash = hashlib.sha512()
for block in iter(lambda: file.read(blocksize), ""):
hash.update(block)
return hash.hexdigest()
if __name__ == "__main__":
import cStringIO as StringIO
a = StringIO.StringIO()
@ -16,3 +25,12 @@ if __name__ == "__main__":
a.seek(0)
print hashlib.sha1("hello!").hexdigest()
print sha1sum(a)
import time
s = time.time()
print sha1sum(open("F:\\Temp\\bigfile")),
print time.time()-s
s = time.time()
print sha512sum(open("F:\\Temp\\bigfile")),
print time.time()-s

View file

@ -12,7 +12,7 @@ class Loading
# We dont need loadingscreen anymore
hideScreen: ->
if not $(".loadingscreen").hasClass("done") # Nothing to do, just let the animtion to be finished
if not $(".loadingscreen").hasClass("done") # Only if its not animating already
if @screen_visible # Hide with animate
$(".loadingscreen").addClass("done").removeLater(2000)
else # Not visible, just remove

View file

@ -235,7 +235,7 @@ class EllipticCurvePoint:
#Of course, this function isn't cryptographically secure.
#Don't use it to generate your key. Use a cryptographically secure source of randomness instead.
#self.d = random.randint(1,self.n-1)
self.d = int(os.urandom(32).encode("hex"), 16) # Better random fix
self.d = random.SystemRandom().randint(1,self.n-1) # Better random fix
def SignECDSA(self,m):
#Sign a message. The private key is self.d .
@ -246,7 +246,8 @@ class EllipticCurvePoint:
r=0
s=0
while not r or not s:
k=random.randint(1,self.n-1)
#k=random.randint(1,self.n-1)
k=random.SystemRandom().randint(1,self.n-1) # Better random fix
R=self*k
R.Normalize()
r=R.x[0]%self.n