Example #1
0
def test_ed25519_scalar_reduce():
    zero = 32 * b'\x00'
    # 65536 times the order of the main subgroup (which is bigger
    # than 32 bytes), padded to 64 bytes
    # 2^252+27742317777372353535851937790883648493
    l65536 = bytes(2 * b'\x00') + \
        bytes(bytearray([0xed, 0xd3, 0xf5, 0x5c,
                         0x1a, 0x63, 0x12, 0x58,
                         0xd6, 0x9c, 0xf7, 0xa2,
                         0xde, 0xf9, 0xde, 0x14,
                         0x00, 0x00, 0x00, 0x00,
                         0x00, 0x00, 0x00, 0x00,
                         0x00, 0x00, 0x00, 0x00,
                         0x00, 0x00, 0x00, 0x10]
                        )
              ) + bytes(30 * b'\x00')

    # random scalar modulo l
    sclr = c.randombytes(c.crypto_core_ed25519_SCALARBYTES)
    p = c.crypto_core_ed25519_scalar_add(sclr, zero)

    # l65536 + p is bigger than 32 bytes
    big = c.sodium_add(l65536, p + bytes(32 * b'\x00'))

    r = c.crypto_core_ed25519_scalar_reduce(big)
    assert r == p
Example #2
0
def test_sodium_add():
    maxint = 32 * b"\xff"
    zero = 32 * b"\x00"
    one = b"\x01" + 31 * b"\x00"
    short_one = b"\x01" + 15 * b"\x00"
    two = b"\x02" + 31 * b"\x00"
    three = b"\x03" + 31 * b"\x00"
    four = b"\x04" + 31 * b"\x00"

    res = c.sodium_add(one, two)
    assert res == three

    res = c.sodium_add(maxint, four)
    assert res == three

    res = c.sodium_add(one, maxint)
    assert res == zero

    with pytest.raises(TypeError):
        res = c.sodium_add(short_one, two)
Example #3
0
def test_sodium_add():
    maxint = 32 * b'\xff'
    zero = 32 * b'\x00'
    one = b'\x01' + 31 * b'\x00'
    short_one = b'\x01' + 15 * b'\x00'
    two = b'\x02' + 31 * b'\x00'
    three = b'\x03' + 31 * b'\x00'
    four = b'\x04' + 31 * b'\x00'

    res = c.sodium_add(one, two)
    assert res == three

    res = c.sodium_add(maxint, four)
    assert res == three

    res = c.sodium_add(one, maxint)
    assert res == zero

    with pytest.raises(TypeError):
        res = c.sodium_add(short_one, two)
Example #4
0
def test_sodium_add():
    maxint = 32 * b'\xff'
    zero = 32 * b'\x00'
    one = b'\x01' + 31 * b'\x00'
    short_one = b'\x01' + 15 * b'\x00'
    two = b'\x02' + 31 * b'\x00'
    three = b'\x03' + 31 * b'\x00'
    four = b'\x04' + 31 * b'\x00'

    res = c.sodium_add(one, two)
    assert res == three

    res = c.sodium_add(maxint, four)
    assert res == three

    res = c.sodium_add(one, maxint)
    assert res == zero

    with pytest.raises(TypeError):
        res = c.sodium_add(short_one, two)
Example #5
0
def test_ed25519_scalar_reduce():
    zero = 32 * b"\x00"
    # 65536 times the order of the main subgroup (which is bigger
    # than 32 bytes), padded to 64 bytes
    # 2^252+27742317777372353535851937790883648493
    l65536 = (bytes(2 * b"\x00") + bytes(
        bytearray([
            0xED,
            0xD3,
            0xF5,
            0x5C,
            0x1A,
            0x63,
            0x12,
            0x58,
            0xD6,
            0x9C,
            0xF7,
            0xA2,
            0xDE,
            0xF9,
            0xDE,
            0x14,
            0x00,
            0x00,
            0x00,
            0x00,
            0x00,
            0x00,
            0x00,
            0x00,
            0x00,
            0x00,
            0x00,
            0x00,
            0x00,
            0x00,
            0x00,
            0x10,
        ])) + bytes(30 * b"\x00"))

    # random scalar modulo l
    sclr = c.randombytes(c.crypto_core_ed25519_SCALARBYTES)
    p = c.crypto_core_ed25519_scalar_add(sclr, zero)

    # l65536 + p is bigger than 32 bytes
    big = c.sodium_add(l65536, p + bytes(32 * b"\x00"))

    r = c.crypto_core_ed25519_scalar_reduce(big)
    assert r == p