예제 #1
0
    def prof_crypto_box_curve25519xsalsa20poly1305_tweet_open(self):
        '''
        test crypto_box_curve25519xsalsa20poly1305_tweet_open functions
        '''
        prof_count = int(self.opts['very_slow_prof_count']**0.5)

        for d in randargs(prof_count, [(17, 2**11)]):
            D = c_ulonglong(d)
            for m, c, n, y, x in randargs(prof_count, [c_ubyte, d],
                                          [c_ubyte, d], [c_ubyte, d],
                                          [c_ubyte, d], [c_ubyte, d]):
                M = ptr(c_ubyte, m)
                C = ptr(c_ubyte, c)
                N = ptr(c_ubyte, n)
                Y = ptr(c_ubyte, y)
                X = ptr(c_ubyte, x)

                tw_out = self.tweetnacl.call_fcn(
                    'crypto_box_curve25519xsalsa20poly1305_tweet_open', M, C,
                    D, N, Y, X)
                py_out = py_tweetnacl.crypto_box_curve25519xsalsa20poly1305_tweet_open(
                    m, c, d, n, y, x)

                self.assertEqual(m, [i for i in M])
                self.assertEqual(tw_out, py_out)
            self.assertEqual(d, D.value)
예제 #2
0
    def prof_crypto_sign_ed25519_tweet_open(self):
        '''
        test crypto_sign_ed25519_tweet_open functions
        '''
        llim = 8
        hlim = 2**8
        prof_count = int(self.opts['very_slow_prof_count']**0.5)

        for n in randargs(prof_count, [(llim, hlim)]):
            N = c_ulonglong(n)
            for m, mlen, sm, pk in randargs(prof_count, [c_ubyte, n + 64],
                                            [c_ulonglong], [c_ubyte, n],
                                            [c_ubyte, 64]):
                M = ptr(c_ubyte, m)
                MLEN = ptr(c_ulonglong, mlen)
                SM = ptr(c_ubyte, sm)
                PK = ptr(c_ubyte, pk)

                tw_out = self.tweetnacl.call_fcn(
                    'crypto_sign_ed25519_tweet_open', M, MLEN, SM, N, PK)
                py_out = py_tweetnacl.crypto_sign_ed25519_tweet_open(
                    m, mlen, sm, n, pk)

                self.assertEqual(m, [i for i in M])
                # In principle we should also test that
                #
                # ``str(c_ulonglong(mlen)) == MLEN.contents``,
                #
                # but python copies the argument when the function is called
                self.assertEqual(tw_out, py_out)
            self.assertEqual(n, N.value)
예제 #3
0
    def prof_crypto_box_curve25519xsalsa20poly1305_tweet():
        '''
        test crypto_box_curve25519xsalsa20poly1305_tweet functions
        '''
        prof_count = int(opts['very_slow_prof_count']**0.5)

        for d in randargs(prof_count, [(17, 2**11)]):
            for c, m, n, y, x in randargs(prof_count, [c_ubyte, d],
                                          [c_ubyte, d], [c_ubyte, d],
                                          [c_ubyte, d], [c_ubyte, d]):
                tweetnacl.crypto_box_curve25519xsalsa20poly1305_tweet(
                    c, m, d, n, y, x)
예제 #4
0
    def prof_vn(self):
        '''
        test vn functions
        '''
        prof_count = int(self.opts['prof_count']**0.5)

        for n in randargs(prof_count, [c_ubyte]):
            N = c_int(n)
            for x, y in randargs(prof_count, [c_ubyte, n], [c_ubyte, n]):
                X = ptr(c_ubyte, x)
                Y = ptr(c_ubyte, y)

                tw_out = self.tweetnacl.call_fcn('vn', X, Y, N)
                py_out = py_tweetnacl.vn(x, y, n)

                self.assertEqual(n, N.value)
                self.assertEqual(tw_out, py_out)
