pynacl

Python wrapper for http://nacl.cace-project.eu/
git clone https://code.literati.org/pynacl.git
Log | Files | Refs | README

commit 4b21eaac2bed085f55e91bbad21c03a681e41a78
parent 6c95cbbbe0f4af92522b4ef4d0d9ddcd154fd1d6
Author: Sean Richard Lynch <seanl@literati.org>
Date:   Fri, 10 Feb 2012 22:20:36 -0800

Merge pull request #2 from warner/remove-dup

Remove dup
Diffstat:
Mnacl.i | 19-------------------
Mtest.py | 31+++++++++++++++++++++----------
2 files changed, 21 insertions(+), 29 deletions(-)

diff --git a/nacl.i b/nacl.i @@ -18,7 +18,6 @@ %{ #include "crypto_box.h" - #include "crypto_scalarmult_curve25519.h" #include "crypto_sign.h" #include "crypto_scalarmult_curve25519.h" #include "crypto_secretbox.h" @@ -341,24 +340,6 @@ int crypto_scalarmult_curve25519_base(unsigned char /** - * Scalar multiplication - */ -%constant int crypto_scalarmult_curve25519_SCALARBYTES; -%constant int crypto_scalarmult_curve25519_BYTES; - -int crypto_scalarmult_curve25519(unsigned char q[crypto_scalarmult_curve25519_BYTES], - const unsigned char n[crypto_scalarmult_curve25519_SCALARBYTES], - const unsigned char p[crypto_scalarmult_curve25519_BYTES]); -int crypto_scalarmult_curve25519_base(unsigned char q[crypto_scalarmult_curve25519_BYTES], - const unsigned char n[crypto_scalarmult_curve25519_SCALARBYTES]); - - -%pythoncode %{ -crypto_scalarmult = crypto_scalarmult_curve25519 -crypto_scalarmult_base = crypto_scalarmult_curve25519_base -%} - -/** * Signatures */ %constant int crypto_sign_BYTES; diff --git a/test.py b/test.py @@ -115,6 +115,27 @@ class ScalarMultTestCase(unittest.TestCase): s2 = nacl.crypto_scalarmult_curve25519(perturb(self.sk2), self.pk1) self.assertNotEqual(s1, s2) + def test_sharedkey(self): + dh_a = nacl.crypto_box_keypair() + dh_b = nacl.crypto_box_keypair() + shk_a = nacl.crypto_scalarmult(dh_a[1], dh_b[0]) + shk_b = nacl.crypto_scalarmult(dh_b[1], dh_a[0]) + self.assertEqual(shk_a, shk_b) + + def test_known(self): + sk3 = binascii.a2b_hex("5305ca1802ea41cd48f904e85d97868c" + "c0f30819473cd07727d7c44974bc8e58") + pk3 = nacl.crypto_scalarmult_curve25519_base(sk3) + sk4 = binascii.a2b_hex("fba6870b71790aa6ca40ca1fe29533a4" + "ab09d401b3b2c624ad15d615454ba27a") + pk4 = nacl.crypto_scalarmult_curve25519_base(sk4) + + s1 = nacl.crypto_scalarmult_curve25519(sk3, pk4) + s2 = nacl.crypto_scalarmult_curve25519(sk4, pk3) + expected = ("63b564b8218367b7d8d700cdc0d2e23a" + "65ef73905606f9c2e23b00d818c16a7e") + self.assertEqual(binascii.b2a_hex(s1), expected) + self.assertEqual(binascii.b2a_hex(s2), expected) class SignTestCase(unittest.TestCase): msg = b"The quick brown fox jumps over the lazy dog." @@ -152,16 +173,6 @@ class SignTestCase(unittest.TestCase): self.assertRaises(ValueError, nacl.crypto_sign_open, sm, self.pk1) -class ScalarMultTestCase(unittest.TestCase): - def setUp(self): - self.dh_a = nacl.crypto_box_keypair() - self.dh_b = nacl.crypto_box_keypair() - - def test_sharedkey(self): - shk_a = nacl.crypto_scalarmult(self.dh_a[1], self.dh_b[0]) - shk_b = nacl.crypto_scalarmult(self.dh_b[1], self.dh_a[0]) - self.assertEqual(shk_a, shk_b) - class SecretBoxTestCase(unittest.TestCase): msg = b"The quick brown fox jumps over the lazy dog." def setUp(self):