예제 #1
0
def get_sharedkey(a, B):
    # Alice Computes Shared Secret: s = B^a mod p

    x = pow(B, a, sharedPrime)
    aKDF = Hkdf(None, str(x).encode(), hash=hashlib.sha512)
    aKey = aKDF.expand(b"context1", 32)
    return x, aKey
예제 #2
0
 def test_vectors(self):
     for vector in HKDF_TEST_VECTORS:
         salt = unhexlify(vector["salt"].encode("ascii"))
         IKM = unhexlify(vector["IKM"].encode("ascii"))
         info = unhexlify(vector["info"].encode("ascii"))
         h = Hkdf(salt=salt, input_key_material=IKM, hash=sha256)
         digest = h.expand(info, vector["L"])
         self.assertEqual(digest, myHKDF(IKM, vector["L"], salt, info))
         #print(hexlify(digest))
         expected = vector["OKM"].encode("ascii")
         self.assertEqual(hexlify(digest), expected, vector)
예제 #3
0
 def test_vectors(self):
     for vector in HKDF_TEST_VECTORS:
         salt = unhexlify(vector["salt"].encode("ascii"))
         IKM = unhexlify(vector["IKM"].encode("ascii"))
         info = unhexlify(vector["info"].encode("ascii"))
         h = Hkdf(salt=salt, input_key_material=IKM, hash=sha256)
         digest = h.expand(info, vector["L"])
         self.assertEqual(digest, myHKDF(IKM, vector["L"], salt, info))
         #print(hexlify(digest))
         expected = vector["OKM"].encode("ascii")
         self.assertEqual(hexlify(digest), expected, vector)
예제 #4
0
    def deriveSecrets(self, inputKeyMaterial, salt, info):
        from hkdf import Hkdf

        if salt == None:
            salt = b"\x00" * self.HASH_OUTPUT_SIZE

        tshkdf = Hkdf(salt, inputKeyMaterial)
        okm = tshkdf.expand(info, self.KEY_MATERIAL_SIZE)

        cipherKey = okm[self.CIPHER_KEYS_OFFSET:self.HASH_OUTPUT_SIZE]
        macKey = okm[self.MAC_KEYS_OFFSET:self.MAC_KEYS_OFFSET + self.HASH_OUTPUT_SIZE]
        return ( cipherKey, macKey )
예제 #5
0
    def deriveSecrets(self, inputKeyMaterial, salt, info):
        from hkdf import Hkdf

        if salt == None:
            salt = b"\x00" * self.HASH_OUTPUT_SIZE

        tshkdf = Hkdf(salt, inputKeyMaterial)
        okm = tshkdf.expand(info, self.KEY_MATERIAL_SIZE)

        cipherKey = okm[self.CIPHER_KEYS_OFFSET:self.HASH_OUTPUT_SIZE]
        macKey = okm[self.MAC_KEYS_OFFSET:self.MAC_KEYS_OFFSET +
                     self.HASH_OUTPUT_SIZE]
        return (cipherKey, macKey)
예제 #6
0
def expand_arbitrary_element_seed(data, num_bytes):
    h = Hkdf(salt=b"", input_key_material=data, hash=hashlib.sha256)
    info = b"SPAKE2 arbitrary element"
    return h.expand(info, num_bytes)
예제 #7
0
def expand_password(data, num_bytes):
    h = Hkdf(salt=b"", input_key_material=data, hash=hashlib.sha256)
    info = b"SPAKE2 pw"
    return h.expand(info, num_bytes)
예제 #8
0
def expand_arbitrary_element_seed(data, num_bytes):
    h = Hkdf(salt=b"", input_key_material=data, hash=hashlib.sha256)
    info = b"SPAKE2 arbitrary element"
    return h.expand(info, num_bytes)
예제 #9
0
def expand_password(data, num_bytes):
    h = Hkdf(salt=b"", input_key_material=data, hash=hashlib.sha256)
    info = b"SPAKE2 pw"
    return h.expand(info, num_bytes)