Exemplo n.º 1
0
def F(p, s, c, i):
  mac = hmac.new(p, digestmod = hashlib.sha1)
  m2 = mac.copy()
  m2.update(s + pad_int2bin(i, 4))
  prev = m2.digest()
  u = bin2int(prev)
  for i in range(c - 1):
    m2 = mac.copy()
    m2.update(prev)
    prev = m2.digest()
    u = u ^ bin2int(prev)
  return int2bin(u)
Exemplo n.º 2
0
def F(p, s, c, i):
    mac = hmac.new(p, digestmod=hashlib.sha1)
    m2 = mac.copy()
    m2.update(s + pad_int2bin(i, 4))
    prev = m2.digest()
    u = bin2int(prev)
    for i in range(c - 1):
        m2 = mac.copy()
        m2.update(prev)
        prev = m2.digest()
        u = u ^ bin2int(prev)
    return int2bin(u)
Exemplo n.º 3
0
 def verify(self, message, s, e):
   r = (pow(self.g, s, self.p) * pow(self.publicKey, e, self.p)) % self.p
   h = HashWrapper()
   h.add(message)
   h.add(int2bin(r))
   e1 = h.digest()
   return bin2int(e1) == e
Exemplo n.º 4
0
 def sign(self, message):
     k = random.SystemRandom().randrange(self.q)
     r = pow(self.g, k, self.p)
     h = HashWrapper()
     h.add(message)
     h.add(int2bin(r))
     e = h.digest()
     s = (k - self.x * bin2int(e)) % self.q
     signature = (e, int2bin(s))
     return signature
Exemplo n.º 5
0
 def sign(self, message):
   k = random.SystemRandom().randrange(self.q)
   r = pow(self.g, k, self.p)
   h = HashWrapper()
   h.add(message)
   h.add(int2bin(r))
   e = h.digest()
   s = (k - self.x * bin2int(e)) % self.q
   signature = (e,  int2bin(s))
   return signature
Exemplo n.º 6
0
def authenticate(request):
    user = request.get('user')
    users = db.GqlQuery("SELECT * FROM User WHERE user ='******'")
    assert users.count(2) == 1

    (key, l) = ascii.encode(users[0].publicKey)
    verifier = SchnorrVerifier(bin2int(b64dec(key)))

    t = request.get('t')
    # FIXME: check t is recent, expire old tokens
    tokens = db.GqlQuery("SELECT * FROM Token WHERE token = '" + t + "'")
    if tokens.count(1) > 0:
        raise ReplayError()

    token = Token()
    token.token = t
    token.put()

    s = getb64(request, 's')
    e = getb64(request, 'e')

    if not verifier.verify(t, bin2int(s), bin2int(e)):
        raise VerifyError()
Exemplo n.º 7
0
def splitGet(user, password, name):
  splits = getSplits(user, password)
  k = int(splits[0])
  n = (len(splits) - 1)/2
  assert int(n) == n
  assert k <= n
  
  keys = KeyDeriver(password)
  shares = {}
  # FIXME: obviously we should try all n until we get k splits
  for s in range(k):
    global host, port
    host = splits[2*s + 1]
    port = splits[2*s + 2]
    print "Getting split", s, "from", host + ":" + port
    records = baseGetList(user, password, 1, name)
    record = records[-1]
    share = unconcat(keys.decrypt(record['value']))
    assert len(share) == 2
    shares[bin2int(share[0])] = bin2int(share[1])

  splitter = ShamirSplit()
  secret = splitter.recover(shares)
  print "value =", secret
Exemplo n.º 8
0
def splitGet(user, password, name):
    splits = getSplits(user, password)
    k = int(splits[0])
    n = (len(splits) - 1) / 2
    assert int(n) == n
    assert k <= n

    keys = KeyDeriver(password)
    shares = {}
    # FIXME: obviously we should try all n until we get k splits
    for s in range(k):
        global host, port
        host = splits[2 * s + 1]
        port = splits[2 * s + 2]
        print "Getting split", s, "from", host + ":" + port
        records = baseGetList(user, password, 1, name)
        record = records[-1]
        share = unconcat(keys.decrypt(record['value']))
        assert len(share) == 2
        shares[bin2int(share[0])] = bin2int(share[1])

    splitter = ShamirSplit()
    secret = splitter.recover(shares)
    print "value =", secret
Exemplo n.º 9
0
def authenticate(request):
  user = request.get('user')
  users = db.GqlQuery("SELECT * FROM User WHERE user ='******'")
  assert users.count(2) == 1

  (key, l) = ascii.encode(users[0].publicKey)
  verifier = SchnorrVerifier(bin2int(b64dec(key)))
    
  t = request.get('t')
  # FIXME: check t is recent, expire old tokens
  tokens = db.GqlQuery("SELECT * FROM Token WHERE token = '"
                       + t + "'")
  if tokens.count(1) > 0:
    raise ReplayError()

  token = Token()
  token.token = t
  token.put()
    
  s = getb64(request, 's')
  e = getb64(request, 'e')
    
  if not verifier.verify(t, bin2int(s), bin2int(e)):
    raise VerifyError()
Exemplo n.º 10
0
 def __init__(self, x):
     self.x = bin2int(x)
Exemplo n.º 11
0
 def __init__(self, x):
   self.x = bin2int(x)