예제 #5
0
    def prof_crypto_hashblocks_sha512_tweet(self):
        '''
        test crypto_hashblocks_sha512_tweet functions
        '''
        prof_count = int(self.opts['very_slow_prof_count']**0.5)

        for n in randargs(prof_count, [(0, 2**17)]):
            N = c_ulonglong(n)
            for x, m in randargs(prof_count, [c_ubyte, 64], [c_ubyte, n]):
                X = ptr(c_ubyte, x)
                M = ptr(c_ubyte, m)

                tw_out = self.tweetnacl.call_fcn(
                    'crypto_hashblocks_sha512_tweet', X, M, N)
                py_out = py_tweetnacl.crypto_hashblocks_sha512_tweet(x, m, n)

                self.assertEqual(x, [i for i in X])
                self.assertEqual(tw_out, py_out)
            self.assertEqual(n, N.value)
예제 #6
0
    def prof_reduce(self):
        '''
        test reduce functions
        '''
        for r in randargs(self.opts['slow_prof_count'], [c_ubyte, 64]):
            R = ptr(c_ubyte, r)

            self.tweetnacl.call_fcn('reduce', R)
            py_tweetnacl.reduce(r)

            self.assertEqual(r, [i for i in R])
예제 #7
0
    def prof_crypto_hash_sha512_tweet(self):
        '''
        test crypto_hash_sha512_tweet functions
        '''
        prof_count = int(self.opts['slow_prof_count']**0.5)

        for n in randargs(prof_count, [(0, 2**11)]):
            N = c_ulonglong(n)
            for out, m in randargs(prof_count, [c_ubyte, 64],
                                   [c_ubyte, 2 * n]):
                OUT = ptr(c_ubyte, out)
                M = ptr(c_ubyte, m)

                tw_out = self.tweetnacl.call_fcn('crypto_hash_sha512_tweet',
                                                 OUT, M, N)
                py_out = py_tweetnacl.crypto_hash_sha512_tweet(out, m, n)

                self.assertEqual(out, [i for i in OUT])
                self.assertEqual(tw_out, py_out)
            self.assertEqual(n, N.value)
예제 #8
0
    def prof_dl64(self):
        '''
        test dl64 functions
        '''
        for x in randargs(self.opts['prof_count'], [c_ubyte, 8]):
            X = ptr(c_ubyte, x)

            tw_out = self.tweetnacl.call_fcn('dl64', X)
            py_out = py_tweetnacl.dl64(x)

            self.assertEqual(tw_out, py_out)
예제 #9
0
    def prof_ld32(self):
        '''
        test ld32 functions
        '''
        for x in randargs(self.opts['prof_count'], [c_ubyte, 4]):
            X = ptr(c_ubyte, x)

            tw_out = self.tweetnacl.call_fcn('ld32', X)
            py_out = py_tweetnacl.ld32(x)

            self.assertEqual(tw_out, py_out)
예제 #10
0
    def prof_crypto_onetimeauth_poly1305_tweet_verify(self):
        '''
        test crypto_onetimeauth_poly1305_tweet_verify functions
        '''
        prof_count = int(self.opts['slow_prof_count']**0.5)

        for n in randargs(prof_count, [(17, 2**11)]):
            N = c_ulonglong(n)
            for h, m, k in randargs(prof_count, [c_ubyte, n], [c_ubyte, n],
                                    [c_ubyte, 2 * n]):
                H = ptr(c_ubyte, h)
                M = ptr(c_ubyte, m)
                K = ptr(c_ubyte, k)

                tw_out = self.tweetnacl.call_fcn(
                    'crypto_onetimeauth_poly1305_tweet_verify', H, M, N, K)
                py_out = py_tweetnacl.crypto_onetimeauth_poly1305_tweet_verify(
                    h, m, n, k)

                self.assertEqual(tw_out, py_out)
            self.assertEqual(n, N.value)
