Example #1
0
def MACI(IKSW, Index, EI, HASHIMINUS):
    c = hmac.new(IKSW, digestmod="sha256")
    if HASHIMINUS:
        c.update(bytes((Index).to_bytes(4, byteorder='big') + EI + HASHIMINUS))
    else:
        #zero index
        c.update(bytes((Index).to_bytes(4, byteorder='big') + EI))
    return c.digest()
Example #2
0
def test_hmac_instantiation(name, algcls, randbytes):
    if name not in md_hash.algorithms_available:
        pytest.skip("not an hmac algorithm")
    key = randbytes(16)
    alg1 = algcls(key)
    alg2 = md_hmac.new(key, digestmod=name)
    assert type(alg1) is type(alg2)
    assert alg1.name == alg2.name
Example #3
0
def test_check_against_hmac_nobuf(algorithm, randbytes):
    buf = randbytes(1024)
    key = randbytes(16)
    try:
        alg = md_hmac.new(key, buf, digestmod=algorithm.name)
        ref = hmac.new(key,
                       buf,
                       digestmod=partial(hashlib.new, algorithm.name))
    except ValueError as exc:
        # Unsupported hash type.
        pytest.skip(str(exc))
    assert alg.digest() == ref.digest()
Example #4
0
def test_check_against_hmac_buf(algorithm, randbytes):
    buf = randbytes(4096)
    key = randbytes(16)
    try:
        alg = md_hmac.new(key, digestmod=algorithm.name)
        ref = hmac.new(key, digestmod=partial(hashlib.new, algorithm.name))
    except ValueError as exc:
        # Unsupported hash type.
        pytest.skip(str(exc))
    for chunk in make_chunks(buf, 500):
        alg.update(chunk)
        ref.update(chunk)
    assert alg.digest() == ref.digest()
Example #5
0
def test_check_against_hmac_nobuf():
    for name in md_hmac.algorithms_available:
        buf = _rnd(1024)
        key = _rnd(16)
        try:
            alg = md_hmac.new(key, buf, digestmod=name)
            ref = hmac.new(key, buf, digestmod=name)
        except ValueError as exc:
            # Unsupported hash type.
            raise SkipTest(str(exc)) from exc
        # Use partial to have the correct name in failed reports (by
        # avoiding late bindings).
        test = partial(assert_equal, alg.digest(), ref.digest())
        test.description = "check_against_hmac_nobuf(%s)" % name
        yield test
Example #6
0
def test_check_against_hmac_buf():
    for name in md_hmac.algorithms_available:
        buf = _rnd(4096)
        key = _rnd(16)
        try:
            alg = md_hmac.new(key, digestmod=name)
            ref = hmac.new(key, digestmod=name)
        except ValueError as exc:
            # Unsupported hash type.
            raise SkipTest(str(exc)) from exc
        for chunk in make_chunks(buf, 500):
            alg.update(chunk)
            ref.update(chunk)
        test = partial(assert_equal, alg.digest(), ref.digest())
        test.description = "check_against_hmac_buf(%s)" % name
        yield test
Example #7
0
 def test_new(self, algorithm, key, buffer):
     copy = hmaclib.new(key, buffer, algorithm.name)
     algorithm.update(buffer)
     assert algorithm.digest() == copy.digest()
     assert algorithm.hexdigest() == copy.hexdigest()
Example #8
0
 def check_instantiation(fun, name):
     key = _rnd(16)
     alg1 = fun(key)
     alg2 = md_hmac.new(key, digestmod=name)
     assert_equal(type(alg1), type(alg2))
     assert_equal(alg1.name, alg2.name)