Readme typo fix, sha512 benchmark, comment fix, better random for ECC
This commit is contained in:
parent
4b02417b61
commit
6424c82887
4 changed files with 24 additions and 5 deletions
|
@ -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.
|
- 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).
|
- 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.
|
- 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.
|
- Each visited sites become also served by You.
|
||||||
|
|
|
@ -9,10 +9,28 @@ def sha1sum(file, blocksize=65536):
|
||||||
return hash.hexdigest()
|
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__":
|
if __name__ == "__main__":
|
||||||
import cStringIO as StringIO
|
import cStringIO as StringIO
|
||||||
a = StringIO.StringIO()
|
a = StringIO.StringIO()
|
||||||
a.write("hello!")
|
a.write("hello!")
|
||||||
a.seek(0)
|
a.seek(0)
|
||||||
print hashlib.sha1("hello!").hexdigest()
|
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
|
|
@ -12,7 +12,7 @@ class Loading
|
||||||
|
|
||||||
# We dont need loadingscreen anymore
|
# We dont need loadingscreen anymore
|
||||||
hideScreen: ->
|
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
|
if @screen_visible # Hide with animate
|
||||||
$(".loadingscreen").addClass("done").removeLater(2000)
|
$(".loadingscreen").addClass("done").removeLater(2000)
|
||||||
else # Not visible, just remove
|
else # Not visible, just remove
|
||||||
|
|
|
@ -235,7 +235,7 @@ class EllipticCurvePoint:
|
||||||
#Of course, this function isn't cryptographically secure.
|
#Of course, this function isn't cryptographically secure.
|
||||||
#Don't use it to generate your key. Use a cryptographically secure source of randomness instead.
|
#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 = 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):
|
def SignECDSA(self,m):
|
||||||
#Sign a message. The private key is self.d .
|
#Sign a message. The private key is self.d .
|
||||||
|
@ -246,7 +246,8 @@ class EllipticCurvePoint:
|
||||||
r=0
|
r=0
|
||||||
s=0
|
s=0
|
||||||
while not r or not s:
|
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=self*k
|
||||||
R.Normalize()
|
R.Normalize()
|
||||||
r=R.x[0]%self.n
|
r=R.x[0]%self.n
|
||||||
|
|
Loading…
Reference in a new issue