예제 #11
0
    def prof_crypto_stream_xsalsa20_tweet(self):
        '''
        test crypto_stream_xsalsa20_tweet functions
        '''
        prof_count = int(self.opts['prof_count']**0.5)

        for d in randargs(prof_count, [(32, 64)]):
            D = c_ulonglong(d)
            for c, n, k in randargs(prof_count, [c_ubyte, d], [c_ubyte, d],
                                    [c_ubyte, d]):
                C = ptr(c_ubyte, c)
                N = ptr(c_ubyte, n)
                K = ptr(c_ubyte, k)

                tw_out = self.tweetnacl.call_fcn(
                    'crypto_stream_xsalsa20_tweet', C, D, N, K)
                py_out = py_tweetnacl.crypto_stream_xsalsa20_tweet(c, d, n, k)

                self.assertEqual(c, [i for i in C])
                self.assertEqual(tw_out, py_out)
            self.assertEqual(d, D.value)
예제 #12
0
    def prof_sigma1(self):
        '''
        test sigma1 functions
        '''
        for x in randargs(self.opts['prof_count'], [c_ulonglong]):
            X = c_ulonglong(x)

            tw_out = self.tweetnacl.call_fcn('sigma1', X)
            py_out = py_tweetnacl.sigma1(x)

            self.assertEqual(x, X.value)
            self.assertEqual(tw_out, py_out)
예제 #13
0
    def prof_car25519(self):
        '''
        test car25519 functions
        '''
        lim = 2**62

        for o in randargs(self.opts['prof_count'], [(-lim, lim), 16]):
            O = ptr(c_longlong, o)

            self.tweetnacl.call_fcn('car25519', O)
            py_tweetnacl.car25519(o)

            self.assertEqual(o, [i for i in O])
예제 #14
0
    def prof_set25519(self):
        '''
        test set25519 functions
        '''
        for r, a in randargs(self.opts['prof_count'], [c_longlong, 16],
                             [c_longlong, 16]):
            R = ptr(c_longlong, r)
            A = ptr(c_longlong, a)

            self.tweetnacl.call_fcn('set25519', R, A)
            py_tweetnacl.set25519(r, a)

            self.assertEqual(r, [i for i in R])
예제 #15
0
    def prof_unpack25519(self):
        '''
        test unpack25519 functions
        '''
        for o, n in randargs(self.opts['prof_count'], [c_longlong, 16],
                             [c_ubyte, 32]):
            O = ptr(c_longlong, o)
            N = ptr(c_ubyte, n)

            self.tweetnacl.call_fcn('unpack25519', O, N)
            py_tweetnacl.unpack25519(o, n)

            self.assertEqual(o, [i for i in O])
예제 #16
0
    def prof_par25519(self):
        '''
        test par25519 functions
        '''
        lim = 2**47

        for a in randargs(self.opts['prof_count'], [(-lim, lim), 16]):
            A = ptr(c_longlong, a)

            tw_out = self.tweetnacl.call_fcn('par25519', A)
            py_out = py_tweetnacl.par25519(a)

            self.assertEqual(tw_out, py_out)
예제 #17
0
    def prof_add1305(self):
        '''
        test add1305 functions
        '''
        for h, c in randargs(self.opts['prof_count'], [c_ulong, 17],
                             [c_ulong, 17]):
            H = ptr(c_ulong, h)
            C = ptr(c_ulong, c)

            self.tweetnacl.call_fcn('add1305', H, C)
            py_tweetnacl.add1305(h, c)

            self.assertEqual(h, [i for i in H])
예제 #18
0
    def prof_crypto_verify_32_tweet(self):
        '''
        test crypto_verify_32_tweet functions
        '''
        for x, y in randargs(self.opts['prof_count'], [c_ubyte, 32],
                             [c_ubyte, 32]):
            X = ptr(c_ubyte, x)
            Y = ptr(c_ubyte, y)

            tw_out = self.tweetnacl.call_fcn('crypto_verify_32_tweet', X, Y)
            py_out = py_tweetnacl.crypto_verify_32_tweet(x, y)

            self.assertEqual(tw_out, py_out)
