Skip to content

Commit

Permalink
Readme typo fix, sha512 benchmark, comment fix, better random for ECC
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcutme committed Jan 13, 2015
1 parent 4b02417 commit 6424c82
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -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.
Expand Down
20 changes: 19 additions & 1 deletion src/Crypt/CryptHash.py
Expand Up @@ -9,10 +9,28 @@ 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()
a.write("hello!")
a.seek(0)
print hashlib.sha1("hello!").hexdigest()
print sha1sum(a)
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
2 changes: 1 addition & 1 deletion src/Ui/media/Loading.coffee
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/lib/BitcoinECC/BitcoinECC.py
Expand Up @@ -235,7 +235,7 @@ def GeneratePrivateKey(self):
#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 .
Expand All @@ -246,7 +246,8 @@ def SignECDSA(self,m):
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
Expand Down

0 comments on commit 6424c82

Please sign in to comment.