예제 #19
0
    def prof_crypto_secretbox_xsalsa20poly1305_tweet(self):
        '''
        test crypto_secretbox_xsalsa20poly1305_tweet functions
        '''
        prof_count = int(self.opts['slow_prof_count']**0.5)

        for d in randargs(prof_count, [(17, 2**11)]):
            D = c_ulonglong(d)
            for c, m, n, k in randargs(prof_count, [c_ubyte, d], [c_ubyte, d],
                                       [c_ubyte, d], [c_ubyte, 2 * d]):
                C = ptr(c_ubyte, c)
                M = ptr(c_ubyte, m)
                N = ptr(c_ubyte, n)
                K = ptr(c_ubyte, k)

                tw_out = self.tweetnacl.call_fcn(
                    'crypto_secretbox_xsalsa20poly1305_tweet', C, M, D, N, K)
                py_out = py_tweetnacl.crypto_secretbox_xsalsa20poly1305_tweet(
                    c, m, d, n, k)

                self.assertEqual(c, [i for i in C])
                self.assertEqual(tw_out, py_out)
            self.assertEqual(d, D.value)
예제 #20
0
    def prof_ts64(self):
        '''
        test ts64 functions
        '''
        for x, u in randargs(self.opts['prof_count'], [c_ubyte, 8], [c_ubyte]):
            X = ptr(c_ubyte, x)
            U = c_ulong(u)

            self.tweetnacl.call_fcn('ts64', X, U)
            py_out = py_tweetnacl.ts64(x, u)

            self.assertEqual(x, [i for i in X])
            self.assertEqual(u, U.value)
            self.assertEqual(py_out, [i for i in X])
예제 #21
0
    def prof_crypto_stream_salsa20_tweet_xor(self):
        '''
        test crypto_stream_salsa20_tweet_xor functions
        '''
        prof_count = int(self.opts['prof_count']**0.5)

        for b in randargs(prof_count, [(32, 2**7)]):
            B = c_ulonglong(b)
            for c, m, n, k in randargs(prof_count, [c_ubyte, b], [c_ubyte, b],
                                       [c_ubyte, b], [c_ubyte, b]):
                C = ptr(c_ubyte, c)
                M = ptr(c_ubyte, m)
                N = ptr(c_ubyte, n)
                K = ptr(c_ubyte, k)

                tw_out = self.tweetnacl.call_fcn(
                    'crypto_stream_salsa20_tweet_xor', C, M, B, N, K)
                py_out = py_tweetnacl.crypto_stream_salsa20_tweet_xor(
                    c, m, b, n, k)

                self.assertEqual(c, [i for i in C])
                self.assertEqual(tw_out, py_out)
            self.assertEqual(b, B.value)
예제 #22
0
    def prof_pack25519(self):
        '''
        test pack25519 functions
        '''
        lim = 2**47

        for o, n in randargs(self.opts['prof_count'], [c_ubyte, 32],
                             [(-lim, lim), 16]):
            O = ptr(c_ubyte, o)
            N = ptr(c_longlong, n)

            self.tweetnacl.call_fcn('pack25519', O, N)
            py_tweetnacl.pack25519(o, n)

            self.assertEqual(o, [i for i in O])
예제 #23
0
    def prof_R(self):
        '''
        test R functions
        '''
        for x, c in randargs(self.opts['prof_count'], [c_ulonglong],
                             [(0, 64)]):
            X = c_ulonglong(x)
            C = c_int(c)

            tw_out = self.tweetnacl.call_fcn('R', X, C)
            py_out = py_tweetnacl.R(x, c)

            self.assertEqual(x, X.value)
            self.assertEqual(c, C.value)
            self.assertEqual(tw_out, py_out)
예제 #24
0
    def prof_neq25519(self):
        '''
        test neq25519 functions
        '''
        lim = 2**47

        for a, b in randargs(self.opts['prof_count'], [(-lim, lim), 16],
                             [(-lim, lim), 16]):
            A = ptr(c_longlong, a)
            B = ptr(c_longlong, b)

            tw_out = self.tweetnacl.call_fcn('neq25519', A, B)
            py_out = py_tweetnacl.neq25519(a, b)

            self.assertEqual(tw_out, py_out)
예제 #25
0
    def prof_crypto_scalarmult_curve25519_tweet_base(self):
        '''
        test crypto_scalarmult_curve25519_tweet_base functions
        '''
        for q, n in randargs(self.opts['very_slow_prof_count'], [c_ubyte, 32],
                             [c_ubyte, 32]):
            Q = ptr(c_ubyte, q)
            N = ptr(c_ubyte, n)

            tw_out = self.tweetnacl.call_fcn(
                'crypto_scalarmult_curve25519_tweet_base', Q, N)
            py_out = py_tweetnacl.crypto_scalarmult_curve25519_tweet_base(q, n)

            self.assertEqual(q, [i for i in Q])
            self.assertEqual(tw_out, py_out)
예제 #26
0
    def prof_pow2523(self):
        '''
        test pow2523 functions
        '''
        lim = 2**27

        for o, i in randargs(self.opts['very_slow_prof_count'],
                             [(-lim, lim - 1), 16], [(-lim, lim - 1), 16]):
            O = ptr(c_longlong, o)
            I = ptr(c_longlong, i)

            self.tweetnacl.call_fcn('pow2523', O, I)
            py_tweetnacl.pow2523(o, i)

            self.assertEqual(o, [j for j in O])
예제 #27
0
    def prof_unpackneg(self):
        '''
        test unpackneg functions
        '''
        for r, p in randargs(self.opts['very_slow_prof_count'],
                             [c_longlong, (16, 4)], [c_ubyte, 32]):
            R = ptr(c_longlong, r, (16, 4))
            P = ptr(c_ubyte, p)

            tw_out = self.tweetnacl.call_fcn('unpackneg', R, P)
            py_out = py_tweetnacl.unpackneg(r, p)

            for i, row in enumerate(R):
                self.assertEqual(r[i], [j for j in row])
            self.assertEqual(tw_out, py_out)
예제 #28
0
    def prof_S(self):
        '''
        test S functions
        '''
        lim = 2**27

        for o, a in randargs(self.opts['prof_count'], [(-lim, lim - 1), 16],
                             [(-lim, lim - 1), 16]):
            O = ptr(c_longlong, o)
            A = ptr(c_longlong, a)

            self.tweetnacl.call_fcn('S', O, A)
            py_tweetnacl.S(o, a)

            self.assertEqual(o, [i for i in O])
예제 #29
0
    def prof_inv25519(self):
        '''
        test inv25519 functions
        '''
        lim = 2**27

        for o, i in randargs(self.opts['very_slow_prof_count'],
                             [(-lim, lim - 1), 16], [(-lim, lim - 1), 16]):
            O = ptr(c_longlong, o)
            I = ptr(c_longlong, i)

            self.tweetnacl.call_fcn('inv25519', O, I)
            py_out = py_tweetnacl.inv25519(o, i)

            self.assertEqual(o, [j for j in O])
            self.assertEqual(py_out, [j for j in O])
예제 #30
0
    def prof_st32(self):
        '''
        test st32 functions
        '''
        for x, u in randargs(self.opts['prof_count'], [c_ubyte, 4], [c_ubyte]):
            X = ptr(c_ubyte, x)
            U = c_ulong(u)

            self.tweetnacl.call_fcn('st32', X, U)
            py_out = py_tweetnacl.st32(x, u)

            self.assertEqual(
                x,
                [i for i in X])  # ctypes funkery requires explicit iteration
            self.assertEqual(u, U.value)
            self.assertEqual(py_out, [i for i in X])