From 8931f04c4dcc79d665aa703594f93ada56b6e0b9 Mon Sep 17 00:00:00 2001 From: jbj Date: Mon, 2 Aug 2004 00:45:38 +0000 Subject: [PATCH] Upgrade to beecrypt-4.0.0. CVS patchset: 7372 CVS date: 2004/08/02 00:45:38 --- beecrypt/.cvsignore | 42 - beecrypt/.splintrc | 51 - beecrypt/AUTHORS | 8 + beecrypt/BENCHMARKS | 8 +- beecrypt/BUGS | 20 +- beecrypt/CONTRIBUTORS | 1 + beecrypt/COPYING | 20 +- beecrypt/DOCUMENTATION | 1 - beecrypt/Doxyfile.in | 598 +++++++--- beecrypt/Doxyheader | 213 ++-- beecrypt/Makefile.am | 55 +- beecrypt/NEWS | 24 +- beecrypt/README | 5 +- beecrypt/acinclude.m4 | 772 +++++++++++-- beecrypt/aes.c | 115 +- beecrypt/aes.h | 114 +- beecrypt/aes_be.h | 11 - beecrypt/aes_le.h | 11 - beecrypt/aesopt.h | 5 + beecrypt/{beecrypt.api.h => api.h} | 20 +- beecrypt/autogen.sh | 42 +- beecrypt/base64.c | 317 +++--- beecrypt/base64.h | 72 +- beecrypt/beecrypt.c | 220 ++-- beecrypt/beecrypt.h | 1193 +++++++++----------- beecrypt/beecrypt.mcp | Bin 60170 -> 0 bytes beecrypt/beecrypt.rc | 8 +- beecrypt/beecrypt.spec.in | 63 -- beecrypt/blockmode.c | 43 +- beecrypt/blockmode.h | 82 +- beecrypt/blockpad.c | 26 +- beecrypt/blockpad.h | 49 +- beecrypt/blowfish.c | 55 +- beecrypt/blowfish.h | 83 +- beecrypt/blowfishopt.h | 5 +- beecrypt/c++/Makefile.am | 44 + beecrypt/c++/Makefile.in | 734 ++++++++++++ beecrypt/c++/adapter.cxx | 65 ++ beecrypt/c++/adapter.h | 45 + beecrypt/c++/array.h | 188 +++ beecrypt/c++/beeyond/AnyEncodedKeySpec.cxx | 40 + beecrypt/c++/beeyond/AnyEncodedKeySpec.h | 53 + beecrypt/c++/beeyond/BeeCertificate.cxx | 619 ++++++++++ beecrypt/c++/beeyond/BeeCertificate.h | 186 +++ beecrypt/c++/beeyond/BeeEncodedKeySpec.cxx | 45 + beecrypt/c++/beeyond/BeeEncodedKeySpec.h | 48 + beecrypt/c++/beeyond/BeeInputStream.cxx | 75 ++ beecrypt/c++/beeyond/BeeInputStream.h | 49 + beecrypt/c++/beeyond/BeeOutputStream.cxx | 81 ++ beecrypt/c++/beeyond/BeeOutputStream.h | 49 + beecrypt/c++/beeyond/Makefile.am | 30 + beecrypt/c++/beeyond/Makefile.in | 569 ++++++++++ beecrypt/c++/beeyond/PKCS12PBEKey.cxx | 86 ++ beecrypt/c++/beeyond/PKCS12PBEKey.h | 67 ++ beecrypt/c++/beeyond/testcert.cxx | 105 ++ beecrypt/c++/bstream.cxx | 63 ++ beecrypt/c++/bstream.h | 46 + beecrypt/c++/crypto/BadPaddingException.cxx | 35 + beecrypt/c++/crypto/BadPaddingException.h | 44 + beecrypt/c++/crypto/Mac.cxx | 180 +++ beecrypt/c++/crypto/Mac.h | 81 ++ beecrypt/c++/crypto/MacInputStream.cxx | 72 ++ beecrypt/c++/crypto/MacInputStream.h | 62 + beecrypt/c++/crypto/MacOutputStream.cxx | 70 ++ beecrypt/c++/crypto/MacOutputStream.h | 62 + beecrypt/c++/crypto/MacSpi.h | 70 ++ beecrypt/c++/crypto/Makefile.am | 27 + beecrypt/c++/crypto/Makefile.in | 599 ++++++++++ beecrypt/c++/crypto/SecretKey.h | 46 + beecrypt/c++/crypto/SecretKeyFactory.cxx | 99 ++ beecrypt/c++/crypto/SecretKeyFactory.h | 76 ++ beecrypt/c++/crypto/SecretKeyFactorySpi.h | 61 + beecrypt/c++/crypto/interfaces/DHKey.h | 48 + beecrypt/c++/crypto/interfaces/DHParams.h | 47 + beecrypt/c++/crypto/interfaces/DHPrivateKey.h | 53 + beecrypt/c++/crypto/interfaces/DHPublicKey.h | 53 + beecrypt/c++/crypto/interfaces/Makefile.am | 12 + beecrypt/c++/crypto/interfaces/Makefile.in | 444 ++++++++ beecrypt/c++/crypto/interfaces/PBEKey.h | 52 + beecrypt/c++/crypto/spec/DHParameterSpec.cxx | 63 ++ beecrypt/c++/crypto/spec/DHParameterSpec.h | 63 ++ beecrypt/c++/crypto/spec/DHPrivateKeySpec.cxx | 50 + beecrypt/c++/crypto/spec/DHPrivateKeySpec.h | 58 + beecrypt/c++/crypto/spec/DHPublicKeySpec.cxx | 49 + beecrypt/c++/crypto/spec/DHPublicKeySpec.h | 58 + beecrypt/c++/crypto/spec/Makefile.am | 19 + beecrypt/c++/crypto/spec/Makefile.in | 496 ++++++++ beecrypt/c++/crypto/spec/PBEKeySpec.cxx | 66 ++ beecrypt/c++/crypto/spec/PBEKeySpec.h | 61 + beecrypt/c++/io/ByteArrayInputStream.cxx | 129 +++ beecrypt/c++/io/ByteArrayInputStream.h | 68 ++ beecrypt/c++/io/ByteArrayOutputStream.cxx | 127 +++ beecrypt/c++/io/ByteArrayOutputStream.h | 66 ++ beecrypt/c++/io/DataInput.h | 59 + beecrypt/c++/io/DataInputStream.cxx | 370 ++++++ beecrypt/c++/io/DataInputStream.h | 70 ++ beecrypt/c++/io/DataOutput.h | 54 + beecrypt/c++/io/DataOutputStream.cxx | 186 +++ beecrypt/c++/io/DataOutputStream.h | 70 ++ beecrypt/c++/io/EOFException.cxx | 35 + beecrypt/c++/io/EOFException.h | 44 + beecrypt/c++/io/FileInputStream.cxx | 172 +++ beecrypt/c++/io/FileInputStream.h | 60 + beecrypt/c++/io/FileOutputStream.cxx | 108 ++ beecrypt/c++/io/FileOutputStream.h | 53 + beecrypt/c++/io/FilterInputStream.cxx | 86 ++ beecrypt/c++/io/FilterInputStream.h | 62 + beecrypt/c++/io/FilterOutputStream.cxx | 68 ++ beecrypt/c++/io/FilterOutputStream.h | 53 + beecrypt/c++/io/IOException.cxx | 35 + beecrypt/c++/io/IOException.h | 44 + beecrypt/c++/io/InputStream.cxx | 103 ++ beecrypt/c++/io/InputStream.h | 55 + beecrypt/c++/io/Makefile.am | 48 + beecrypt/c++/io/Makefile.in | 616 ++++++++++ beecrypt/c++/io/OutputStream.cxx | 51 + beecrypt/c++/io/OutputStream.h | 51 + beecrypt/c++/io/PrintStream.cxx | 257 +++++ beecrypt/c++/io/PrintStream.h | 88 ++ beecrypt/c++/io/PushbackInputStream.cxx | 168 +++ beecrypt/c++/io/PushbackInputStream.h | 63 ++ beecrypt/c++/io/test.cxx | 103 ++ beecrypt/c++/lang/Error.cxx | 34 + beecrypt/c++/lang/Error.h | 44 + beecrypt/c++/lang/Exception.cxx | 34 + beecrypt/c++/lang/Exception.h | 44 + beecrypt/c++/lang/IllegalArgumentException.cxx | 34 + beecrypt/c++/lang/IllegalArgumentException.h | 44 + beecrypt/c++/lang/IllegalStateException.cxx | 34 + beecrypt/c++/lang/IllegalStateException.h | 44 + beecrypt/c++/lang/Makefile.am | 28 + beecrypt/c++/lang/Makefile.in | 507 +++++++++ beecrypt/c++/lang/NullPointerException.cxx | 34 + beecrypt/c++/lang/NullPointerException.h | 44 + beecrypt/c++/lang/OutOfMemoryError.cxx | 34 + beecrypt/c++/lang/OutOfMemoryError.h | 44 + beecrypt/c++/lang/RuntimeException.cxx | 34 + beecrypt/c++/lang/RuntimeException.h | 44 + beecrypt/c++/lang/String.h | 39 + beecrypt/c++/lang/Throwable.cxx | 45 + beecrypt/c++/lang/Throwable.h | 54 + beecrypt/c++/mutex.h | 157 +++ beecrypt/c++/provider/BeeCertificateFactory.cxx | 67 ++ beecrypt/c++/provider/BeeCertificateFactory.h | 48 + beecrypt/c++/provider/BeeCryptProvider.cxx | 289 +++++ beecrypt/c++/provider/BeeCryptProvider.h | 48 + beecrypt/c++/provider/BeeKeyFactory.cxx | 391 +++++++ beecrypt/c++/provider/BeeKeyFactory.h | 64 ++ beecrypt/c++/provider/BeeKeyStore.cxx | 639 +++++++++++ beecrypt/c++/provider/BeeKeyStore.h | 135 +++ beecrypt/c++/provider/BeeSecureRandom.cxx | 57 + beecrypt/c++/provider/BeeSecureRandom.h | 59 + beecrypt/c++/provider/DHKeyFactory.cxx | 169 +++ beecrypt/c++/provider/DHKeyFactory.h | 58 + beecrypt/c++/provider/DHKeyPairGenerator.cxx | 164 +++ beecrypt/c++/provider/DHKeyPairGenerator.h | 60 + beecrypt/c++/provider/DHParameterGenerator.cxx | 123 ++ beecrypt/c++/provider/DHParameterGenerator.h | 59 + beecrypt/c++/provider/DHParameters.cxx | 82 ++ beecrypt/c++/provider/DHParameters.h | 56 + beecrypt/c++/provider/DHPrivateKeyImpl.cxx | 98 ++ beecrypt/c++/provider/DHPrivateKeyImpl.h | 68 ++ beecrypt/c++/provider/DHPublicKeyImpl.cxx | 96 ++ beecrypt/c++/provider/DHPublicKeyImpl.h | 68 ++ beecrypt/c++/provider/DSAKeyFactory.cxx | 171 +++ beecrypt/c++/provider/DSAKeyFactory.h | 58 + beecrypt/c++/provider/DSAKeyPairGenerator.cxx | 161 +++ beecrypt/c++/provider/DSAKeyPairGenerator.h | 61 + beecrypt/c++/provider/DSAParameterGenerator.cxx | 123 ++ beecrypt/c++/provider/DSAParameterGenerator.h | 57 + beecrypt/c++/provider/DSAParameters.cxx | 82 ++ beecrypt/c++/provider/DSAParameters.h | 58 + beecrypt/c++/provider/DSAPrivateKeyImpl.cxx | 98 ++ beecrypt/c++/provider/DSAPrivateKeyImpl.h | 64 ++ beecrypt/c++/provider/DSAPublicKeyImpl.cxx | 97 ++ beecrypt/c++/provider/DSAPublicKeyImpl.h | 63 ++ beecrypt/c++/provider/HMACMD5.cxx | 121 ++ beecrypt/c++/provider/HMACMD5.h | 62 + beecrypt/c++/provider/HMACSHA1.cxx | 121 ++ beecrypt/c++/provider/HMACSHA1.h | 62 + beecrypt/c++/provider/HMACSHA256.cxx | 121 ++ beecrypt/c++/provider/HMACSHA256.h | 62 + beecrypt/c++/provider/KeyProtector.cxx | 259 +++++ beecrypt/c++/provider/KeyProtector.h | 60 + beecrypt/c++/provider/MD5Digest.cxx | 85 ++ beecrypt/c++/provider/MD5Digest.h | 62 + beecrypt/c++/provider/MD5withRSASignature.cxx | 35 + beecrypt/c++/provider/MD5withRSASignature.h | 43 + beecrypt/c++/provider/Makefile.am | 83 ++ beecrypt/c++/provider/Makefile.in | 570 ++++++++++ beecrypt/c++/provider/PKCS12KeyFactory.cxx | 71 ++ beecrypt/c++/provider/PKCS12KeyFactory.h | 49 + beecrypt/c++/provider/PKCS1RSASignature.cxx | 196 ++++ beecrypt/c++/provider/PKCS1RSASignature.h | 78 ++ beecrypt/c++/provider/RSAKeyFactory.cxx | 196 ++++ beecrypt/c++/provider/RSAKeyFactory.h | 62 + beecrypt/c++/provider/RSAKeyPairGenerator.cxx | 105 ++ beecrypt/c++/provider/RSAKeyPairGenerator.h | 65 ++ beecrypt/c++/provider/RSAPrivateCrtKeyImpl.cxx | 129 +++ beecrypt/c++/provider/RSAPrivateCrtKeyImpl.h | 71 ++ beecrypt/c++/provider/RSAPrivateKeyImpl.cxx | 82 ++ beecrypt/c++/provider/RSAPrivateKeyImpl.h | 59 + beecrypt/c++/provider/RSAPublicKeyImpl.cxx | 81 ++ beecrypt/c++/provider/RSAPublicKeyImpl.h | 59 + beecrypt/c++/provider/SHA1Digest.cxx | 85 ++ beecrypt/c++/provider/SHA1Digest.h | 62 + beecrypt/c++/provider/SHA1withDSASignature.cxx | 411 +++++++ beecrypt/c++/provider/SHA1withDSASignature.h | 84 ++ beecrypt/c++/provider/SHA1withRSASignature.cxx | 34 + beecrypt/c++/provider/SHA1withRSASignature.h | 43 + beecrypt/c++/provider/SHA256withRSASignature.cxx | 35 + beecrypt/c++/provider/SHA256withRSASignature.h | 43 + beecrypt/c++/resource.cxx | 27 + beecrypt/c++/resource.h | 31 + .../c++/security/AlgorithmParameterGenerator.cxx | 112 ++ .../c++/security/AlgorithmParameterGenerator.h | 75 ++ .../c++/security/AlgorithmParameterGeneratorSpi.h | 63 ++ beecrypt/c++/security/AlgorithmParameters.cxx | 107 ++ beecrypt/c++/security/AlgorithmParameters.h | 76 ++ beecrypt/c++/security/AlgorithmParametersSpi.h | 59 + beecrypt/c++/security/DigestInputStream.cxx | 72 ++ beecrypt/c++/security/DigestInputStream.h | 61 + beecrypt/c++/security/DigestOutputStream.cxx | 70 ++ beecrypt/c++/security/DigestOutputStream.h | 61 + beecrypt/c++/security/GeneralSecurityException.cxx | 35 + beecrypt/c++/security/GeneralSecurityException.h | 44 + .../InvalidAlgorithmParameterException.cxx | 35 + .../security/InvalidAlgorithmParameterException.h | 44 + beecrypt/c++/security/InvalidKeyException.cxx | 35 + beecrypt/c++/security/InvalidKeyException.h | 44 + .../c++/security/InvalidParameterException.cxx | 35 + beecrypt/c++/security/InvalidParameterException.h | 43 + beecrypt/c++/security/Key.h | 55 + beecrypt/c++/security/KeyException.cxx | 35 + beecrypt/c++/security/KeyException.h | 44 + beecrypt/c++/security/KeyFactory.cxx | 103 ++ beecrypt/c++/security/KeyFactory.h | 77 ++ beecrypt/c++/security/KeyFactorySpi.h | 65 ++ beecrypt/c++/security/KeyPair.cxx | 51 + beecrypt/c++/security/KeyPair.h | 56 + beecrypt/c++/security/KeyPairGenerator.cxx | 108 ++ beecrypt/c++/security/KeyPairGenerator.h | 74 ++ beecrypt/c++/security/KeyPairGeneratorSpi.h | 61 + beecrypt/c++/security/KeyStore.cxx | 188 +++ beecrypt/c++/security/KeyStore.h | 95 ++ beecrypt/c++/security/KeyStoreException.cxx | 35 + beecrypt/c++/security/KeyStoreException.h | 44 + beecrypt/c++/security/KeyStoreSpi.h | 93 ++ beecrypt/c++/security/Makefile.am | 73 ++ beecrypt/c++/security/Makefile.in | 655 +++++++++++ beecrypt/c++/security/MessageDigest.cxx | 134 +++ beecrypt/c++/security/MessageDigest.h | 78 ++ beecrypt/c++/security/MessageDigestSpi.h | 59 + beecrypt/c++/security/NoSuchAlgorithmException.cxx | 35 + beecrypt/c++/security/NoSuchAlgorithmException.h | 44 + beecrypt/c++/security/NoSuchProviderException.cxx | 35 + beecrypt/c++/security/NoSuchProviderException.h | 44 + beecrypt/c++/security/PrivateKey.h | 46 + beecrypt/c++/security/Provider.cxx | 122 ++ beecrypt/c++/security/Provider.h | 83 ++ beecrypt/c++/security/PublicKey.h | 46 + beecrypt/c++/security/SecureRandom.cxx | 115 ++ beecrypt/c++/security/SecureRandom.h | 74 ++ beecrypt/c++/security/SecureRandomSpi.h | 49 + beecrypt/c++/security/Security.cxx | 404 +++++++ beecrypt/c++/security/Security.h | 104 ++ beecrypt/c++/security/ShortBufferException.cxx | 35 + beecrypt/c++/security/ShortBufferException.h | 44 + beecrypt/c++/security/Signature.cxx | 172 +++ beecrypt/c++/security/Signature.h | 91 ++ beecrypt/c++/security/SignatureException.cxx | 35 + beecrypt/c++/security/SignatureException.h | 44 + beecrypt/c++/security/SignatureSpi.h | 83 ++ .../c++/security/UnrecoverableKeyException.cxx | 35 + beecrypt/c++/security/UnrecoverableKeyException.h | 44 + beecrypt/c++/security/cert/Certificate.cxx | 55 + beecrypt/c++/security/cert/Certificate.h | 77 ++ .../c++/security/cert/CertificateException.cxx | 35 + beecrypt/c++/security/cert/CertificateException.h | 46 + .../security/cert/CertificateExpiredException.cxx | 35 + .../security/cert/CertificateExpiredException.h | 46 + beecrypt/c++/security/cert/CertificateFactory.cxx | 93 ++ beecrypt/c++/security/cert/CertificateFactory.h | 75 ++ beecrypt/c++/security/cert/CertificateFactorySpi.h | 60 + .../cert/CertificateNotYetValidException.cxx | 35 + .../cert/CertificateNotYetValidException.h | 46 + beecrypt/c++/security/cert/Makefile.am | 22 + beecrypt/c++/security/cert/Makefile.in | 500 ++++++++ beecrypt/c++/security/interfaces/DSAKey.h | 48 + beecrypt/c++/security/interfaces/DSAParams.h | 47 + beecrypt/c++/security/interfaces/DSAPrivateKey.h | 50 + beecrypt/c++/security/interfaces/DSAPublicKey.h | 50 + beecrypt/c++/security/interfaces/Makefile.am | 15 + beecrypt/c++/security/interfaces/Makefile.in | 447 ++++++++ beecrypt/c++/security/interfaces/RSAKey.h | 48 + .../c++/security/interfaces/RSAPrivateCrtKey.h | 53 + beecrypt/c++/security/interfaces/RSAPrivateKey.h | 49 + beecrypt/c++/security/interfaces/RSAPublicKey.h | 49 + .../c++/security/spec/AlgorithmParameterSpec.h | 46 + beecrypt/c++/security/spec/DSAParameterSpec.cxx | 60 + beecrypt/c++/security/spec/DSAParameterSpec.h | 62 + beecrypt/c++/security/spec/DSAPrivateKeySpec.cxx | 60 + beecrypt/c++/security/spec/DSAPrivateKeySpec.h | 60 + beecrypt/c++/security/spec/DSAPublicKeySpec.cxx | 59 + beecrypt/c++/security/spec/DSAPublicKeySpec.h | 60 + beecrypt/c++/security/spec/EncodedKeySpec.cxx | 44 + beecrypt/c++/security/spec/EncodedKeySpec.h | 58 + .../c++/security/spec/InvalidKeySpecException.cxx | 35 + .../c++/security/spec/InvalidKeySpecException.h | 46 + .../spec/InvalidParameterSpecException.cxx | 35 + .../security/spec/InvalidParameterSpecException.h | 46 + beecrypt/c++/security/spec/KeySpec.h | 46 + beecrypt/c++/security/spec/Makefile.am | 33 + beecrypt/c++/security/spec/Makefile.in | 513 +++++++++ .../c++/security/spec/RSAKeyGenParameterSpec.cxx | 50 + .../c++/security/spec/RSAKeyGenParameterSpec.h | 59 + .../c++/security/spec/RSAPrivateCrtKeySpec.cxx | 71 ++ beecrypt/c++/security/spec/RSAPrivateCrtKeySpec.h | 61 + beecrypt/c++/security/spec/RSAPrivateKeySpec.cxx | 47 + beecrypt/c++/security/spec/RSAPrivateKeySpec.h | 56 + beecrypt/c++/security/spec/RSAPublicKeySpec.cxx | 47 + beecrypt/c++/security/spec/RSAPublicKeySpec.h | 56 + beecrypt/c++/testdsa.cxx | 88 ++ beecrypt/c++/testks.cxx | 90 ++ beecrypt/c++/testrsa.cxx | 90 ++ beecrypt/c++/util/Date.cxx | 105 ++ beecrypt/c++/util/Date.h | 61 + beecrypt/c++/util/Enumeration.h | 46 + beecrypt/c++/util/Makefile.am | 27 + beecrypt/c++/util/Makefile.in | 597 ++++++++++ beecrypt/c++/util/NoSuchElementException.cxx | 35 + beecrypt/c++/util/NoSuchElementException.h | 44 + beecrypt/c++/util/Properties.cxx | 171 +++ beecrypt/c++/util/Properties.h | 91 ++ beecrypt/c++/util/testdate.cxx | 37 + beecrypt/c++/util/testprop.cxx | 58 + beecrypt/config.m4.in | 1 - beecrypt/configure.ac | 436 +++---- beecrypt/cppglue.cxx | 296 +++++ beecrypt/debug.h | 13 - beecrypt/dhaes.c | 102 +- beecrypt/dhaes.h | 86 +- beecrypt/dldp.c | 84 +- beecrypt/dldp.h | 171 ++- beecrypt/dlkp.c | 19 +- beecrypt/dlkp.h | 51 +- beecrypt/dlpk.c | 15 +- beecrypt/dlpk.h | 66 +- beecrypt/dlsvdp-dh.c | 27 +- beecrypt/dlsvdp-dh.h | 24 +- beecrypt/docs/.cvsignore | 19 - beecrypt/dsa.c | 59 +- beecrypt/dsa.h | 76 +- beecrypt/elgamal.c | 62 +- beecrypt/elgamal.h | 134 ++- beecrypt/endianness.c | 28 +- beecrypt/endianness.h | 42 +- beecrypt/entropy.c | 458 +++----- beecrypt/entropy.h | 45 +- beecrypt/fips186.c | 57 +- beecrypt/fips186.h | 55 +- beecrypt/gas/.cvsignore | 19 - beecrypt/gas/Makefile.am | 2 +- beecrypt/gas/aesopt.i586.m4 | 580 ---------- beecrypt/gas/aesopt.ppc.m4 | 69 +- beecrypt/gas/aesopt.x86.m4 | 1 + beecrypt/gas/blowfishopt.i586.m4 | 1 + beecrypt/gas/blowfishopt.ppc.m4 | 1 + beecrypt/gas/fips180opt.ia64.S | 213 ---- beecrypt/gas/mpopt.alpha.m4 | 1 + beecrypt/gas/mpopt.arm.m4 | 1 + beecrypt/gas/mpopt.ia64.m4 | 1 + beecrypt/gas/mpopt.m68k.m4 | 1 + beecrypt/gas/mpopt.ppc.m4 | 3 +- beecrypt/gas/mpopt.ppc64.m4 | 1 + beecrypt/gas/mpopt.s390x.m4 | 12 +- beecrypt/gas/mpopt.sparcv8.m4 | 1 + beecrypt/gas/mpopt.sparcv8plus.m4 | 1 + beecrypt/gas/mpopt.x86.m4 | 5 +- beecrypt/gas/mpopt.x86_64.m4 | 148 ++- beecrypt/gas/ppc.m4 | 18 +- beecrypt/gas/ppc64.m4 | 101 +- beecrypt/gas/sha1opt.x86.m4 | 13 +- beecrypt/gnu.h | 58 + beecrypt/{beecrypt.gnu.h.in => gnu.h.in} | 15 +- beecrypt/hmac.c | 18 +- beecrypt/hmac.h | 27 +- beecrypt/hmacmd5.c | 32 +- beecrypt/hmacmd5.h | 42 +- beecrypt/hmacsha1.c | 24 +- beecrypt/hmacsha1.h | 42 +- beecrypt/hmacsha256.c | 24 +- beecrypt/hmacsha256.h | 42 +- beecrypt/java/.cvsignore | 5 - beecrypt/java/Makefile.am | 20 +- beecrypt/java/javaglue.c | 51 +- beecrypt/masm/.cvsignore | 19 - beecrypt/md5.c | 77 +- beecrypt/md5.h | 86 +- beecrypt/memchunk.c | 41 +- beecrypt/memchunk.h | 33 +- beecrypt/mp.c | 250 ++-- beecrypt/mp.h | 873 +++++++------- beecrypt/mpbarrett.c | 597 ++++------ beecrypt/mpbarrett.h | 233 ++-- beecrypt/mpnumber.c | 174 ++- beecrypt/mpnumber.h | 108 +- beecrypt/mpopt.h | 15 +- beecrypt/mpprime.c | 339 ++---- beecrypt/mpprime.h | 50 +- beecrypt/mtprng.c | 56 +- beecrypt/mtprng.h | 57 +- beecrypt/mwerks/.cvsignore | 19 - beecrypt/mwerks/Makefile.am | 25 - beecrypt/mwerks/beecrypt.pch | 6 - beecrypt/mwerks/blowfishopt.i586.asm | 173 --- beecrypt/mwerks/mp32opt.i386.asm | 299 ----- beecrypt/mwerks/sha1opt.i586.asm | 292 ----- beecrypt/pkcs1.c | 62 + beecrypt/pkcs1.h | 27 + beecrypt/pkcs12.c | 81 ++ beecrypt/pkcs12.h | 26 + beecrypt/python/.cvsignore | 7 - beecrypt/python/Makefile.am | 27 +- beecrypt/python/_bc-py.c | 8 +- beecrypt/python/debug-py.c | 4 +- beecrypt/python/mpw-py.c | 36 +- beecrypt/python/mpw-py.h | 2 +- beecrypt/python/rng-py.c | 2 +- beecrypt/python/rng-py.h | 4 +- beecrypt/python/test/.cvsignore | 3 - beecrypt/python/test/Makefile.am | 5 +- beecrypt/python/test/test_methods.py | 6 +- beecrypt/rsa.c | 87 +- beecrypt/rsa.h | 97 +- beecrypt/rsakp.c | 178 ++- beecrypt/rsakp.h | 85 +- beecrypt/rsapk.c | 14 +- beecrypt/rsapk.h | 44 +- beecrypt/sha1.c | 102 +- beecrypt/sha1.h | 82 +- beecrypt/sha1opt.h | 15 +- beecrypt/sha256.c | 139 +-- beecrypt/sha256.h | 80 +- beecrypt/stamp-h.in | 1 - beecrypt/system.h | 89 -- beecrypt/tests/.cvsignore | 37 - beecrypt/tests/Makefile.am | 4 +- beecrypt/tests/beetest.c | 793 ------------- beecrypt/tests/benchbc.c | 4 +- beecrypt/tests/benchhf.c | 4 +- beecrypt/tests/benchme.c | 4 +- beecrypt/tests/openpgp.c | 741 ------------ beecrypt/tests/testaes.c | 5 +- beecrypt/tests/testblowfish.c | 7 +- beecrypt/tests/testconv.c | 35 + beecrypt/tests/testdldp.c | 6 +- beecrypt/tests/testdsa.c | 95 +- beecrypt/tests/testhmacmd5.c | 46 +- beecrypt/tests/testhmacsha1.c | 46 +- beecrypt/tests/testmd5.c | 4 +- beecrypt/tests/testmp.c | 5 +- beecrypt/tests/testmpinv.c | 74 +- beecrypt/tests/testrsa.c | 79 +- beecrypt/tests/testsha1.c | 4 +- beecrypt/tests/testsha256.c | 4 +- beecrypt/tests/testutil.c | 4 +- beecrypt/timestamp.c | 25 +- beecrypt/timestamp.h | 18 +- beecrypt/win.h | 139 +++ 470 files changed, 36141 insertions(+), 9273 deletions(-) delete mode 100644 beecrypt/.cvsignore delete mode 100644 beecrypt/.splintrc delete mode 100644 beecrypt/DOCUMENTATION rename beecrypt/{beecrypt.api.h => api.h} (85%) delete mode 100644 beecrypt/beecrypt.mcp delete mode 100644 beecrypt/beecrypt.spec.in create mode 100644 beecrypt/c++/Makefile.am create mode 100644 beecrypt/c++/Makefile.in create mode 100644 beecrypt/c++/adapter.cxx create mode 100644 beecrypt/c++/adapter.h create mode 100644 beecrypt/c++/array.h create mode 100644 beecrypt/c++/beeyond/AnyEncodedKeySpec.cxx create mode 100644 beecrypt/c++/beeyond/AnyEncodedKeySpec.h create mode 100644 beecrypt/c++/beeyond/BeeCertificate.cxx create mode 100644 beecrypt/c++/beeyond/BeeCertificate.h create mode 100644 beecrypt/c++/beeyond/BeeEncodedKeySpec.cxx create mode 100644 beecrypt/c++/beeyond/BeeEncodedKeySpec.h create mode 100644 beecrypt/c++/beeyond/BeeInputStream.cxx create mode 100644 beecrypt/c++/beeyond/BeeInputStream.h create mode 100644 beecrypt/c++/beeyond/BeeOutputStream.cxx create mode 100644 beecrypt/c++/beeyond/BeeOutputStream.h create mode 100644 beecrypt/c++/beeyond/Makefile.am create mode 100644 beecrypt/c++/beeyond/Makefile.in create mode 100644 beecrypt/c++/beeyond/PKCS12PBEKey.cxx create mode 100644 beecrypt/c++/beeyond/PKCS12PBEKey.h create mode 100644 beecrypt/c++/beeyond/testcert.cxx create mode 100644 beecrypt/c++/bstream.cxx create mode 100644 beecrypt/c++/bstream.h create mode 100644 beecrypt/c++/crypto/BadPaddingException.cxx create mode 100644 beecrypt/c++/crypto/BadPaddingException.h create mode 100644 beecrypt/c++/crypto/Mac.cxx create mode 100644 beecrypt/c++/crypto/Mac.h create mode 100644 beecrypt/c++/crypto/MacInputStream.cxx create mode 100644 beecrypt/c++/crypto/MacInputStream.h create mode 100644 beecrypt/c++/crypto/MacOutputStream.cxx create mode 100644 beecrypt/c++/crypto/MacOutputStream.h create mode 100644 beecrypt/c++/crypto/MacSpi.h create mode 100644 beecrypt/c++/crypto/Makefile.am create mode 100644 beecrypt/c++/crypto/Makefile.in create mode 100644 beecrypt/c++/crypto/SecretKey.h create mode 100644 beecrypt/c++/crypto/SecretKeyFactory.cxx create mode 100644 beecrypt/c++/crypto/SecretKeyFactory.h create mode 100644 beecrypt/c++/crypto/SecretKeyFactorySpi.h create mode 100644 beecrypt/c++/crypto/interfaces/DHKey.h create mode 100644 beecrypt/c++/crypto/interfaces/DHParams.h create mode 100644 beecrypt/c++/crypto/interfaces/DHPrivateKey.h create mode 100644 beecrypt/c++/crypto/interfaces/DHPublicKey.h create mode 100644 beecrypt/c++/crypto/interfaces/Makefile.am create mode 100644 beecrypt/c++/crypto/interfaces/Makefile.in create mode 100644 beecrypt/c++/crypto/interfaces/PBEKey.h create mode 100644 beecrypt/c++/crypto/spec/DHParameterSpec.cxx create mode 100644 beecrypt/c++/crypto/spec/DHParameterSpec.h create mode 100644 beecrypt/c++/crypto/spec/DHPrivateKeySpec.cxx create mode 100644 beecrypt/c++/crypto/spec/DHPrivateKeySpec.h create mode 100644 beecrypt/c++/crypto/spec/DHPublicKeySpec.cxx create mode 100644 beecrypt/c++/crypto/spec/DHPublicKeySpec.h create mode 100644 beecrypt/c++/crypto/spec/Makefile.am create mode 100644 beecrypt/c++/crypto/spec/Makefile.in create mode 100644 beecrypt/c++/crypto/spec/PBEKeySpec.cxx create mode 100644 beecrypt/c++/crypto/spec/PBEKeySpec.h create mode 100644 beecrypt/c++/io/ByteArrayInputStream.cxx create mode 100644 beecrypt/c++/io/ByteArrayInputStream.h create mode 100644 beecrypt/c++/io/ByteArrayOutputStream.cxx create mode 100644 beecrypt/c++/io/ByteArrayOutputStream.h create mode 100644 beecrypt/c++/io/DataInput.h create mode 100644 beecrypt/c++/io/DataInputStream.cxx create mode 100644 beecrypt/c++/io/DataInputStream.h create mode 100644 beecrypt/c++/io/DataOutput.h create mode 100644 beecrypt/c++/io/DataOutputStream.cxx create mode 100644 beecrypt/c++/io/DataOutputStream.h create mode 100644 beecrypt/c++/io/EOFException.cxx create mode 100644 beecrypt/c++/io/EOFException.h create mode 100644 beecrypt/c++/io/FileInputStream.cxx create mode 100644 beecrypt/c++/io/FileInputStream.h create mode 100644 beecrypt/c++/io/FileOutputStream.cxx create mode 100644 beecrypt/c++/io/FileOutputStream.h create mode 100644 beecrypt/c++/io/FilterInputStream.cxx create mode 100644 beecrypt/c++/io/FilterInputStream.h create mode 100644 beecrypt/c++/io/FilterOutputStream.cxx create mode 100644 beecrypt/c++/io/FilterOutputStream.h create mode 100644 beecrypt/c++/io/IOException.cxx create mode 100644 beecrypt/c++/io/IOException.h create mode 100644 beecrypt/c++/io/InputStream.cxx create mode 100644 beecrypt/c++/io/InputStream.h create mode 100644 beecrypt/c++/io/Makefile.am create mode 100644 beecrypt/c++/io/Makefile.in create mode 100644 beecrypt/c++/io/OutputStream.cxx create mode 100644 beecrypt/c++/io/OutputStream.h create mode 100644 beecrypt/c++/io/PrintStream.cxx create mode 100644 beecrypt/c++/io/PrintStream.h create mode 100644 beecrypt/c++/io/PushbackInputStream.cxx create mode 100644 beecrypt/c++/io/PushbackInputStream.h create mode 100644 beecrypt/c++/io/test.cxx create mode 100644 beecrypt/c++/lang/Error.cxx create mode 100644 beecrypt/c++/lang/Error.h create mode 100644 beecrypt/c++/lang/Exception.cxx create mode 100644 beecrypt/c++/lang/Exception.h create mode 100644 beecrypt/c++/lang/IllegalArgumentException.cxx create mode 100644 beecrypt/c++/lang/IllegalArgumentException.h create mode 100644 beecrypt/c++/lang/IllegalStateException.cxx create mode 100644 beecrypt/c++/lang/IllegalStateException.h create mode 100644 beecrypt/c++/lang/Makefile.am create mode 100644 beecrypt/c++/lang/Makefile.in create mode 100644 beecrypt/c++/lang/NullPointerException.cxx create mode 100644 beecrypt/c++/lang/NullPointerException.h create mode 100644 beecrypt/c++/lang/OutOfMemoryError.cxx create mode 100644 beecrypt/c++/lang/OutOfMemoryError.h create mode 100644 beecrypt/c++/lang/RuntimeException.cxx create mode 100644 beecrypt/c++/lang/RuntimeException.h create mode 100644 beecrypt/c++/lang/String.h create mode 100644 beecrypt/c++/lang/Throwable.cxx create mode 100644 beecrypt/c++/lang/Throwable.h create mode 100644 beecrypt/c++/mutex.h create mode 100644 beecrypt/c++/provider/BeeCertificateFactory.cxx create mode 100644 beecrypt/c++/provider/BeeCertificateFactory.h create mode 100644 beecrypt/c++/provider/BeeCryptProvider.cxx create mode 100644 beecrypt/c++/provider/BeeCryptProvider.h create mode 100644 beecrypt/c++/provider/BeeKeyFactory.cxx create mode 100644 beecrypt/c++/provider/BeeKeyFactory.h create mode 100644 beecrypt/c++/provider/BeeKeyStore.cxx create mode 100644 beecrypt/c++/provider/BeeKeyStore.h create mode 100644 beecrypt/c++/provider/BeeSecureRandom.cxx create mode 100644 beecrypt/c++/provider/BeeSecureRandom.h create mode 100644 beecrypt/c++/provider/DHKeyFactory.cxx create mode 100644 beecrypt/c++/provider/DHKeyFactory.h create mode 100644 beecrypt/c++/provider/DHKeyPairGenerator.cxx create mode 100644 beecrypt/c++/provider/DHKeyPairGenerator.h create mode 100644 beecrypt/c++/provider/DHParameterGenerator.cxx create mode 100644 beecrypt/c++/provider/DHParameterGenerator.h create mode 100644 beecrypt/c++/provider/DHParameters.cxx create mode 100644 beecrypt/c++/provider/DHParameters.h create mode 100644 beecrypt/c++/provider/DHPrivateKeyImpl.cxx create mode 100644 beecrypt/c++/provider/DHPrivateKeyImpl.h create mode 100644 beecrypt/c++/provider/DHPublicKeyImpl.cxx create mode 100644 beecrypt/c++/provider/DHPublicKeyImpl.h create mode 100644 beecrypt/c++/provider/DSAKeyFactory.cxx create mode 100644 beecrypt/c++/provider/DSAKeyFactory.h create mode 100644 beecrypt/c++/provider/DSAKeyPairGenerator.cxx create mode 100644 beecrypt/c++/provider/DSAKeyPairGenerator.h create mode 100644 beecrypt/c++/provider/DSAParameterGenerator.cxx create mode 100644 beecrypt/c++/provider/DSAParameterGenerator.h create mode 100644 beecrypt/c++/provider/DSAParameters.cxx create mode 100644 beecrypt/c++/provider/DSAParameters.h create mode 100644 beecrypt/c++/provider/DSAPrivateKeyImpl.cxx create mode 100644 beecrypt/c++/provider/DSAPrivateKeyImpl.h create mode 100644 beecrypt/c++/provider/DSAPublicKeyImpl.cxx create mode 100644 beecrypt/c++/provider/DSAPublicKeyImpl.h create mode 100644 beecrypt/c++/provider/HMACMD5.cxx create mode 100644 beecrypt/c++/provider/HMACMD5.h create mode 100644 beecrypt/c++/provider/HMACSHA1.cxx create mode 100644 beecrypt/c++/provider/HMACSHA1.h create mode 100644 beecrypt/c++/provider/HMACSHA256.cxx create mode 100644 beecrypt/c++/provider/HMACSHA256.h create mode 100644 beecrypt/c++/provider/KeyProtector.cxx create mode 100644 beecrypt/c++/provider/KeyProtector.h create mode 100644 beecrypt/c++/provider/MD5Digest.cxx create mode 100644 beecrypt/c++/provider/MD5Digest.h create mode 100644 beecrypt/c++/provider/MD5withRSASignature.cxx create mode 100644 beecrypt/c++/provider/MD5withRSASignature.h create mode 100644 beecrypt/c++/provider/Makefile.am create mode 100644 beecrypt/c++/provider/Makefile.in create mode 100644 beecrypt/c++/provider/PKCS12KeyFactory.cxx create mode 100644 beecrypt/c++/provider/PKCS12KeyFactory.h create mode 100644 beecrypt/c++/provider/PKCS1RSASignature.cxx create mode 100644 beecrypt/c++/provider/PKCS1RSASignature.h create mode 100644 beecrypt/c++/provider/RSAKeyFactory.cxx create mode 100644 beecrypt/c++/provider/RSAKeyFactory.h create mode 100644 beecrypt/c++/provider/RSAKeyPairGenerator.cxx create mode 100644 beecrypt/c++/provider/RSAKeyPairGenerator.h create mode 100644 beecrypt/c++/provider/RSAPrivateCrtKeyImpl.cxx create mode 100644 beecrypt/c++/provider/RSAPrivateCrtKeyImpl.h create mode 100644 beecrypt/c++/provider/RSAPrivateKeyImpl.cxx create mode 100644 beecrypt/c++/provider/RSAPrivateKeyImpl.h create mode 100644 beecrypt/c++/provider/RSAPublicKeyImpl.cxx create mode 100644 beecrypt/c++/provider/RSAPublicKeyImpl.h create mode 100644 beecrypt/c++/provider/SHA1Digest.cxx create mode 100644 beecrypt/c++/provider/SHA1Digest.h create mode 100644 beecrypt/c++/provider/SHA1withDSASignature.cxx create mode 100644 beecrypt/c++/provider/SHA1withDSASignature.h create mode 100644 beecrypt/c++/provider/SHA1withRSASignature.cxx create mode 100644 beecrypt/c++/provider/SHA1withRSASignature.h create mode 100644 beecrypt/c++/provider/SHA256withRSASignature.cxx create mode 100644 beecrypt/c++/provider/SHA256withRSASignature.h create mode 100644 beecrypt/c++/resource.cxx create mode 100644 beecrypt/c++/resource.h create mode 100644 beecrypt/c++/security/AlgorithmParameterGenerator.cxx create mode 100644 beecrypt/c++/security/AlgorithmParameterGenerator.h create mode 100644 beecrypt/c++/security/AlgorithmParameterGeneratorSpi.h create mode 100644 beecrypt/c++/security/AlgorithmParameters.cxx create mode 100644 beecrypt/c++/security/AlgorithmParameters.h create mode 100644 beecrypt/c++/security/AlgorithmParametersSpi.h create mode 100644 beecrypt/c++/security/DigestInputStream.cxx create mode 100644 beecrypt/c++/security/DigestInputStream.h create mode 100644 beecrypt/c++/security/DigestOutputStream.cxx create mode 100644 beecrypt/c++/security/DigestOutputStream.h create mode 100644 beecrypt/c++/security/GeneralSecurityException.cxx create mode 100644 beecrypt/c++/security/GeneralSecurityException.h create mode 100644 beecrypt/c++/security/InvalidAlgorithmParameterException.cxx create mode 100644 beecrypt/c++/security/InvalidAlgorithmParameterException.h create mode 100644 beecrypt/c++/security/InvalidKeyException.cxx create mode 100644 beecrypt/c++/security/InvalidKeyException.h create mode 100644 beecrypt/c++/security/InvalidParameterException.cxx create mode 100644 beecrypt/c++/security/InvalidParameterException.h create mode 100644 beecrypt/c++/security/Key.h create mode 100644 beecrypt/c++/security/KeyException.cxx create mode 100644 beecrypt/c++/security/KeyException.h create mode 100644 beecrypt/c++/security/KeyFactory.cxx create mode 100644 beecrypt/c++/security/KeyFactory.h create mode 100644 beecrypt/c++/security/KeyFactorySpi.h create mode 100644 beecrypt/c++/security/KeyPair.cxx create mode 100644 beecrypt/c++/security/KeyPair.h create mode 100644 beecrypt/c++/security/KeyPairGenerator.cxx create mode 100644 beecrypt/c++/security/KeyPairGenerator.h create mode 100644 beecrypt/c++/security/KeyPairGeneratorSpi.h create mode 100644 beecrypt/c++/security/KeyStore.cxx create mode 100644 beecrypt/c++/security/KeyStore.h create mode 100644 beecrypt/c++/security/KeyStoreException.cxx create mode 100644 beecrypt/c++/security/KeyStoreException.h create mode 100644 beecrypt/c++/security/KeyStoreSpi.h create mode 100644 beecrypt/c++/security/Makefile.am create mode 100644 beecrypt/c++/security/Makefile.in create mode 100644 beecrypt/c++/security/MessageDigest.cxx create mode 100644 beecrypt/c++/security/MessageDigest.h create mode 100644 beecrypt/c++/security/MessageDigestSpi.h create mode 100644 beecrypt/c++/security/NoSuchAlgorithmException.cxx create mode 100644 beecrypt/c++/security/NoSuchAlgorithmException.h create mode 100644 beecrypt/c++/security/NoSuchProviderException.cxx create mode 100644 beecrypt/c++/security/NoSuchProviderException.h create mode 100644 beecrypt/c++/security/PrivateKey.h create mode 100644 beecrypt/c++/security/Provider.cxx create mode 100644 beecrypt/c++/security/Provider.h create mode 100644 beecrypt/c++/security/PublicKey.h create mode 100644 beecrypt/c++/security/SecureRandom.cxx create mode 100644 beecrypt/c++/security/SecureRandom.h create mode 100644 beecrypt/c++/security/SecureRandomSpi.h create mode 100644 beecrypt/c++/security/Security.cxx create mode 100644 beecrypt/c++/security/Security.h create mode 100644 beecrypt/c++/security/ShortBufferException.cxx create mode 100644 beecrypt/c++/security/ShortBufferException.h create mode 100644 beecrypt/c++/security/Signature.cxx create mode 100644 beecrypt/c++/security/Signature.h create mode 100644 beecrypt/c++/security/SignatureException.cxx create mode 100644 beecrypt/c++/security/SignatureException.h create mode 100644 beecrypt/c++/security/SignatureSpi.h create mode 100644 beecrypt/c++/security/UnrecoverableKeyException.cxx create mode 100644 beecrypt/c++/security/UnrecoverableKeyException.h create mode 100644 beecrypt/c++/security/cert/Certificate.cxx create mode 100644 beecrypt/c++/security/cert/Certificate.h create mode 100644 beecrypt/c++/security/cert/CertificateException.cxx create mode 100644 beecrypt/c++/security/cert/CertificateException.h create mode 100644 beecrypt/c++/security/cert/CertificateExpiredException.cxx create mode 100644 beecrypt/c++/security/cert/CertificateExpiredException.h create mode 100644 beecrypt/c++/security/cert/CertificateFactory.cxx create mode 100644 beecrypt/c++/security/cert/CertificateFactory.h create mode 100644 beecrypt/c++/security/cert/CertificateFactorySpi.h create mode 100644 beecrypt/c++/security/cert/CertificateNotYetValidException.cxx create mode 100644 beecrypt/c++/security/cert/CertificateNotYetValidException.h create mode 100644 beecrypt/c++/security/cert/Makefile.am create mode 100644 beecrypt/c++/security/cert/Makefile.in create mode 100644 beecrypt/c++/security/interfaces/DSAKey.h create mode 100644 beecrypt/c++/security/interfaces/DSAParams.h create mode 100644 beecrypt/c++/security/interfaces/DSAPrivateKey.h create mode 100644 beecrypt/c++/security/interfaces/DSAPublicKey.h create mode 100644 beecrypt/c++/security/interfaces/Makefile.am create mode 100644 beecrypt/c++/security/interfaces/Makefile.in create mode 100644 beecrypt/c++/security/interfaces/RSAKey.h create mode 100644 beecrypt/c++/security/interfaces/RSAPrivateCrtKey.h create mode 100644 beecrypt/c++/security/interfaces/RSAPrivateKey.h create mode 100644 beecrypt/c++/security/interfaces/RSAPublicKey.h create mode 100644 beecrypt/c++/security/spec/AlgorithmParameterSpec.h create mode 100644 beecrypt/c++/security/spec/DSAParameterSpec.cxx create mode 100644 beecrypt/c++/security/spec/DSAParameterSpec.h create mode 100644 beecrypt/c++/security/spec/DSAPrivateKeySpec.cxx create mode 100644 beecrypt/c++/security/spec/DSAPrivateKeySpec.h create mode 100644 beecrypt/c++/security/spec/DSAPublicKeySpec.cxx create mode 100644 beecrypt/c++/security/spec/DSAPublicKeySpec.h create mode 100644 beecrypt/c++/security/spec/EncodedKeySpec.cxx create mode 100644 beecrypt/c++/security/spec/EncodedKeySpec.h create mode 100644 beecrypt/c++/security/spec/InvalidKeySpecException.cxx create mode 100644 beecrypt/c++/security/spec/InvalidKeySpecException.h create mode 100644 beecrypt/c++/security/spec/InvalidParameterSpecException.cxx create mode 100644 beecrypt/c++/security/spec/InvalidParameterSpecException.h create mode 100644 beecrypt/c++/security/spec/KeySpec.h create mode 100644 beecrypt/c++/security/spec/Makefile.am create mode 100644 beecrypt/c++/security/spec/Makefile.in create mode 100644 beecrypt/c++/security/spec/RSAKeyGenParameterSpec.cxx create mode 100644 beecrypt/c++/security/spec/RSAKeyGenParameterSpec.h create mode 100644 beecrypt/c++/security/spec/RSAPrivateCrtKeySpec.cxx create mode 100644 beecrypt/c++/security/spec/RSAPrivateCrtKeySpec.h create mode 100644 beecrypt/c++/security/spec/RSAPrivateKeySpec.cxx create mode 100644 beecrypt/c++/security/spec/RSAPrivateKeySpec.h create mode 100644 beecrypt/c++/security/spec/RSAPublicKeySpec.cxx create mode 100644 beecrypt/c++/security/spec/RSAPublicKeySpec.h create mode 100644 beecrypt/c++/testdsa.cxx create mode 100644 beecrypt/c++/testks.cxx create mode 100644 beecrypt/c++/testrsa.cxx create mode 100644 beecrypt/c++/util/Date.cxx create mode 100644 beecrypt/c++/util/Date.h create mode 100644 beecrypt/c++/util/Enumeration.h create mode 100644 beecrypt/c++/util/Makefile.am create mode 100644 beecrypt/c++/util/Makefile.in create mode 100644 beecrypt/c++/util/NoSuchElementException.cxx create mode 100644 beecrypt/c++/util/NoSuchElementException.h create mode 100644 beecrypt/c++/util/Properties.cxx create mode 100644 beecrypt/c++/util/Properties.h create mode 100644 beecrypt/c++/util/testdate.cxx create mode 100644 beecrypt/c++/util/testprop.cxx create mode 100644 beecrypt/cppglue.cxx delete mode 100644 beecrypt/debug.h delete mode 100644 beecrypt/docs/.cvsignore delete mode 100644 beecrypt/gas/.cvsignore delete mode 100644 beecrypt/gas/aesopt.i586.m4 delete mode 100644 beecrypt/gas/fips180opt.ia64.S create mode 100644 beecrypt/gnu.h rename beecrypt/{beecrypt.gnu.h.in => gnu.h.in} (79%) delete mode 100644 beecrypt/java/.cvsignore delete mode 100644 beecrypt/masm/.cvsignore delete mode 100644 beecrypt/mwerks/.cvsignore delete mode 100644 beecrypt/mwerks/Makefile.am delete mode 100644 beecrypt/mwerks/beecrypt.pch delete mode 100644 beecrypt/mwerks/blowfishopt.i586.asm delete mode 100644 beecrypt/mwerks/mp32opt.i386.asm delete mode 100644 beecrypt/mwerks/sha1opt.i586.asm create mode 100644 beecrypt/pkcs1.c create mode 100644 beecrypt/pkcs1.h create mode 100644 beecrypt/pkcs12.c create mode 100644 beecrypt/pkcs12.h delete mode 100644 beecrypt/python/.cvsignore delete mode 100644 beecrypt/python/test/.cvsignore delete mode 100644 beecrypt/stamp-h.in delete mode 100644 beecrypt/system.h delete mode 100644 beecrypt/tests/.cvsignore delete mode 100644 beecrypt/tests/beetest.c delete mode 100644 beecrypt/tests/openpgp.c create mode 100644 beecrypt/tests/testconv.c create mode 100644 beecrypt/win.h diff --git a/beecrypt/.cvsignore b/beecrypt/.cvsignore deleted file mode 100644 index ce9cfd7..0000000 --- a/beecrypt/.cvsignore +++ /dev/null @@ -1,42 +0,0 @@ -.deps -.depend -.depend-done -.libs -Doxyfile -Makefile -Makefile.in -aclocal.m4 -missing -mkinstalldirs -apidocs -autom4te* -beecrypt.gnu.h -beecrypt.spec -beecrypt-*.tar.gz -config.h -config.h.in -config.cache -config.guess -config.log -config.m4 -config.status -config.sub -configure -depcomp -doxygen -libtool -listobjs -ltconfig -ltmain.sh -aesopt.c -blowfishopt.c -mpopt.c -sha1opt.c -*.la -*.lcd -*.lo -*.o -*.s -stamp-h -stamp-h1 -stamp-h.in diff --git a/beecrypt/.splintrc b/beecrypt/.splintrc deleted file mode 100644 index feee213..0000000 --- a/beecrypt/.splintrc +++ /dev/null @@ -1,51 +0,0 @@ --I. -I/usr/lib/gcc-lib/i386-redhat-linux/3.1/include -DHAVE_CONFIG_H -D_GNU_SOURCE -DHAVE_DEV_DSP -DHAVE_SYS_SOUNDCARD - -#+partial -+forcehints - --warnposix - -+unixlib - --unrecogcomments # XXX ignore doxygen markings - -+strict # lclint level - -# --- in progress -+likelybounds --bufferoverflowhigh - --elseifcomplete --whileempty - -# --- not-yet at strict level --exportconst # 3 --exportfcn # 308 --exporttype # 53 --exportvar # 14 --protoparamname # 826 - --ansi-reserved-internal # goofy - --ptrarith # 212 - --mustdefine # 64 --strictops # 23 - --impcheckedstrictglobs --impcheckedstrictstatics --strictbranchstate - --forblock # 15 --ifblock # 455 --whileblock # 25 --sys-dir-errors # 1296 - -# --- not-yet at checks level --predboolptr # 88 --ansi-reserved # goofy - -# --- not-yet at standard level -+boolint # 329 -+charint # 3 -+matchanyintegral # 573 diff --git a/beecrypt/AUTHORS b/beecrypt/AUTHORS index 05ff7a3..878abf5 100644 --- a/beecrypt/AUTHORS +++ b/beecrypt/AUTHORS @@ -1,3 +1,11 @@ BeeCrypt Cryptograpy Library: Bob Deblier + +C++ Interface: + +Bob Deblier + +Python Interface: + +Jeff Johson diff --git a/beecrypt/BENCHMARKS b/beecrypt/BENCHMARKS index 9eed9b1..efdd509 100644 --- a/beecrypt/BENCHMARKS +++ b/beecrypt/BENCHMARKS @@ -3,14 +3,18 @@ i.e. the amount of free memory, swapped memory, amount of cpu cache, etc. I've tried to make them as accurate as possible, within limits. Note: many of the testing systems were provided by HP's testdrive program; -many thanks to them for giving me access to their systems. +many thanks to them for giving me access to their systems. Also thanks to +SourceForge for their compile farm! Note: to avoid religious wars, in the table below read GNU/Linux for Linux - I'm just a little cramped for space... BENCHmark Modular Exponentation (more is better): +BeeCrypt 4.0.0 | gcc-3.3.3 | Fedora Core 2 | Athlon 64 3000+| 1 GB: 24740 +BeeCrypt 4.0.0 | gcc-3.2.2 | SuSE 8 EL | Opteron 1600 | 1 GB: 19460 BeeCrypt 3.0.0 | gcc-3.x | RedHat Linux | Opteron MP 1600 | : 17230 +BeeCrypt 3.2.0 | gcc-2.96 | RedHat AS 2.1 | Itanium 2 1400 | 1 GB: 11453 BeeCrypt 3.0.0 | gcc-3.2.2 | Debian Linux 3.0 | Itanium 2 900 | 12 GB: 7317 BeeCrypt 3.0.0 | gcc-3.3 | RedHat AS 2.1 | P4 Xeon 2400 | 4 GB: 6920 [--with-arch=pentium4] BeeCrypt 3.0.0 | gcc-2.95.4 | Debian Linux 3.0 | Alpha EV6.7 666 | 2 GB: 5742 @@ -29,9 +33,11 @@ BeeCrypt 3.0.0 | gcc-2.95.4 | Debian Linux 3.0r1 | M68030 25 BENCHmark Hash Function (more is better): MD5 +BeeCrypt 4.0.0 | gcc-3.3.3 | Fedora Core 2 | Athlon 64 3000+| 1 GB: 186.6 MB/s BeeCrypt 3.0.0 | gcc-2.96 | RedHat AS 2.1 | P4 Xeon 2400 | 4 GB: 137.0 MB/s [--with-arch=pentiumpro] SHA-1 +BeeCrypt 4.0.0 | gcc-3.3.3 | Fedora Core 2 | Athlon 64 3000+| 1 GB: 104.7 MB/s BeeCrypt 3.0.0 | gcc-2.96 | RedHat AS 2.1 | P4 Xeon 2400 | 4 GB: 77.0 MB/s [--with-arch=pentiumpro] SHA-256 diff --git a/beecrypt/BUGS b/beecrypt/BUGS index dcdbe0d..57bed50 100644 --- a/beecrypt/BUGS +++ b/beecrypt/BUGS @@ -2,13 +2,19 @@ Legend: - = open bug * = fixed bug -3.0.0pre: - - Intel icc can't cope with gcj headers; there's also a problem in - combination with aio.h. Solution should be to not test gcj when using - this compiler. As a workaround, you can specify --without-javaglue. - - GCC 3.3 produces faster output for Blowfish than the included assembler - source; try coding two Blowfish rounds (without swap) in C and compile - to assembler to see how GCC accomplishes this. +3.1.0: + * Error in final result computation of mpextgcd_w in certain circumstances. + * PowerPC 64-bit assembler symbols aren't defined according to LSB 1.3. + +3.0.0: + - Can't seem to generate 64-bit shared libraries on AIX; use + --disable-shared on this platform for now. + - Intel icc can't cope with gcj headers. There's also a problem in + combination with aio.h; solution should be to not test gcj when using + this compiler. As a workaround, you can specify --without-javaglue. + - GCC 3.3 produces faster output for Blowfish on Pentium 4 than the + included assembler source; try coding two Blowfish rounds (without swap) + in C and compile to assembler to see how GCC accomplishes this. 2.3.0pre: * bug in certain instances of computing modular inverse. diff --git a/beecrypt/CONTRIBUTORS b/beecrypt/CONTRIBUTORS index 6a9cee9..7f61011 100644 --- a/beecrypt/CONTRIBUTORS +++ b/beecrypt/CONTRIBUTORS @@ -1,5 +1,6 @@ I would like to thank the following people (in alphabetical order): +- Seth Arnold, for contributing to the documentation. - Jan-Rudolph Bührmann, for helping me get started on the 64-bit multi- precision integer library. - Luca Filipozzi, maintainer/packager of BeeCrypt for Debian GNU/Linux. diff --git a/beecrypt/COPYING b/beecrypt/COPYING index d60c31a..a6d7d01 100644 --- a/beecrypt/COPYING +++ b/beecrypt/COPYING @@ -325,16 +325,12 @@ mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice +necessary. Hereny it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Library General -Public License instead of this License. + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Section \ No newline at end of file diff --git a/beecrypt/DOCUMENTATION b/beecrypt/DOCUMENTATION deleted file mode 100644 index fb36fd2..0000000 --- a/beecrypt/DOCUMENTATION +++ /dev/null @@ -1 +0,0 @@ -To generate the documentation, please use doxygen. diff --git a/beecrypt/Doxyfile.in b/beecrypt/Doxyfile.in index 3a897a3..6784705 100644 --- a/beecrypt/Doxyfile.in +++ b/beecrypt/Doxyfile.in @@ -1,4 +1,4 @@ -# Doxyfile 1.2.10 +# Doxyfile 1.3.4 # This file describes the settings to be used by the documentation system # doxygen (www.doxygen.org) for a project @@ -11,7 +11,7 @@ # Values that contain spaces should be placed between quotes (" ") #--------------------------------------------------------------------------- -# General configuration options +# Project related configuration options #--------------------------------------------------------------------------- # The PROJECT_NAME tag is a single word (or a sequence of words surrounded @@ -36,43 +36,22 @@ OUTPUT_DIRECTORY = @top_srcdir@/docs # documentation generated by doxygen is written. Doxygen will use this # information to generate all constant output in the proper language. # The default language is English, other supported languages are: -# Brazilian, Chinese, Croatian, Czech, Danish, Dutch, Finnish, French, -# German, Hungarian, Italian, Japanese, Korean, Norwegian, Polish, -# Portuguese, Romanian, Russian, Slovak, Slovene, Spanish and Swedish. +# Brazilian, Catalan, Chinese, Chinese-Traditional, Croatian, Czech, Danish, Dutch, +# Finnish, French, German, Greek, Hungarian, Italian, Japanese, Japanese-en +# (Japanese with English messages), Korean, Norwegian, Polish, Portuguese, +# Romanian, Russian, Serbian, Slovak, Slovene, Spanish, Swedish, and Ukrainian. OUTPUT_LANGUAGE = English -# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in -# documentation are documented, even if no documentation was available. -# Private class members and static file members will be hidden unless -# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES - -EXTRACT_ALL = YES +# This tag can be used to specify the encoding used in the generated output. +# The encoding is not always determined by the language that is chosen, +# but also whether or not the output is meant for Windows or non-Windows users. +# In case there is a difference, setting the USE_WINDOWS_ENCODING tag to YES +# forces the Windows encoding (this is the default for the Windows binary), +# whereas setting the tag to NO uses a Unix-style encoding (the default for +# all platforms other than Windows). -# If the EXTRACT_PRIVATE tag is set to YES all private members of a class -# will be included in the documentation. - -EXTRACT_PRIVATE = NO - -# If the EXTRACT_STATIC tag is set to YES all static members of a file -# will be included in the documentation. - -EXTRACT_STATIC = YES - -# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all -# undocumented members of documented classes, files or namespaces. -# If set to NO (the default) these members will be included in the -# various overviews, but no documentation section is generated. -# This option has no effect if EXTRACT_ALL is enabled. - -HIDE_UNDOC_MEMBERS = NO - -# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all -# undocumented classes that are normally visible in the class hierarchy. -# If set to NO (the default) these class will be included in the various -# overviews. This option has no effect if EXTRACT_ALL is enabled. - -HIDE_UNDOC_CLASSES = NO +USE_WINDOWS_ENCODING = NO # If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will # include brief member descriptions after the members that are listed in @@ -94,94 +73,187 @@ REPEAT_BRIEF = YES ALWAYS_DETAILED_SEC = NO +# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all inherited +# members of a class in the documentation of that class as if those members were +# ordinary class members. Constructors, destructors and assignment operators of +# the base classes will not be shown. + +INLINE_INHERITED_MEMB = NO + # If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full # path before files name in the file list and in the header files. If set # to NO the shortest path that makes the file name unique will be used. -FULL_PATH_NAMES = NO +FULL_PATH_NAMES = YES # If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag -# can be used to strip a user defined part of the path. Stripping is +# can be used to strip a user-defined part of the path. Stripping is # only done if one of the specified strings matches the left-hand part of # the path. It is allowed to use relative paths in the argument list. STRIP_FROM_PATH = @top_srcdir@/ -# The INTERNAL_DOCS tag determines if documentation -# that is typed after a \internal command is included. If the tag is set -# to NO (the default) then the documentation will be excluded. -# Set it to YES to include the internal documentation. +# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter +# (but less readable) file names. This can be useful is your file systems +# doesn't support long names like on DOS, Mac, or CD-ROM. -INTERNAL_DOCS = YES +SHORT_NAMES = NO -# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will -# generate a class diagram (in Html and LaTeX) for classes with base or -# super classes. Setting the tag to NO turns the diagrams off. +# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen +# will interpret the first line (until the first dot) of a JavaDoc-style +# comment as the brief description. If set to NO, the JavaDoc +# comments will behave just like the Qt-style comments (thus requiring an +# explict @brief command for a brief description. -CLASS_DIAGRAMS = YES +JAVADOC_AUTOBRIEF = YES -# If the SOURCE_BROWSER tag is set to YES then a list of source files will -# be generated. Documented entities will be cross-referenced with these sources. +# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen +# treat a multi-line C++ special comment block (i.e. a block of //! or /// +# comments) as a brief description. This used to be the default behaviour. +# The new default is to treat a multi-line C++ comment block as a detailed +# description. Set this tag to YES if you prefer the old behaviour instead. -SOURCE_BROWSER = YES +MULTILINE_CPP_IS_BRIEF = NO -# Setting the INLINE_SOURCES tag to YES will include the body -# of functions and classes directly in the documentation. +# If the DETAILS_AT_TOP tag is set to YES then Doxygen +# will output the detailed description near the top, like JavaDoc. +# If set to NO, the detailed description appears after the member +# documentation. -INLINE_SOURCES = NO +DETAILS_AT_TOP = NO -# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct -# doxygen to hide any special comment blocks from generated source code -# fragments. Normal C and C++ comments will always remain visible. +# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented +# member inherits the documentation from any documented member that it +# reimplements. -STRIP_CODE_COMMENTS = YES +INHERIT_DOCS = YES + +# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC +# tag is set to YES, then doxygen will reuse the documentation of the first +# member in the group (if any) for the other members of the group. By default +# all members of a group must be documented explicitly. + +DISTRIBUTE_GROUP_DOC = NO + +# The TAB_SIZE tag can be used to set the number of spaces in a tab. +# Doxygen uses this value to replace tabs by spaces in code fragments. + +TAB_SIZE = 4 + +# This tag can be used to specify a number of aliases that acts +# as commands in the documentation. An alias has the form "name=value". +# For example adding "sideeffect=\par Side Effects:\n" will allow you to +# put the command \sideeffect (or @sideeffect) in the documentation, which +# will result in a user-defined paragraph with heading "Side Effects:". +# You can put \n's in the value part of an alias to insert newlines. + +ALIASES = + +# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources +# only. Doxygen will then generate output that is more tailored for C. +# For instance, some of the names that are used will be different. The list +# of all members will be omitted, etc. + +OPTIMIZE_OUTPUT_FOR_C = YES + +# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java sources +# only. Doxygen will then generate output that is more tailored for Java. +# For instance, namespaces will be presented as packages, qualified scopes +# will look different, etc. + +OPTIMIZE_OUTPUT_JAVA = NO + +# Set the SUBGROUPING tag to YES (the default) to allow class member groups of +# the same type (for instance a group of public functions) to be put as a +# subgroup of that type (e.g. under the Public Functions section). Set it to +# NO to prevent subgrouping. Alternatively, this can be done per class using +# the \nosubgrouping command. + +SUBGROUPING = YES + +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- + +# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in +# documentation are documented, even if no documentation was available. +# Private class members and static file members will be hidden unless +# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES + +EXTRACT_ALL = YES + +# If the EXTRACT_PRIVATE tag is set to YES all private members of a class +# will be included in the documentation. + +EXTRACT_PRIVATE = NO + +# If the EXTRACT_STATIC tag is set to YES all static members of a file +# will be included in the documentation. + +EXTRACT_STATIC = YES + +# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) +# defined locally in source files will be included in the documentation. +# If set to NO only classes defined in header files are included. + +EXTRACT_LOCAL_CLASSES = YES + +# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all +# undocumented members of documented classes, files or namespaces. +# If set to NO (the default) these members will be included in the +# various overviews, but no documentation section is generated. +# This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_MEMBERS = NO + +# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all +# undocumented classes that are normally visible in the class hierarchy. +# If set to NO (the default) these classes will be included in the various +# overviews. This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_CLASSES = NO + +# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all +# friend (class|struct|union) declarations. +# If set to NO (the default) these declarations will be included in the +# documentation. + +HIDE_FRIEND_COMPOUNDS = NO + +# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any +# documentation blocks found inside the body of a function. +# If set to NO (the default) these blocks will be appended to the +# function's detailed documentation block. + +HIDE_IN_BODY_DOCS = NO + +# The INTERNAL_DOCS tag determines if documentation +# that is typed after a \internal command is included. If the tag is set +# to NO (the default) then the documentation will be excluded. +# Set it to YES to include the internal documentation. + +INTERNAL_DOCS = YES # If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate -# file names in lower case letters. If set to YES upper case letters are also +# file names in lower-case letters. If set to YES upper-case letters are also # allowed. This is useful if you have classes or files whose names only differ # in case and if your file system supports case sensitive file names. Windows -# users are adviced to set this option to NO. +# users are advised to set this option to NO. CASE_SENSE_NAMES = YES -# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter -# (but less readable) file names. This can be useful is your file systems -# doesn't support long names like on DOS, Mac, or CD-ROM. - -SHORT_NAMES = NO - # If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen # will show members with their full class and namespace scopes in the # documentation. If set to YES the scope will be hidden. HIDE_SCOPE_NAMES = NO -# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen -# will generate a verbatim copy of the header file for each class for -# which an include is specified. Set to NO to disable this. - -VERBATIM_HEADERS = YES - # If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen -# will put list of the files that are included by a file in the documentation +# will put a list of the files that are included by a file in the documentation # of that file. SHOW_INCLUDE_FILES = YES -# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen -# will interpret the first line (until the first dot) of a JavaDoc-style -# comment as the brief description. If set to NO, the JavaDoc -# comments will behave just like the Qt-style comments (thus requiring an -# explict @brief command for a brief description. - -JAVADOC_AUTOBRIEF = YES - -# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented -# member inherits the documentation from any documented member that it -# reimplements. - -INHERIT_DOCS = YES - # If the INLINE_INFO tag is set to YES (the default) then a tag [inline] # is inserted in the documentation for inline members. @@ -194,18 +266,6 @@ INLINE_INFO = YES SORT_MEMBER_DOCS = YES -# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC -# tag is set to YES, then doxygen will reuse the documentation of the first -# member in the group (if any) for the other members of the group. By default -# all members of a group must be documented explicitly. - -DISTRIBUTE_GROUP_DOC = NO - -# The TAB_SIZE tag can be used to set the number of spaces in a tab. -# Doxygen uses this value to replace tabs by spaces in code fragments. - -TAB_SIZE = 4 - # The GENERATE_TODOLIST tag can be used to enable (YES) or # disable (NO) the todo list. This list is created by putting \todo # commands in the documentation. @@ -224,14 +284,11 @@ GENERATE_TESTLIST = YES GENERATE_BUGLIST = YES -# This tag can be used to specify a number of aliases that acts -# as commands in the documentation. An alias has the form "name=value". -# For example adding "sideeffect=\par Side Effects:\n" will allow you to -# put the command \sideeffect (or @sideeffect) in the documentation, which -# will result in a user defined paragraph with heading "Side Effects:". -# You can put \n's in the value part of an alias to insert newlines. +# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or +# disable (NO) the deprecated list. This list is created by putting +# \deprecated commands in the documentation. -ALIASES = +GENERATE_DEPRECATEDLIST= YES # The ENABLED_SECTIONS tag can be used to enable conditional # documentation sections, marked by \if sectionname ... \endif. @@ -239,7 +296,7 @@ ALIASES = ENABLED_SECTIONS = # The MAX_INITIALIZER_LINES tag determines the maximum number of lines -# the initial value of a variable or define consist of for it to appear in +# the initial value of a variable or define consists of for it to appear in # the documentation. If the initializer consists of more lines than specified # here it will be hidden. Use a value of 0 to hide initializers completely. # The appearance of the initializer of individual variables and defines in the @@ -248,13 +305,6 @@ ENABLED_SECTIONS = MAX_INITIALIZER_LINES = 30 -# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources -# only. Doxygen will then generate output that is more tailored for C. -# For instance some of the names that are used will be different. The list -# of all members will be omitted, etc. - -OPTIMIZE_OUTPUT_FOR_C = YES - # Set the SHOW_USED_FILES tag to NO to disable the list of files generated # at the bottom of the documentation of classes and structs. If set to YES the # list will mention the files that were used to generate the documentation. @@ -282,6 +332,13 @@ WARNINGS = YES WARN_IF_UNDOCUMENTED = YES +# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for +# potential errors in the documentation, such as not documenting some +# parameters in a documented function, or documenting parameters that +# don't exist or using markup commands wrongly. + +WARN_IF_DOC_ERROR = YES + # The WARN_FORMAT tag determines the format of the warning messages that # doxygen can produce. The string should contain the $file, $line, and $text # tags, which will be replaced by the file and line number from which the @@ -304,14 +361,27 @@ WARN_LOGFILE = # directories like "/usr/src/myproject". Separate the files or directories # with spaces. -INPUT = \ - @top_srcdir@/Doxyheader \ - @top_srcdir@/ +INPUT = @top_srcdir@/Doxyheader \ + @top_srcdir@/ \ + @top_srcdir@/c++ \ + @top_srcdir@/c++/crypto \ + @top_srcdir@/c++/crypto/interfaces \ + @top_srcdir@/c++/crypto/spec \ + @top_srcdir@/c++/io \ + @top_srcdir@/c++/lang \ + @top_srcdir@/c++/provider \ + @top_srcdir@/c++/security \ + @top_srcdir@/c++/security/cert \ + @top_srcdir@/c++/security/interfaces \ + @top_srcdir@/c++/security/spec \ + @top_srcdir@/c++/util # If the value of the INPUT tag contains directories, you can use the # FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp # and *.h) to filter out the source-files in the directories. If left -# blank all files are included. +# blank the following patterns are tested: +# *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx *.hpp +# *.h++ *.idl *.odl *.cs *.php *.php3 *.inc FILE_PATTERNS = *.h @@ -327,11 +397,16 @@ RECURSIVE = NO EXCLUDE = +# The EXCLUDE_SYMLINKS tag can be used select whether or not files or directories +# that are symbolic links (a Unix filesystem feature) are excluded from the input. + +EXCLUDE_SYMLINKS = NO + # If the value of the INPUT tag contains directories, you can use the # EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude # certain files from those directories. -EXCLUDE_PATTERNS = +EXCLUDE_PATTERNS = *config*.h # The EXAMPLE_PATH tag can be used to specify one or more files or # directories that contain example code fragments that are included (see @@ -346,6 +421,13 @@ EXAMPLE_PATH = @top_srcdir@/docs EXAMPLE_PATTERNS = +# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be +# searched for input files to be used with the \include or \dontinclude +# commands irrespective of the value of the RECURSIVE tag. +# Possible values are YES and NO. If left blank NO is used. + +EXAMPLE_RECURSIVE = NO + # The IMAGE_PATH tag can be used to specify one or more files or # directories that contain image that are included in the documentation (see # the \image command). @@ -363,11 +445,49 @@ INPUT_FILTER = # If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using # INPUT_FILTER) will be used to filter the input files when producing source -# files to browse. +# files to browse (i.e. when SOURCE_BROWSER is set to YES). FILTER_SOURCE_FILES = NO #--------------------------------------------------------------------------- +# configuration options related to source browsing +#--------------------------------------------------------------------------- + +# If the SOURCE_BROWSER tag is set to YES then a list of source files will +# be generated. Documented entities will be cross-referenced with these sources. + +SOURCE_BROWSER = NO + +# Setting the INLINE_SOURCES tag to YES will include the body +# of functions and classes directly in the documentation. + +INLINE_SOURCES = NO + +# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct +# doxygen to hide any special comment blocks from generated source code +# fragments. Normal C and C++ comments will always remain visible. + +STRIP_CODE_COMMENTS = YES + +# If the REFERENCED_BY_RELATION tag is set to YES (the default) +# then for each documented function all documented +# functions referencing it will be listed. + +REFERENCED_BY_RELATION = YES + +# If the REFERENCES_RELATION tag is set to YES (the default) +# then for each documented function all documented entities +# called/used by that function will be listed. + +REFERENCES_RELATION = YES + +# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen +# will generate a verbatim copy of the header file for each class for +# which an include is specified. Set to NO to disable this. + +VERBATIM_HEADERS = YES + +#--------------------------------------------------------------------------- # configuration options related to the alphabetical class index #--------------------------------------------------------------------------- @@ -403,7 +523,13 @@ GENERATE_HTML = YES # If a relative path is entered the value of OUTPUT_DIRECTORY will be # put in front of it. If left blank `html' will be used as the default path. -HTML_OUTPUT = +HTML_OUTPUT = + +# The HTML_FILE_EXTENSION tag can be used to specify the file extension for +# each generated HTML page (for example: .htm,.php,.asp). If it is left blank +# doxygen will generate files with .html extension. + +HTML_FILE_EXTENSION = .html # The HTML_HEADER tag can be used to specify a personal HTML header for # each generated HTML page. If it is left blank doxygen will generate a @@ -417,7 +543,7 @@ HTML_HEADER = HTML_FOOTER = -# The HTML_STYLESHEET tag can be used to specify a user defined cascading +# The HTML_STYLESHEET tag can be used to specify a user-defined cascading # style sheet that is used by each HTML page. It can be used to # fine-tune the look of the HTML output. If the tag is left blank doxygen # will generate a default style sheet @@ -437,6 +563,20 @@ HTML_ALIGN_MEMBERS = YES GENERATE_HTMLHELP = NO +# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can +# be used to specify the file name of the resulting .chm file. You +# can add a path in front of the file if the result should not be +# written to the html output dir. + +CHM_FILE = + +# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can +# be used to specify the location (absolute path including file name) of +# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run +# the HTML help compiler on the generated index.hhp. + +HHC_LOCATION = + # If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag # controls if a separate .chi index file is generated (YES) or that # it should be included in the master .chm file (NO). @@ -450,7 +590,7 @@ GENERATE_CHI = NO BINARY_TOC = NO # The TOC_EXPAND flag can be set to YES to add extra items for group members -# to the contents of the Html help documentation and to the tree view. +# to the contents of the HTML help documentation and to the tree view. TOC_EXPAND = NO @@ -468,8 +608,9 @@ ENUM_VALUES_PER_LINE = 4 # If the GENERATE_TREEVIEW tag is set to YES, a side panel will be # generated containing a tree-like index structure (just like the one that # is generated for HTML Help). For this to work a browser that supports -# JavaScript and frames is required (for instance Netscape 4.0+ -# or Internet explorer 4.0+). +# JavaScript, DHTML, CSS and frames is required (for instance Mozilla 1.0+, +# Netscape 6.0+, Internet explorer 5.0+, or Konqueror). Windows users are +# probably better off using the HTML help feature. GENERATE_TREEVIEW = NO @@ -492,7 +633,18 @@ GENERATE_LATEX = YES # If a relative path is entered the value of OUTPUT_DIRECTORY will be # put in front of it. If left blank `latex' will be used as the default path. -LATEX_OUTPUT = +LATEX_OUTPUT = + +# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be +# invoked. If left blank `latex' will be used as the default command name. + +LATEX_CMD_NAME = latex + +# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to +# generate index for LaTeX. If left blank `makeindex' will be used as the +# default command name. + +MAKEINDEX_CMD_NAME = makeindex # If the COMPACT_LATEX tag is set to YES Doxygen generates more compact # LaTeX documents. This may be useful for small projects and may help to @@ -538,6 +690,12 @@ USE_PDFLATEX = YES LATEX_BATCHMODE = NO +# If LATEX_HIDE_INDICES is set to YES then doxygen will not +# include the index chapters (such as File Index, Compound Index, etc.) +# in the output. + +LATEX_HIDE_INDICES = NO + #--------------------------------------------------------------------------- # configuration options related to the RTF output #--------------------------------------------------------------------------- @@ -593,17 +751,17 @@ GENERATE_MAN = NO # If a relative path is entered the value of OUTPUT_DIRECTORY will be # put in front of it. If left blank `man' will be used as the default path. -MAN_OUTPUT = +MAN_OUTPUT = # The MAN_EXTENSION tag determines the extension that is added to # the generated man pages (default is the subroutine's section .3) MAN_EXTENSION = -# If the MAN_LINKS tag is set to YES and Doxygen generates man output, -# then it will generate one additional man file for each entity -# documented in the real man page(s). These additional files -# only source the real man page, but without them the man command +# If the MAN_LINKS tag is set to YES and Doxygen generates man output, +# then it will generate one additional man file for each entity +# documented in the real man page(s). These additional files +# only source the real man page, but without them the man command # would be unable to find the correct page. The default is NO. MAN_LINKS = NO @@ -620,6 +778,69 @@ MAN_LINKS = NO GENERATE_XML = NO +# The XML_OUTPUT tag is used to specify where the XML pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `xml' will be used as the default path. + +XML_OUTPUT = xml + +# The XML_SCHEMA tag can be used to specify an XML schema, +# which can be used by a validating XML parser to check the +# syntax of the XML files. + +XML_SCHEMA = + +# The XML_DTD tag can be used to specify an XML DTD, +# which can be used by a validating XML parser to check the +# syntax of the XML files. + +XML_DTD = + +#--------------------------------------------------------------------------- +# configuration options for the AutoGen Definitions output +#--------------------------------------------------------------------------- + +# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will +# generate an AutoGen Definitions (see autogen.sf.net) file +# that captures the structure of the code including all +# documentation. Note that this feature is still experimental +# and incomplete at the moment. + +GENERATE_AUTOGEN_DEF = NO + +#--------------------------------------------------------------------------- +# configuration options related to the Perl module output +#--------------------------------------------------------------------------- + +# If the GENERATE_PERLMOD tag is set to YES Doxygen will +# generate a Perl module file that captures the structure of +# the code including all documentation. Note that this +# feature is still experimental and incomplete at the +# moment. + +GENERATE_PERLMOD = NO + +# If the PERLMOD_LATEX tag is set to YES Doxygen will generate +# the necessary Makefile rules, Perl scripts and LaTeX code to be able +# to generate PDF and DVI output from the Perl module output. + +PERLMOD_LATEX = NO + +# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be +# nicely formatted so it can be parsed by a human reader. This is useful +# if you want to understand what is going on. On the other hand, if this +# tag is set to NO the size of the Perl module output will be much smaller +# and Perl will parse it just the same. + +PERLMOD_PRETTY = YES + +# The names of the make variables in the generated doxyrules.make file +# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. +# This is useful so different doxyrules.make files included by the same +# Makefile don't overwrite each other's variables. + +PERLMOD_MAKEVAR_PREFIX = + #--------------------------------------------------------------------------- # Configuration options related to the preprocessor #--------------------------------------------------------------------------- @@ -635,7 +856,7 @@ ENABLE_PREPROCESSING = YES # compilation will be performed. Macro expansion can be done in a controlled # way by setting EXPAND_ONLY_PREDEF to YES. -MACRO_EXPANSION = YES +MACRO_EXPANSION = NO # If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES # then the macro expansion is limited to the macros specified with the @@ -667,20 +888,41 @@ INCLUDE_FILE_PATTERNS = # or name=definition (no spaces). If the definition and the = are # omitted =1 is assumed. -PREDEFINED = +PREDEFINED = __cplusplus MP_WBITS=@MP_WBITS@ -# If the MACRO_EXPANSION and EXPAND_PREDEF_ONLY tags are set to YES then +# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then # this tag can be used to specify a list of macro names that should be expanded. # The macro definition that is found in the sources will be used. # Use the PREDEFINED tag if you want to use a different macro definition. EXPAND_AS_DEFINED = +# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then +# doxygen's preprocessor will remove all function-like macros that are alone +# on a line, have an all uppercase name, and do not end with a semicolon. Such +# function macros are typically used for boiler-plate code, and will confuse the +# parser if not removed. + +SKIP_FUNCTION_MACROS = YES + #--------------------------------------------------------------------------- # Configuration::addtions related to external references #--------------------------------------------------------------------------- -# The TAGFILES tag can be used to specify one or more tagfiles. +# The TAGFILES option can be used to specify one or more tagfiles. +# Optionally an initial location of the external documentation +# can be added for each tagfile. The format of a tag file without +# this location is as follows: +# TAGFILES = file1 file2 ... +# Adding location for the tag files is done as follows: +# TAGFILES = file1=loc1 "file2 = loc2" ... +# where "loc1" and "loc2" can be relative or absolute paths or +# URLs. If a location is present for each tag, the installdox tool +# does not have to be run to correct the links. +# Note that each tag file must have a unique name +# (where the name does NOT include the path) +# If a tag file is not located in the directory in which doxygen +# is run, you must also specify the path to the tagfile here. TAGFILES = @@ -695,6 +937,12 @@ GENERATE_TAGFILE = ALLEXTERNALS = NO +# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed +# in the modules index. If set to NO, only the current project's groups will +# be listed. + +EXTERNAL_GROUPS = YES + # The PERL_PATH should be the absolute path and name of the perl script # interpreter (i.e. the result of `which perl'). @@ -704,12 +952,26 @@ PERL_PATH = /usr/bin/perl # Configuration options related to the dot tool #--------------------------------------------------------------------------- +# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will +# generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base or +# super classes. Setting the tag to NO turns the diagrams off. Note that this +# option is superceded by the HAVE_DOT option below. This is only a fallback. It is +# recommended to install and use dot, since it yields more powerful graphs. + +CLASS_DIAGRAMS = YES + +# If set to YES, the inheritance and collaboration graphs will hide +# inheritance and usage relations if the target is undocumented +# or is not a class. + +HIDE_UNDOC_RELATIONS = YES + # If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is # available from the path. This tool is part of Graphviz, a graph visualization # toolkit from AT&T and Lucent Bell Labs. The other options in this section # have no effect if this option is set to NO (the default) -HAVE_DOT = NO +HAVE_DOT = YES # If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen # will generate a graph for each documented class showing the direct and @@ -725,6 +987,12 @@ CLASS_GRAPH = YES COLLABORATION_GRAPH = YES +# If the UML_LOOK tag is set to YES doxygen will generate inheritance and +# collaboration diagrams in a style similiar to the OMG's Unified Modeling +# Language. + +UML_LOOK = NO + # If set to YES, the inheritance and collaboration graphs will show the # relations between templates and their instances. @@ -744,11 +1012,25 @@ INCLUDE_GRAPH = YES INCLUDED_BY_GRAPH = YES +# If the CALL_GRAPH and HAVE_DOT tags are set to YES then doxygen will +# generate a call dependency graph for every global function or class method. +# Note that enabling this option will significantly increase the time of a run. +# So in most cases it will be better to enable call graphs for selected +# functions only using the \callgraph command. + +CALL_GRAPH = NO + # If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen # will graphical hierarchy of all classes instead of a textual one. GRAPHICAL_HIERARCHY = YES +# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images +# generated by dot. Possible values are png, jpg, or gif +# If left blank png will be used. + +DOT_IMAGE_FORMAT = png + # The tag DOT_PATH can be used to specify the path where the dot tool can be # found. If left blank, it is assumed the dot tool can be found on the path. @@ -776,6 +1058,17 @@ MAX_DOT_GRAPH_WIDTH = 1024 MAX_DOT_GRAPH_HEIGHT = 1024 +# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the +# graphs generated by dot. A depth value of 3 means that only nodes reachable +# from the root by following a path via at most 3 edges will be shown. Nodes that +# lay further from the root node will be omitted. Note that setting this option to +# 1 or 2 may greatly reduce the computation time needed for large code bases. Also +# note that a graph may be further truncated if the graph's image dimensions are +# not sufficient to fit the graph (see MAX_DOT_GRAPH_WIDTH and MAX_DOT_GRAPH_HEIGHT). +# If 0 is used for the depth value (the default), the graph is not depth-constrained. + +MAX_DOT_GRAPH_DEPTH = 0 + # If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will # generate a legend page explaining the meaning of the various boxes and # arrows in the dot generated graphs. @@ -783,7 +1076,7 @@ MAX_DOT_GRAPH_HEIGHT = 1024 GENERATE_LEGEND = YES # If the DOT_CLEANUP tag is set to YES (the default) Doxygen will -# remove the intermedate dot files that are used to generate +# remove the intermediate dot files that are used to generate # the various graphs. DOT_CLEANUP = YES @@ -796,38 +1089,3 @@ DOT_CLEANUP = YES # used. If set to NO the values of all tags below this one will be ignored. SEARCHENGINE = NO - -# The CGI_NAME tag should be the name of the CGI script that -# starts the search engine (doxysearch) with the correct parameters. -# A script with this name will be generated by doxygen. - -CGI_NAME = - -# The CGI_URL tag should be the absolute URL to the directory where the -# cgi binaries are located. See the documentation of your http daemon for -# details. - -CGI_URL = - -# The DOC_URL tag should be the absolute URL to the directory where the -# documentation is located. If left blank the absolute path to the -# documentation, with file:// prepended to it, will be used. - -DOC_URL = - -# The DOC_ABSPATH tag should be the absolute path to the directory where the -# documentation is located. If left blank the directory on the local machine -# will be used. - -DOC_ABSPATH = - -# The BIN_ABSPATH tag must point to the directory where the doxysearch binary -# is installed. - -BIN_ABSPATH = /usr/bin - -# The EXT_DOC_PATHS tag can be used to specify one or more paths to -# documentation generated for other projects. This allows doxysearch to search -# the documentation for these projects as well. - -EXT_DOC_PATHS = diff --git a/beecrypt/Doxyheader b/beecrypt/Doxyheader index 2f38355..d83fdb9 100644 --- a/beecrypt/Doxyheader +++ b/beecrypt/Doxyheader @@ -3,7 +3,8 @@ BeeCrypt started its life when the need for a portable and fast cryptography library arose at Virtual Unlimited in 1997. I'm still trying to make it faster, easier to use and more portable, in addition to providing better -documentation. +documentation. The library is currently in full swing again, thanks to the +Beeyond Software Holding BV. BeeCrypt is released under the following license: @@ -26,58 +27,82 @@ cryptography may be limited or forbidden by law. Before using this library, make sure you are legally entitled to do so. Included in the library are: - - entropy sources for initializing pseudo-random generators - - pseudo-random generators - - FIPS-186 - - Mersenne Twister - - block ciphers - - AES - - Blowfish - - hash functions - - MD5 - - SHA-1 - - SHA-256 - - keyed hash functions (a.k.a. message authentication codes) - - HMAC-MD5 - - HMAC-SHA-1 - - HMAC-SHA-256 - - multi-precision integer library, with assembler-optimized routines - for a range of processors; optimized to perform well on both 32-bit - and 64-bit machines - - probabilistic primality testing, with optimized small prime trial - division - - discrete logarithm parameter generation over a prime field - - Diffie-Hellman key agreement - - DHAES encryption scheme - - DSA signature scheme - - ElGamal signature scheme (two variants) - - RSA keypair generation with chinese remainder theorem variables - - RSA public & private key operations +
    +
  • entropy sources for initializing pseudo-random generators +
  • pseudo-random generators +
      +
    • FIPS-186 +
    +
  • block ciphers +
      +
    • AES +
    • Blowfish +
    +
  • hash functions +
      +
    • MD5 +
    • SHA-1 +
    • SHA-256 +
    +
  • keyed hash functions (a.k.a. message authentication codes) +
      +
    • HMAC-MD5 +
    • HMAC-SHA-1 +
    • HMAC-SHA-256 +
    +
  • multi-precision integer library, with assembler-optimized routines + for a range of processors; optimized to perform well on both 32-bit + and 64-bit machines; uses Barrett modular reduction instead of the + more common usual Montgomery algorithm; also implements sliding + windows. +
  • probabilistic primality testing, with optimized small prime trial + division +
  • discrete logarithm parameter generation over a prime field +
  • Diffie-Hellman key agreement +
  • DHAES encryption scheme +
  • DSA signature scheme +
  • ElGamal signature scheme (two variants) +
  • RSA keypair generation with chinese remainder theorem variables +
  • RSA public & private key operations +
-Planned for the near future are: - - compliance with and compliance statements for IEEE P1363 - - more blockciphers (Twofish, ... ) - - more hash functions (RIPEMD-160, SHA-384, SHA-512, HAVAL, Tiger) - - RSA signatures as specified by RFC-2440. - - Elliptic Curves (ECDSA, ... ) - - more blockcipher modes (OFB, ... ) +A new feature in version 4.x is the C++ API, built to resemble Java's security +and cryptography API. At this moment the number of classes provided is just +enough to build CSPs. If there is enough interest, we may expand this library. + +Planned for the future are: +
    +
  • compliance with and compliance statements for IEEE P1363 +
  • more blockciphers (Twofish, ... ) +
  • more blockcipher modes (CTR, OFB, ... ) +
  • more hash functions (RIPEMD-160, SHA-384, SHA-512, HAVAL, Tiger) +
  • RSA signatures as specified by RFC-2440. +
  • Elliptic Curves (ECDSA, ... ) +
The library has been tested on the following platforms: - - Linux glibc 2.x alpha - - Linux glibc 2.x arm - - Linux glibc 2.x ia64 - - Linux glibc 2.x m68k - - Linux glibc 2.x ppc - - Linux glibc 2.x s390x - - Linux glibc 2.x sparc - - Linux glibc 2.x x86 - - Solaris 2.[6789] sparc (with Forte or GNU compilers) - - Solaris 2.[78] x86 (with Forte or GNU compilers) - - Tru64 Unix alpha - - Win32 (Windows 95, 98, NT 4.0, 2000, XP) - - AIX (shared libraries don't seem to work in 64-bit mode) - - Darwin (javaglue doesn't compile yet) - - Cygwin (the DLL builds now, but needs to be tested) +
    +
  • Darwin +
  • Linux glibc 2.x alpha +
  • Linux glibc 2.x arm +
  • Linux glibc 2.x ia64 +
  • Linux glibc 2.x m68k +
  • Linux glibc 2.x ppc +
  • Linux glibc 2.x s390x +
  • Linux glibc 2.x sparc +
  • Linux glibc 2.x x86 +
  • Linux glibc 2.x x86_64 +
  • Solaris 2.[6789] sparc (with Forte or GNU compilers) +
  • Solaris 2.[78] x86 (with Forte or GNU compilers) +
  • Tru64 Unix alpha +
  • Win32 (Windows 95, 98, NT 4.0, 2000, XP) +
+ +The library is currently in the process of being ported to: +
    +
  • AIX (shared libraries don't seem to work in 64-bit mode) +
  • Cygwin (the DLL builds now, but needs to be tested) +
The structures in the library are geared towards exchange with Java and its security and cryptography classes. This library can also be @@ -86,63 +111,91 @@ provider and the counterpart of this library. */ -/*! \defgroup ES_m Entropy sources +/*!\defgroup ES_m Entropy sources + */ +/*!\defgroup ES_audio_m Entropy sources: /dev/audio + */ +/*!\defgroup ES_dsp_m Entropy sources: /dev/dsp + */ +/*!\defgroup ES_random_m Entropy sources: /dev/random + */ +/*!\defgroup ES_urandom_m Entropy sources: /dev/urandom + */ +/*!\defgroup ES_tty_m Entropy sources: /dev/tty + */ +/*!\defgroup PRNG_m Pseudo-Random Number Generators + */ +/*!\defgroup PRNG_fips186_m Pseudo-Random Number Generators: FIPS-186 + */ +/*!\defgroup PRNG_mt_m Pseudo-Random Number Generators: Mersenne Twister + */ +/*!\defgroup HASH_m Hash Functions + */ +/*!\defgroup HASH_md5_m Hash Functions: MD5 + */ +/*!\defgroup HASH_sha1_m Hash Functions: SHA-1 + */ +/*!\defgroup HASH_sha256_m Hash Functions: SHA-256 + */ +/*!\defgroup HMAC_m Keyed Hash Functions, a.k.a. Message Authentication Codes + */ +/*!\defgroup HMAC_md5_m Keyed Hash Functions: HMAC-MD5 */ -/*! \defgroup ES_audio_m Entropy sources: /dev/audio +/*!\defgroup HMAC_sha1_m Keyed Hash Functions: HMAC-SHA-1 */ -/*! \defgroup ES_dsp_m Entropy sources: /dev/dsp +/*!\defgroup HMAC_sha256_m Keyed Hash Functions: HMAC-SHA-256 */ -/*! \defgroup ES_random_m Entropy sources: /dev/random +/*!\defgroup BC_m Block ciphers */ -/*! \defgroup ES_urandom_m Entropy sources: /dev/urandom +/*!\defgroup BC_aes_m Block ciphers: AES */ -/*! \defgroup ES_tty_m Entropy sources: /dev/tty +/*!\defgroup BC_blowfish_m Block ciphers: Blowfish */ -/*! \defgroup PRNG_m Pseudo-Random Number Generators +/*!\defgroup MP_m Multiple Precision Integer Arithmetic */ -/*! \defgroup PRNG_fips186_m Pseudo-Random Number Generators: FIPS-186 +/*!\defgroup DL_m Discrete Logarithm Primitives */ -/*! \defgroup PRNG_mt_m Pseudo-Random Number Generators: Mersenne Twister +/*!\defgroup DL_dh_m Discrete Logarithm Primitives: Diffie-Hellman */ -/*! \defgroup HASH_m Hash Functions +/*!\defgroup DL_dsa_m Discrete Logarithm Primitives: DSA */ -/*! \defgroup HASH_md5_m Hash Functions: MD5 +/*!\defgroup DL_elgamal_m Discrete Logarithm Primitives: ElGamal */ -/*! \defgroup HASH_sha1_m Hash Functions: SHA-1 +/*!\defgroup IF_m Integer Factorization Primitives */ -/*! \defgroup HASH_sha256_m Hash Functions: SHA-256 +/*!\defgroup IF_rsa_m Integer Factorization Primitives: RSA */ -/*! \defgroup HMAC_m Keyed Hash Functions, a.k.a. Message Authentication Codes +/*!\defgroup PKCS1_m PKCS#1 */ -/*! \defgroup HMAC_md5_m Keyed Hash Functions: HMAC-MD5 +/*!\defgroup PKCS12_m PKCS#12 */ -/*! \defgroup HMAC_sha1_m Keyed Hash Functions: HMAC-SHA-1 +/*!\defgroup CXX_m C++ API */ -/*! \defgroup HMAC_sha256_m Keyed Hash Functions: HMAC-SHA-256 +/*!\defgroup CXX_CRYPTO_m C++ classes mimicking javax.crypto */ -/*! \defgroup BC_m Block ciphers +/*!\defgroup CXX_CRYPTO_INTERFACES_m C++ classes mimicking javax.crypto.interfaces */ -/*! \defgroup BC_aes_m Block ciphers: AES +/*!\defgroup CXX_CRYPTO_SPEC_m C++ classes mimicking javax.crypto.spec */ -/*! \defgroup BC_blowfish_m Block ciphers: Blowfish +/*!\defgroup CXX_IO_m C++ classes mimicking java.io */ -/*! \defgroup MP_m Multiple Precision Integer Arithmetic +/*!\defgroup CXX_LANG_m C++ classes mimicking java.lang */ -/*! \defgroup DL_m Discrete Logarithm Primitives +/*!\defgroup CXX_PROV_m C++ Base Cryptographic Service Provider */ -/*! \defgroup DL_dh_m Discrete Logarithm Primitives: Diffie-Hellman +/*!\defgroup CXX_SECURITY_m C++ classes mimicking java.security */ -/*! \defgroup DL_dsa_m Discrete Logarithm Primitives: DSA +/*!\defgroup CXX_SECURITY_CERT_m C++ classes mimicking java.security.cert */ -/*! \defgroup DL_elgamal_m Discrete Logarithm Primitives: ElGamal +/*!\defgroup CXX_SECURITY_INTERFACES_m C++ classes mimicking java.security.interfaces */ -/*! \defgroup IF_m Integer Factorization Primitives +/*!\defgroup CXX_SECURITY_SPEC_m C++ classes mimicking java.security.spec */ -/*! \defgroup IF_rsa_m Integer Factorization Primitives: RSA +/*!\defgroup CXX_UTIL_m C++ classes mimicking java.util */ -/*! \defgroup JAVA_m Java API +/*!\defgroup JAVA_m Java API */ -/*! \defgroup UNIT_m Unit tests +/*!\defgroup UNIT_m Unit tests */ -/*! \defgroup BENCH_m Benchmark tests +/*!\defgroup BENCH_m Benchmark tests */ diff --git a/beecrypt/Makefile.am b/beecrypt/Makefile.am index a7bcf83..5007bea 100644 --- a/beecrypt/Makefile.am +++ b/beecrypt/Makefile.am @@ -28,72 +28,39 @@ # 3. Interfaces removed (bad): Increment CURRENT, set AGE and REVISION to 0. # -LIBBEECRYPT_LT_CURRENT = 6 -LIBBEECRYPT_LT_AGE = 0 +LIBBEECRYPT_LT_CURRENT = 8 +LIBBEECRYPT_LT_AGE = 2 LIBBEECRYPT_LT_REVISION = 0 AUTOMAKE_OPTIONS = gnu check-news no-dependencies -LINT = splint - -SUBDIRS = . docs gas masm tests $(MAYBE_OPT) +SUBDIRS = . $(MAYBE_SUB) tests docs gas masm SUFFIXES = .s +INCLUDES = -I$(top_srcdir)/.. + .s.lo: $(LTCOMPILE) -c -o $@ `test -f $< || echo '$(srcdir)/'`$< -BEECRYPT_OBJECTS = aes.lo aesopt.lo base64.lo beecrypt.lo blockmode.lo blockpad.lo blowfish.lo blowfishopt.lo dhaes.lo dldp.lo dlkp.lo dlpk.lo dlsvdp-dh.lo dsa.lo elgamal.lo endianness.lo entropy.lo fips186.lo hmac.lo hmacmd5.lo hmacsha1.lo hmacsha256.lo md5.lo memchunk.lo mp.lo mpbarrett.lo mpnumber.lo mpopt.lo mpprime.lo mtprng.lo rsa.lo rsakp.lo rsapk.lo sha1.lo sha1opt.lo sha256.lo timestamp.lo +BEECRYPT_OBJECTS = aes.lo aesopt.lo base64.lo beecrypt.lo blockmode.lo blockpad.lo blowfish.lo blowfishopt.lo dhaes.lo dldp.lo dlkp.lo dlpk.lo dlsvdp-dh.lo dsa.lo elgamal.lo endianness.lo entropy.lo fips186.lo hmac.lo hmacmd5.lo hmacsha1.lo hmacsha256.lo md5.lo memchunk.lo mp.lo mpopt.lo mpbarrett.lo mpnumber.lo mpprime.lo mtprng.lo pkcs1.lo pkcs12.lo rsa.lo rsakp.lo rsapk.lo sha1.lo sha1opt.lo sha256.lo timestamp.lo -libaltdir = $(libdir)@LIBALT@ +libaltdir=$(prefix)/lib@LIBALT@ libalt_LTLIBRARIES = libbeecrypt.la -libbeecrypt_la_SOURCES = aes.c base64.c beecrypt.c blockmode.c blockpad.c blowfish.c dhaes.c dldp.c dlkp.c dlpk.c dlsvdp-dh.c dsa.c elgamal.c endianness.c entropy.c fips186.c hmac.c hmacmd5.c hmacsha1.c hmacsha256.c md5.c memchunk.c mp.c mpbarrett.c mpnumber.c mpprime.c mtprng.c rsa.c rsakp.c rsapk.c sha1.c sha256.c timestamp.c - +libbeecrypt_la_SOURCES = aes.c base64.c beecrypt.c blockmode.c blockpad.c blowfish.c dhaes.c dldp.c dlkp.c dlpk.c dlsvdp-dh.c dsa.c elgamal.c endianness.c entropy.c fips186.c hmac.c hmacmd5.c hmacsha1.c hmacsha256.c md5.c memchunk.c mp.c mpbarrett.c mpnumber.c mpprime.c mtprng.c pkcs1.c pkcs12.c rsa.c rsakp.c rsapk.c sha1.c sha256.c timestamp.c cppglue.cxx libbeecrypt_la_DEPENDENCIES = $(BEECRYPT_OBJECTS) - libbeecrypt_la_LIBADD = aesopt.lo blowfishopt.lo mpopt.lo sha1opt.lo - libbeecrypt_la_LDFLAGS = -no-undefined -version-info $(LIBBEECRYPT_LT_CURRENT):$(LIBBEECRYPT_LT_REVISION):$(LIBBEECRYPT_LT_AGE) -pkginclude_HEADERS = aes.h base64.h beecrypt.h beecrypt.api.h beecrypt.gnu.h blockmode.h blockpad.h blowfish.h dhaes.h dldp.h dlkp.h dlpk.h dlsvdp-dh.h dsa.h elgamal.h endianness.h entropy.h fips186.h hmac.h hmacmd5.h hmacsha1.h hmacsha256.h md5.h memchunk.h mp.h mpbarrett.h mpnumber.h mpprime.h mtprng.h rsa.h rsakp.h rsapk.h sha1.h sha256.h timestamp.h +pkginclude_HEADERS = aes.h aesopt.h api.h base64.h beecrypt.h blockmode.h blockpad.h blowfish.h blowfishopt.h dhaes.h dldp.h dlkp.h dlpk.h dlsvdp-dh.h dsa.h elgamal.h endianness.h entropy.h fips186.h gnu.h hmac.h hmacmd5.h hmacsha1.h hmacsha256.h md5.h memchunk.h mp.h mpbarrett.h mpnumber.h mpopt.h mpprime.h mtprng.h pkcs1.h pkcs12.h rsa.h rsakp.h rsapk.h sha1.h sha1opt.h sha256.h timestamp.h win.h -noinst_HEADERS = aes_be.h aes_le.h aesopt.h beecrypt.win.h \ - blowfishopt.h debug.h mpopt.h sha1opt.h system.h +noinst_HEADERS = aes_be.h aes_le.h -EXTRA_DIST = BENCHMARKS BUGS CONTRIBUTORS Doxyfile.in Doxyheader README README.DLL README.WIN32 beecrypt.gnu.h.in beecrypt.rc beecrypt.spec autogen.sh Makefile.mak +EXTRA_DIST = BENCHMARKS BUGS CONTRIBUTORS README.DLL README.WIN32 Doxyheader beecrypt.rc autogen.sh Makefile.mak DISTCLEANFILES = mpopt.s aesopt.s blowfishopt.s sha1opt.s bench: (cd tests && $(MAKE) $(AM_MAKEFLAGS) bench) - -.PHONY: beetest -beetest: all - ${MAKE} -C tests beetest - ./tests/beetest - -beecrypt.lcd: Makefile.am ${libbeecrypt_la_SOURCES} ${pkginclude_HEADERS} ${noinst_HEADERS} - lclint $(DEFS) $(INCLUDES) ${libbeecrypt_la_SOURCES} -dump $@ - -# XXX don't bite into gcj java dependencies (yet) -.PHONY: sources -sources: - @echo $(libbeecrypt_la_SOURCES:%=beecrypt/%) | sed -e 's,beecrypt/javaglue.c,,' - -# XXX don't bite into javaglue.c (yet) -.PHONY: lint -lint: - $(LINT) $(DEFS) $(INCLUDES) $(libbeecrypt_la_SOURCES:javaglue.c=) tests/beetest.c - -.PHONY: listobjs -listobjs: - @echo $(BEECRYPT_OBJECTS) > $@ - -DOXYGEN = /usr/bin/doxygen -.PHONY: doxygen -doxygen apidocs: Doxyfile Doxyheader - rm -rf $@ - mkdir -p $@ - - [ -x ${DOXYGEN} ] && ${DOXYGEN} diff --git a/beecrypt/NEWS b/beecrypt/NEWS index 5c20960..9b34b55 100644 --- a/beecrypt/NEWS +++ b/beecrypt/NEWS @@ -1,4 +1,23 @@ -3.0.0pre: +4.0.0: + - Added a C++ API interface, modeled after Java's security & crypto API. + - Added the new GNU noexecstack feature. + - Added more x86_64 and s390x assembler routines. + - Modified i2osp, so that it only requires as many octets as there are + significant bytes in the multi-precision integers. + - Fixed a bug in the creation of rsa keypairs; code was not correctly + migrated to new calling sequence. The code now implements the method + described in IEEE P.1363. + - Fixed another bug in mpextgcd_w which sometimes returned incorrect + results. + - Fixed a bug in mprshiftlsz, which didn't work correctly when size = 1. + - Fixed a configuration problem on Tru64 Unix. + +3.1.0: + - Added wiping of private key components of keypairs before freeing. + - Fixed bug in mpextgcd_w which sometimes returned incorrect result. + - Fixed error in PowerPC 64-bit assembler symbol definitions. + +3.0.0: - Cleaned up installed header files. - Modified the API so that all keys can be passed as arrays of bytes. - Modified the API so that all key sizes are given in bits. @@ -11,7 +30,10 @@ - Added multi-precision integer assembler routines for PowerPC 64-bit. - Added multi-precision integer assembler routines for Alpha. - Added multi-precision integer assembler routines for Opteron. + - Added multi-precision integer assembler routines for IBM zSeries 64-bit. - Added multi-precision integer assembler routines for M68K. + - Added Jeff Johnson's python bindings. + - Added new unit tests. - Added new benchmarking programs. 2.3.0pre: diff --git a/beecrypt/README b/beecrypt/README index affc428..d875372 100644 --- a/beecrypt/README +++ b/beecrypt/README @@ -109,6 +109,7 @@ Planned for the near future are: The library has been tested on the following platforms: - AIX 5.1 ppc - AIX 5.1 ppc64 + - Darwin 6.5 (a.k.a. MacOS X 10.2) - FreeBSD 4.0 alpha - FreeBSD 4.0, 4.2 x86 - Linux glibc 2.x alpha @@ -123,8 +124,6 @@ The library has been tested on the following platforms: - Win32 (Windows 95, 98, NT 4.0, 2000, XP) The library is currently in the process of being ported to: - - Darwin (apparently Apple has decided to change the PPC assembler format; - this will need a fix) - Cygwin (Can't seem to get the DLL to build properly with the current version of the autotools) - HP/UX is a pain in the backside; I'll try getting it working, but the @@ -135,7 +134,7 @@ For more information, refer to the HTML documentation in the docs directory. If you want to report bugs, make suggestions, contribute fixes or enhancements, please see the beecrypt-specific website: -http://beecrypt.virtualunlimited.com/ +http://sourceforge.net/projects/beecrypt or contact me at mailto:bob.deblier@pandora.be diff --git a/beecrypt/acinclude.m4 b/beecrypt/acinclude.m4 index deda40d..d6493d2 100644 --- a/beecrypt/acinclude.m4 +++ b/beecrypt/acinclude.m4 @@ -8,8 +8,143 @@ dnl dnl LGPL +dnl BEECRYPT_WITH_CPU +AC_DEFUN([BEECRYPT_WITH_CPU],[ + ac_with_cpu=yes + bc_target_cpu=$withval + case $target_cpu in + i[[3456]]86) + case $withval in + i[[3456]]86 | \ + pentium | pentium-mmx | pentiumpro | pentium[[234]] | \ + athlon | athlon-tbird | athlon-4 | athlon-xp | athlon-mp) + ;; + *) + AC_MSG_WARN([invalid cpu type]) + bc_target_cpu=$target_cpu + ;; + esac + ;; + powerpc | powerpc64) + case $withval in + 403 | 505 | \ + 60[[1234]] | 60[[34]]e | 6[[23]]0 | \ + 7[[45]]0 | 74[[05]]0 | \ + 801 | 82[[13]] | 860 | \ + power | power2 | powerpc | powerpc64) + ;; + *) + AC_MSG_WARN([invalid cpu type]) + bc_target_cpu=$target_cpu + ;; + esac + ;; + sparc | sparc64) + case $withval in + sparcv8 | sparcv8plus | sparcv8plus[[ab]] | sparcv9 | sparcv9[[ab]]) + ;; + *) + AC_MSG_WARN([invalid cpu type]) + bc_target_cpu=$target_cpu + ;; + esac + ;; + x86) # QNX Neutrino doesn't list the exact cpu type + case $withval in + i[[3456]]86) + ;; + *) + AC_MSG_WARN([unsupported or invalid cpu type]) + bc_target_cpu=$target_cpu + ;; + esac + ;; + *) + AC_MSG_WARN([unsupported or invalid cpu type]) + bc_target_cpu=$target_cpu + ;; + esac + ]) + +dnl BEECRYPT_WITHOUT_CPU +AC_DEFUN([BEECRYPT_WITHOUT_CPU],[ + ac_with_cpu=no + bc_target_cpu=$target_cpu + ]) + + +dnl BEECRYPT_WITH_ARCH +AC_DEFUN([BEECRYPT_WITH_ARCH],[ + ac_with_arch=yes + bc_target_arch=$withval + case $target_cpu in + i[[3456]]86) + case $withval in + i[[3456]]86 | \ + pentium | pentium-mmx | pentiumpro | pentium[[234]] | \ + athlon | athlon-tbird | athlon-4 | athlon-xp | athlon-mp) + if test "$ac_with_cpu" != yes; then + bc_target_cpu=$withval + fi + ;; + esac + ;; + powerpc*) + case $withval in + powerpc) + ;; + powerpc64) + bc_target_arch=powerpc64 + ;; + *) + AC_MSG_WARN([unsupported on invalid arch type]) + bc_target_arch=powerpc + ;; + esac + ;; + esac + ]) + +dnl BEECRYPT_WITHOUT_ARCH +AC_DEFUN([BEECRYPT_WITHOUT_ARCH],[ + ac_with_arch=no + case $target_cpu in + alpha*) + bc_target_arch=alpha + ;; + arm*) + bc_target_arch=arm + ;; + i[[3456]]86) + bc_target_arch=i386 + ;; + ia64) + bc_target_arch=ia64 + ;; + m68k) + bc_target_arch=m68k + ;; + powerpc) + bc_target_arch=powerpc + ;; + powerpc64) + bc_target_arch=powerpc64 + ;; + s390x) + bc_target_arch=s390x + ;; + sparc*) + bc_target_arch=sparc + ;; + x86_64) + bc_target_arch=x86_64 + ;; + esac + ]) + + dnl BEECRYPT_INT_TYPES -AC_DEFUN(BEECRYPT_INT_TYPES,[ +AC_DEFUN([BEECRYPT_INT_TYPES],[ AC_TYPE_SIZE_T bc_typedef_size_t= if test $ac_cv_type_size_t != yes; then @@ -112,7 +247,7 @@ AC_DEFUN(BEECRYPT_INT_TYPES,[ dnl BEECRYPT_CPU_BITS -AC_DEFUN(BEECRYPT_CPU_BITS,[ +AC_DEFUN([BEECRYPT_CPU_BITS],[ AC_CHECK_SIZEOF([unsigned long]) if test $ac_cv_sizeof_unsigned_long -eq 8; then AC_SUBST(MP_WBITS,64U) @@ -125,7 +260,7 @@ AC_DEFUN(BEECRYPT_CPU_BITS,[ dnl BEECRYPT_WORKING_AIO -AC_DEFUN(BEECRYPT_WORKING_AIO,[ +AC_DEFUN([BEECRYPT_WORKING_AIO],[ AC_CHECK_HEADERS(aio.h) if test "$ac_cv_header_aio_h" = yes; then AC_SEARCH_LIBS([aio_read],[c rt aio posix4],[ @@ -214,7 +349,7 @@ main() case $target_os in linux* | solaris*) bc_cv_working_aio=yes ;; - *) + *) bc_cv_working_aio=no ;; esac ]) @@ -228,7 +363,7 @@ main() dnl BEECRYPT_CFLAGS_REM -AC_DEFUN(BEECRYPT_CFLAGS_REM,[ +AC_DEFUN([BEECRYPT_CFLAGS_REM],[ if test "$CFLAGS" != ""; then CFLAGS_save="" for flag in $CFLAGS @@ -242,8 +377,23 @@ AC_DEFUN(BEECRYPT_CFLAGS_REM,[ ]) +dnl BEECRYPT_CXXFLAGS_REM +AC_DEFUN([BEECRYPT_CXXFLAGS_REM],[ + if test "$CXXFLAGS" != ""; then + CXXFLAGS_save="" + for flag in $CXXFLAGS + do + if test "$flag" != "$1"; then + CXXFLAGS_save="$CXXFLAGS_save $flag" + fi + done + CXXFLAGS="$CXXFLAGS_save" + fi + ]) + + dnl BEECRYPT_GNU_CC -AC_DEFUN(BEECRYPT_GNU_CC,[ +AC_DEFUN([BEECRYPT_GNU_CC],[ AC_REQUIRE([AC_PROG_CC]) case $bc_target_arch in ia64) @@ -263,7 +413,6 @@ AC_DEFUN(BEECRYPT_GNU_CC,[ case $target_os in aix*) CC="$CC -maix64" - LDFLAGS="$LDFLAGS -b64" ;; esac ;; @@ -276,6 +425,10 @@ AC_DEFUN(BEECRYPT_GNU_CC,[ CPPFLAGS="$CPPFLAGS -pthread" LDFLAGS="$LDFLAGS -pthread" ;; + osf*) + CFLAGS="$CFLAGS -pthread" + CPPFLAGS="$CPPFLAGS -pthread" + ;; esac fi if test "$ac_enable_debug" = yes; then @@ -286,56 +439,147 @@ AC_DEFUN(BEECRYPT_GNU_CC,[ BEECRYPT_CFLAGS_REM([-g]) BEECRYPT_CFLAGS_REM([-O2]) CFLAGS="$CFLAGS -O3 -fomit-frame-pointer" - case $bc_target_cpu in - athlon*) - CFLAGS="$CFLAGS -mcpu=pentiumpro"; - ;; - i586) - CFLAGS="$CFLAGS -mcpu=pentium" - ;; - i686) - CFLAGS="$CFLAGS -mcpu=pentiumpro" - ;; - ia64) - # no -mcpu=... option on ia64 - ;; - pentium*) - CFLAGS="$CFLAGS -mcpu=$bc_target_arch" + if test "$bc_cv_c_aggressive_opt" = yes; then + case $bc_target_cpu in + athlon*) + CFLAGS="$CFLAGS -mcpu=pentiumpro"; + ;; + i586) + CFLAGS="$CFLAGS -mcpu=pentium" + ;; + i686) + CFLAGS="$CFLAGS -mcpu=pentiumpro" + ;; + ia64) + # no -mcpu=... option on ia64 + ;; + pentium*) + CFLAGS="$CFLAGS -mcpu=$bc_target_arch" + ;; + esac + # Architecture-specific optimizations + case $bc_target_arch in + athlon*) + CFLAGS="$CFLAGS -march=$bc_target_arch" + ;; + i586) + CFLAGS="$CFLAGS -march=pentium" + ;; + i686) + CFLAGS="$CFLAGS -march=pentiumpro" + ;; + pentium*) + CFLAGS="$CFLAGS -march=$bc_target_arch" + ;; + powerpc | powerpc64) + CFLAGS="$CFLAGS -mcpu=$bc_target_arch" + ;; + sparcv8) + CFLAGS="$CFLAGS -mv8" + ;; + sparcv8plus) + CFLAGS="$CFLAGS -mv8plus" + ;; + esac + fi + fi + ]) + + +dnl BEECRYPT_GNU_CXX +AC_DEFUN([BEECRYPT_GNU_CXX],[ + AC_REQUIRE([AC_PROG_CXX]) + case $bc_target_arch in + ia64) + case $target_os in + # HP/UX on Itanium needs to be told that a long is 64-bit! + hpux*) + CXXFLAGS="$CXXFLAGS -mlp64" ;; esac - # Architecture-specific optimizations - case $bc_target_arch in - athlon*) - CFLAGS="$CFLAGS -march=$bc_target_arch" - ;; - i586) - CFLAGS="$CFLAGS -march=pentium" - ;; - i686) - CFLAGS="$CFLAGS -march=pentiumpro" - ;; - pentium*) - CFLAGS="$CFLAGS -march=$bc_target_arch" - ;; - powerpc) - CFLAGS="$CFLAGS -mcpu=powerpc" - ;; - powerpc64) - CFLAGS="$CFLAGS -mcpu=powerpc64" + ;; + # PowerPC needs a signed char + powerpc) + CXXFLAGS="$CXXFLAGS -fsigned-char" + ;; + powerpc64) + CXXFLAGS="$CXXFLAGS -fsigned-char" + case $target_os in + aix*) + CXX="$CXX -maix64" ;; - sparcv8) - CFLAGS="$CFLAGS -mv8" + esac + ;; + esac + # Certain platforms needs special flags for multi-threaded code + if test "$ac_enable_threads" = yes; then + case $target_os in + freebsd*) + CXXFLAGS="$CXXFLAGS -pthread" + CXXCPPFLAGS="$CXXCPPFLAGS -pthread" + LDFLAGS="$LDFLAGS -pthread" ;; - sparcv8plus) - CFLAGS="$CFLAGS -mv8plus" + osf*) + CXXFLAGS="$CXXFLAGS -pthread" + CXXCPPFLAGS="$CXXCPPFLAGS -pthread" ;; esac fi + if test "$ac_enable_debug" = yes; then + BEECRYPT_CXXFLAGS_REM([-O2]) + CXXFLAGS="$CXXFLAGS -Wall -pedantic" + else + # Generic optimizations, including cpu tuning + BEECRYPT_CXXFLAGS_REM([-g]) + if test "$bc_cv_c_aggressive_opt" = yes; then + case $bc_target_cpu in + athlon*) + CXXFLAGS="$CXXFLAGS -mcpu=pentiumpro"; + ;; + i586) + CXXFLAGS="$CXXFLAGS -mcpu=pentium" + ;; + i686) + CXXFLAGS="$CXXFLAGS -mcpu=pentiumpro" + ;; + ia64) + # no -mcpu=... option on ia64 + ;; + pentium*) + CXXFLAGS="$CXXFLAGS -mcpu=$bc_target_arch" + ;; + esac + # Architecture-specific optimizations + case $bc_target_arch in + athlon*) + CXXFLAGS="$CXXFLAGS -march=$bc_target_arch" + ;; + i586) + CXXFLAGS="$CXXFLAGS -march=pentium" + ;; + i686) + CXXFLAGS="$CXXFLAGS -march=pentiumpro" + ;; + pentium*) + CXXFLAGS="$CXXFLAGS -march=$bc_target_arch" + ;; + powerpc | powerpc64) + CXXFLAGS="$CXXFLAGS -mcpu=$bc_target_arch" + ;; + sparcv8) + CXXFLAGS="$CXXFLAGS -mv8" + ;; + sparcv8plus) + CXXFLAGS="$CXXFLAGS -mv8plus" + ;; + esac + fi + fi ]) dnl BEECRYPT_COMPAQ_CC -AC_DEFUN(BEECRYPT_COMPAQ_CC,[ +AC_DEFUN([BEECRYPT_COMPAQ_CC],[ AC_REQUIRE([AC_PROG_CC]) AC_REQUIRE([AC_PROG_CPP]) AC_CACHE_CHECK([whether we are using Compaq's C compiler],bc_cv_prog_COMPAQ_CC,[ @@ -352,23 +596,37 @@ AC_DEFUN(BEECRYPT_COMPAQ_CC,[ fi if test "$ac_enable_debug" != yes; then BEECRYPT_CFLAGS_REM([-g]) - CFLAGS="$CFLAGS -fast" + if test "$bc_cv_c_aggressive_opt" = yes; then + CFLAGS="$CFLAGS -fast" + fi fi fi ]) +dnl BEECRYPT_COMPAQ_CXX +AC_DEFUN([BEECRYPT_COMPAQ_CXX],[ + ]) + + dnl BEECRYPT_HPUX_CC -AC_DEFUN(BEECRYPT_HPUX_CC,[ +AC_DEFUN([BEECRYPT_HPUX_CC],[ if test "$ac_enable_debug" != yes; then BEECRYPT_CFLAGS_REM([-g]) - CFLAGS="$CFLAGS -fast" + if test "$bc_cv_c_aggressive_opt" = yes; then + CFLAGS="$CFLAGS -fast" + fi fi ]) +dnl BEECRYPT_HP_CXX +AC_DEFUN([BEECRYPT_HP_CXX],[ + ]) + + dnl BEECRYPT_IBM_CC -AC_DEFUN(BEECRYPT_IBM_CC,[ +AC_DEFUN([BEECRYPT_IBM_CC],[ AC_REQUIRE([AC_PROG_CC]) AC_REQUIRE([AC_PROG_CPP]) AC_CACHE_CHECK([whether we are using IBM C],bc_cv_prog_IBM_CC,[ @@ -389,10 +647,12 @@ AC_DEFUN(BEECRYPT_IBM_CC,[ esac if test "$ac_enable_debug" != yes; then BEECRYPT_CFLAGS_REM([-g]) - if test "$ac_with_arch" = yes; then - CFLAGS="$CFLAGS -O5" - else - CFLAGS="$CFLAGS -O3" + if test "$bc_cv_c_aggressive_opt" = yes; then + if test "$ac_with_arch" = yes; then + CFLAGS="$CFLAGS -O5" + else + CFLAGS="$CFLAGS -O3" + fi fi fi # Version 5.0 doesn't have this, but 6.0 does @@ -401,8 +661,13 @@ AC_DEFUN(BEECRYPT_IBM_CC,[ ]) +dnl BEECRYPT_IBM_CXX +AC_DEFUN([BEECRYPT_IBM_CXX],[ + ]) + + dnl BEECRYPT_INTEL_CC -AC_DEFUN(BEECRYPT_INTEL_CC,[ +AC_DEFUN([BEECRYPT_INTEL_CC],[ AC_REQUIRE([AC_PROG_CC]) AC_REQUIRE([AC_PROG_CPP]) AC_CACHE_CHECK([whether we are using Intel C++],bc_cv_prog_INTEL_CC,[ @@ -415,35 +680,36 @@ AC_DEFUN(BEECRYPT_INTEL_CC,[ if test "$bc_cv_prog_INTEL_CC" = yes; then if test "$ac_enable_debug" != yes; then BEECRYPT_CFLAGS_REM([-g]) - CFLAGS="$CFLAGS -O3" - case $bc_target_cpu in - i586 | pentium | pentium-mmx) - CFLAGS="$CFLAGS -mcpu=pentium" - ;; - i686 | pentiumpro | pentium[[23]]) - CFLAGS="$CFLAGS -mcpu=pentiumpro" - ;; - pentium4) - CFLAGS="$CFLAGS -mcpu=pentium4" - ;; - esac - case $bc_target_arch in - i586 | pentium | pentium-mmx) - CFLAGS="$CFLAGS -tpp5" - ;; - i686 | pentiumpro) - CFLAGS="$CFLAGS -tpp6 -march=pentiumpro" - ;; - pentium2) - CFLAGS="$CFLAGS -tpp6 -march=pentiumii" - ;; - pentium3) - CFLAGS="$CFLAGS -tpp6 -march=pentiumiii" - ;; - pentium4) - CFLAGS="$CFLAGS -tpp7 -march=pentium4" - ;; - esac + if test "$bc_cv_c_aggressive_opt" = yes; then + case $bc_target_cpu in + i586 | pentium | pentium-mmx) + CFLAGS="$CFLAGS -mcpu=pentium" + ;; + i686 | pentiumpro | pentium[[23]]) + CFLAGS="$CFLAGS -mcpu=pentiumpro" + ;; + pentium4) + CFLAGS="$CFLAGS -mcpu=pentium4" + ;; + esac + case $bc_target_arch in + i586 | pentium | pentium-mmx) + CFLAGS="$CFLAGS -tpp5" + ;; + i686 | pentiumpro) + CFLAGS="$CFLAGS -tpp6 -march=pentiumpro" + ;; + pentium2) + CFLAGS="$CFLAGS -tpp6 -march=pentiumii" + ;; + pentium3) + CFLAGS="$CFLAGS -tpp6 -march=pentiumiii" + ;; + pentium4) + CFLAGS="$CFLAGS -tpp7 -march=pentium4" + ;; + esac + fi fi AC_CHECK_FUNC([_rotl]) AC_CHECK_FUNC([_rotr]) @@ -451,8 +717,13 @@ AC_DEFUN(BEECRYPT_INTEL_CC,[ ]) +dnl BEECRYPT_INTEL_CXX +AC_DEFUN([BEECRYPT_INTEL_CXX],[ + ]) + + dnl BEECRYPT_SUN_FORTE_CC -AC_DEFUN(BEECRYPT_SUN_FORTE_CC,[ +AC_DEFUN([BEECRYPT_SUN_FORTE_CC],[ AC_REQUIRE([AC_PROG_CC]) AC_REQUIRE([AC_PROG_CPP]) AC_CACHE_CHECK([whether we are using Sun Forte C],bc_cv_prog_SUN_FORTE_CC,[ @@ -468,28 +739,236 @@ AC_DEFUN(BEECRYPT_SUN_FORTE_CC,[ fi if test "$ac_enable_debug" != yes; then BEECRYPT_CFLAGS_REM([-g]) - CFLAGS="$CFLAGS -fast" - case $bc_target_arch in - sparc) - CFLAGS="$CFLAGS -xtarget=generic -xarch=generic" - ;; - sparcv8) - CFLAGS="$CFLAGS -xtarget=generic -xarch=v8" - ;; - sparcv8plus*) - CFLAGS="$CFLAGS -xtarget=generic -xarch=v8plus" - ;; - sparcv9*) - CFLAGS="$CFLAGS -xtarget=generic64 -xarch=v9" - ;; - esac + if test "$bc_cv_c_aggressive_opt" = yes; then + CFLAGS="$CFLAGS -fast" + case $bc_target_arch in + sparc) + CFLAGS="$CFLAGS -xtarget=generic -xarch=generic" + ;; + sparcv8) + CFLAGS="$CFLAGS -xtarget=generic -xarch=v8" + ;; + sparcv8plus*) + CFLAGS="$CFLAGS -xtarget=generic -xarch=v8plus" + ;; + sparcv9*) + CFLAGS="$CFLAGS -xtarget=generic64 -xarch=v9" + ;; + esac + fi + fi + fi + ]) + + +dnl BEECRYPT_SUN_FORTE_CXX +AC_DEFUN([BEECRYPT_SUN_FORTE_CXX],[ + ]) + + +dnl BEECRYPT_CC +AC_DEFUN([BEECRYPT_CC],[ + if test "$CFLAGS" = ""; then + bc_cv_c_aggressive_opt=yes + else + bc_cv_c_aggressive_opt=no + fi + # set flags for large file support + case $target_os in + linux* | solaris*) + CPPFLAGS="$CPPFLAGS `getconf LFS_CFLAGS`" + LDFLAGS="$LDFLAGS `getconf LFS_LDFLAGS`" + ;; + esac + if test "$ac_cv_c_compiler_gnu" = yes; then + # Intel's icc can be mistakenly identified as gcc + case $target_os in + linux*) + BEECRYPT_INTEL_CC + ;; + esac + if test "$bc_cv_prog_INTEL_CC" != yes; then + BEECRYPT_GNU_CC fi + else + case $target_os in + aix*) + BEECRYPT_IBM_CC + ;; + hpux*) + BEECRYPT_HPUX_CC + ;; + linux*) + BEECRYPT_INTEL_CC + ;; + solaris*) + BEECRYPT_SUN_FORTE_CC + ;; + osf*) + BEECRYPT_COMPAQ_CC + ;; + esac fi ]) +dnl BEECRYPT_CXX +AC_DEFUN([BEECRYPT_CXX],[ + if test "$CXXFLAGS" = ""; then + bc_cv_cxx_aggressive_opt=yes + else + bc_cv_cxx_aggressive_opt=no + fi + if test "$ac_cv_cxx_compiler_gnu" = yes; then + # Intel's icc can be mistakenly identified as gcc + case $target_os in + linux*) + BEECRYPT_INTEL_CXX + ;; + esac + if test "$bc_cv_prog_INTEL_CXX" != yes; then + BEECRYPT_GNU_CXX + fi + else + case $target_os in + aix*) + BEECRYPT_IBM_CXX + ;; + hpux*) + BEECRYPT_HPUX_CXX + ;; + linux*) + BEECRYPT_INTEL_CXX + ;; + solaris*) + BEECRYPT_SUN_FORTE_CXX + ;; + osf*) + BEECRYPT_COMPAQ_CXX + ;; + esac + fi + ]) + + +dnl BEECRYPT_NOEXECSTACK +AC_DEFUN([BEECRYPT_NOEXECSTACK],[ + AC_CACHE_CHECK([whether the assembler can use noexecstack],bc_cv_as_noexecstack,[ + cat > conftest.c << EOF +void foo(void) { } +EOF + if AC_TRY_COMMAND([$CC -c -o conftest.o conftest.c]) then + bc_cv_as_noexecstack=yes + if test "$ac_cv_c_compiler_gnu" = yes; then + CFLAGS="$CFLAGS -Wa,--noexecstack" + fi + if test "$ac_cv_cxx_compiler_gnu" = yes; then + CXXFLAGS="$CXXFLAGS -Wa,--noexecstack" + fi + else + bc_cv_as_noexecstack=no + fi + ]) + AC_CACHE_CHECK([whether the linker can use noexecstack],bc_cv_ld_noexecstack,[ + if AC_TRY_COMMAND([$LD -z noexecstack -o conftest conftest.o]) then + bc_cv_ld_noexecstack=yes + LDFLAGS="$LDFLAGS -z noexecstack" + else + bc_cv_ld_noexecstack=no + fi + ]) + ]) + + +dnl BEECRYPT_LIBTOOL +AC_DEFUN([BEECRYPT_LIBTOOL],[ + case $target_os in + aix*) + case $bc_target_arch in + powerpc64) + AR="ar -X64" + NM="/usr/bin/nm -B -X64" + ;; + esac + ;; + solaris*) + case $bc_target_arch in + sparcv9*) + LD="/usr/ccs/bin/ld -64" + ;; + esac + ;; + esac + ]) + + +dnl BEECRYPT_OS_DEFS +AC_DEFUN([BEECRYPT_OS_DEFS],[ + AH_TEMPLATE([AIX],[Define to 1 if you are using AIX]) + AH_TEMPLATE([CYGWIN],[Define to 1 if you are using Cygwin]) + AH_TEMPLATE([DARWIN],[Define to 1 if you are using Darwin/MacOS X]) + AH_TEMPLATE([FREEBSD],[Define to 1 if you are using FreeBSD]) + AH_TEMPLATE([HPUX],[Define to 1 if you are using HPUX]) + AH_TEMPLATE([LINUX],[Define to 1 if you are using GNU/Linux]) + AH_TEMPLATE([NETBSD],[Define to 1 if you are using NetBSD]) + AH_TEMPLATE([OPENBSD],[Define to 1 if you are using OpenBSD]) + AH_TEMPLATE([OSF],[Define to 1 if you are using OSF]) + AH_TEMPLATE([QNX],[Define to 1 if you are using QNX]) + AH_TEMPLATE([SCO_UNIX],[Define to 1 if you are using SCO Unix]) + AH_TEMPLATE([SOLARIS],[Define to 1 if you are using Solaris]) + AH_VERBATIM([WIN32],[ +#ifndef WIN32 + #undef WIN32 +#endif + ]) + + case $target_os in + aix*) + AC_DEFINE([AIX]) + ;; + cygwin*) + AC_DEFINE([CYGWIN]) + AC_DEFINE([WIN32]) + ;; + darwin*) + AC_DEFINE([DARWIN]) + ;; + freebsd*) + AC_DEFINE([FREEBSD]) + ;; + hpux*) + AC_DEFINE([HPUX]) + ;; + linux*) + AC_DEFINE([LINUX]) + ;; + netbsd*) + AC_DEFINE([NETBSD]) + ;; + openbsd*) + AC_DEFINE([OPENBSD]) + ;; + osf*) + AC_DEFINE([OSF]) + ;; + *qnx) + AC_DEFINE([QNX]) + ;; + solaris*) + AC_DEFINE([SOLARIS]) + ;; + sysv*uv*) + AC_DEFINE([SCO_UNIX]) + ;; + *) + AC_MSG_WARN([Operating system type $target_os currently not supported and/or tested]) + ;; + esac + ]) + + dnl BEECRYPT_ASM_DEFS -AC_DEFUN(BEECRYPT_ASM_DEFS,[ +AC_DEFUN([BEECRYPT_ASM_DEFS],[ AC_SUBST(ASM_OS,$target_os) AC_SUBST(ASM_CPU,$bc_target_cpu) AC_SUBST(ASM_ARCH,$bc_target_arch) @@ -498,7 +977,7 @@ AC_DEFUN(BEECRYPT_ASM_DEFS,[ dnl BEECRYPT_ASM_TEXTSEG -AC_DEFUN(BEECRYPT_ASM_TEXTSEG,[ +AC_DEFUN([BEECRYPT_ASM_TEXTSEG],[ AC_CACHE_CHECK([how to switch to text segment], bc_cv_asm_textseg,[ case $target_os in @@ -520,7 +999,7 @@ AC_DEFUN(BEECRYPT_ASM_TEXTSEG,[ dnl BEECRYPT_ASM_GLOBL -AC_DEFUN(BEECRYPT_ASM_GLOBL,[ +AC_DEFUN([BEECRYPT_ASM_GLOBL],[ AC_CACHE_CHECK([how to declare a global symbol], bc_cv_asm_globl,[ case $target_os in @@ -533,7 +1012,7 @@ AC_DEFUN(BEECRYPT_ASM_GLOBL,[ dnl BEECRYPT_ASM_GSYM_PREFIX -AC_DEFUN(BEECRYPT_ASM_GSYM_PREFIX,[ +AC_DEFUN([BEECRYPT_ASM_GSYM_PREFIX],[ AC_CACHE_CHECK([if global symbols need leading underscore], bc_cv_asm_gsym_prefix,[ case $target_os in @@ -546,7 +1025,7 @@ AC_DEFUN(BEECRYPT_ASM_GSYM_PREFIX,[ dnl BEECRYPT_ASM_LSYM_PREFIX -AC_DEFUN(BEECRYPT_ASM_LSYM_PREFIX,[ +AC_DEFUN([BEECRYPT_ASM_LSYM_PREFIX],[ AC_CACHE_CHECK([how to declare a local symbol], bc_cv_asm_lsym_prefix,[ case $target_os in @@ -566,10 +1045,12 @@ AC_DEFUN(BEECRYPT_ASM_LSYM_PREFIX,[ dnl BEECRYPT_ASM_ALIGN -AC_DEFUN(BEECRYPT_ASM_ALIGN,[ +AC_DEFUN([BEECRYPT_ASM_ALIGN],[ AC_CACHE_CHECK([how to align symbols], bc_cv_asm_align,[ case $target_cpu in + alpha*) + bc_cv_asm_align=".align 5" ;; i[[3456]]86 | athlon*) bc_cv_asm_align=".align 4" ;; ia64) @@ -580,6 +1061,8 @@ AC_DEFUN(BEECRYPT_ASM_ALIGN,[ bc_cv_asm_align=".align 4" ;; sparc*) bc_cv_asm_align=".align 4" ;; + x86_64) + bc_cv_asm_align=".align 16" ;; esac ]) AC_SUBST(ASM_ALIGN,$bc_cv_asm_align) @@ -587,7 +1070,7 @@ AC_DEFUN(BEECRYPT_ASM_ALIGN,[ dnl BEECRYPT_ASM_SOURCES -AC_DEFUN(BEECRYPT_ASM_SOURCES,[ +AC_DEFUN([BEECRYPT_ASM_SOURCES],[ echo > mpopt.s echo > aesopt.s echo > blowfishopt.s @@ -671,3 +1154,78 @@ AC_DEFUN(BEECRYPT_ASM_SOURCES,[ fi fi ]) + + +dnl BEECRYPT_DLFCN + +AC_DEFUN([BEECRYPT_DLFCN],[ + AH_TEMPLATE([HAVE_DLFCN_H],[.]) + AC_CHECK_HEADERS([dlfcn.h]) + if test "$ac_cv_header_dlfcn_h" = yes; then + AC_SEARCH_LIBS([dlopen],[dl dld],[ + ]) + fi + ]) + + +dnl BEECRYPT_MULTITHREAD +AC_DEFUN([BEECRYPT_MULTITHREAD],[ + AH_TEMPLATE([ENABLE_THREADS],[Define to 1 if you want to enable multithread support]) + AH_TEMPLATE([HAVE_THREAD_H],[.]) + AH_TEMPLATE([HAVE_PTHREAD_H],[.]) + AH_TEMPLATE([HAVE_SYNCH_H],[.]) + AH_TEMPLATE([HAVE_SEMAPHORE_H],[.]) + + if test "$ac_enable_threads" = yes; then + AC_CHECK_HEADERS([synch.h thread.h pthread.h semaphore.h]) + fi + + bc_include_synch_h= + bc_include_thread_h= + bc_include_pthread_h= + bc_typedef_bc_cond_t= + bc_typedef_bc_mutex_t= + bc_typedef_bc_thread_t= + if test "$ac_enable_threads" = yes; then + if test "$ac_cv_header_thread_h" = yes -a "$ac_cv_header_synch_h" = yes; then + bc_include_synch_h="#include " + bc_include_thread_h="#include " + bc_typedef_bc_cond_t="typedef cond_t bc_cond_t;" + bc_typedef_bc_mutex_t="typedef mutex_t bc_mutex_t;" + bc_typedef_bc_thread_t="typedef thread_t bc_thread_t;" + AC_SEARCH_LIBS([mutex_lock],[thread],[ + AC_DEFINE([ENABLE_THREADS],1) + ]) + elif test "$ac_cv_header_pthread_h" = yes; then + bc_include_pthread_h="#include " + bc_typedef_bc_cond_t="typedef pthread_cond_t bc_cond_t;" + bc_typedef_bc_mutex_t="typedef pthread_mutex_t bc_mutex_t;" + bc_typedef_bc_thread_t="typedef pthread_t bc_thread_t;" + # On most systems this tests will say 'none required', but that doesn't + # mean that the linked code will work correctly! + case $target_os in + linux* | solaris* ) + AC_DEFINE([ENABLE_THREADS],1) + LIBS="-lpthread $LIBS" + ;; + osf*) + AC_DEFINE([ENABLE_THREADS],1) + LIBS="-lpthread -lmach -lexc $LIBS" + ;; + *) + AC_SEARCH_LIBS([pthread_mutex_lock],[pthread],[ + AC_DEFINE([ENABLE_THREADS],1) + ]) + ;; + esac + else + AC_MSG_WARN([Don't know which thread library to check for]) + fi + fi + AC_SUBST(INCLUDE_SYNCH_H,$bc_include_synch_h) + AC_SUBST(INCLUDE_THREAD_H,$bc_include_thread_h) + AC_SUBST(INCLUDE_PTHREAD_H,$bc_include_pthread_h) + AC_SUBST(TYPEDEF_BC_COND_T,$bc_typedef_bc_cond_t) + AC_SUBST(TYPEDEF_BC_MUTEX_T,$bc_typedef_bc_mutex_t) + AC_SUBST(TYPEDEF_BC_THREAD_T,$bc_typedef_bc_thread_t) + ]) diff --git a/beecrypt/aes.c b/beecrypt/aes.c index bcc22b8..2d73776 100644 --- a/beecrypt/aes.c +++ b/beecrypt/aes.c @@ -1,4 +1,3 @@ -/*@-bitwisesigned@*/ /* * Copyright (c) 2002, 2003 Bob Deblier * @@ -28,12 +27,13 @@ * \ingroup BC_aes_m BC_m */ -#include "system.h" -#include "beecrypt.h" -#include "aesopt.h" -#include "aes.h" -#include "mp.h" -#include "debug.h" +#define BEECRYPT_DLL_EXPORT + +#if HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/aes.h" #if defined(BYTE_ORDER) && defined(BIG_ENDIAN) && defined(LITTLE_ENDIAN) # if (BYTE_ORDER != BIG_ENDIAN) && (BYTE_ORDER != LITTLE_ENDIAN) @@ -41,14 +41,10 @@ # endif #endif -/*!\addtogroup BC_aes_m - * \{ - */ - #if WORDS_BIGENDIAN -# include "aes_be.h" +# include "beecrypt/aes_be.h" #else -# include "aes_le.h" +# include "beecrypt/aes_le.h" #endif #ifdef ASM_AESENCRYPTECB @@ -59,15 +55,13 @@ extern int aesEncryptECB(aesParam*, uint32_t*, const uint32_t*, unsigned int); extern int aesDecryptECB(aesParam*, uint32_t*, const uint32_t*, unsigned int); #endif -/*@-sizeoftype@*/ -/*@-castfcnptr@*/ const blockCipher aes = { "AES", sizeof(aesParam), - 16U, - 128U, - 256U, - 64U, + 16, + 128, + 256, + 64, (blockCipherSetup) aesSetup, (blockCipherSetIV) aesSetIV, /* raw */ @@ -95,8 +89,6 @@ const blockCipher aes = { }, (blockCipherFeedback) aesFeedback }; -/*@=castfcnptr@*/ -/*@=sizeoftype@*/ int aesSetup(aesParam* ap, const byte* key, size_t keybits, cipherOperation op) { @@ -127,16 +119,16 @@ int aesSetup(aesParam* ap, const byte* key, size_t keybits, cipherOperation op) { t = rk[3]; #if WORDS_BIGENDIAN - t = (_ae4[(t >> 16) & 0xff] & 0xff000000U) ^ - (_ae4[(t >> 8) & 0xff] & 0x00ff0000U) ^ - (_ae4[(t ) & 0xff] & 0x0000ff00U) ^ - (_ae4[(t >> 24) ] & 0x000000ffU) ^ + t = (_ae4[(t >> 16) & 0xff] & 0xff000000) ^ + (_ae4[(t >> 8) & 0xff] & 0x00ff0000) ^ + (_ae4[(t ) & 0xff] & 0x0000ff00) ^ + (_ae4[(t >> 24) ] & 0x000000ff) ^ _arc[i]; #else - t = (_ae4[(t >> 8) & 0xff] & 0x000000ffU) ^ - (_ae4[(t >> 16) & 0xff] & 0x0000ff00U) ^ - (_ae4[(t >> 24) ] & 0x00ff0000U) ^ - (_ae4[(t ) & 0xff] & 0xff000000U) ^ + t = (_ae4[(t >> 8) & 0xff] & 0x000000ff) ^ + (_ae4[(t >> 16) & 0xff] & 0x0000ff00) ^ + (_ae4[(t >> 24) ] & 0x00ff0000) ^ + (_ae4[(t ) & 0xff] & 0xff000000) ^ _arc[i]; #endif rk[4] = (t ^= rk[0]); @@ -154,16 +146,16 @@ int aesSetup(aesParam* ap, const byte* key, size_t keybits, cipherOperation op) { t = rk[5]; #if WORDS_BIGENDIAN - t = (_ae4[(t >> 16) & 0xff] & 0xff000000U) ^ - (_ae4[(t >> 8) & 0xff] & 0x00ff0000U) ^ - (_ae4[(t ) & 0xff] & 0x0000ff00U) ^ - (_ae4[(t >> 24) ] & 0x000000ffU) ^ + t = (_ae4[(t >> 16) & 0xff] & 0xff000000) ^ + (_ae4[(t >> 8) & 0xff] & 0x00ff0000) ^ + (_ae4[(t ) & 0xff] & 0x0000ff00) ^ + (_ae4[(t >> 24) ] & 0x000000ff) ^ _arc[i]; #else - t = (_ae4[(t >> 8) & 0xff] & 0x000000ffU) ^ - (_ae4[(t >> 16) & 0xff] & 0x0000ff00U) ^ - (_ae4[(t >> 24) ] & 0x00ff0000U) ^ - (_ae4[(t ) & 0xff] & 0xff000000U) ^ + t = (_ae4[(t >> 8) & 0xff] & 0x000000ff) ^ + (_ae4[(t >> 16) & 0xff] & 0x0000ff00) ^ + (_ae4[(t >> 24) ] & 0x00ff0000) ^ + (_ae4[(t ) & 0xff] & 0xff000000) ^ _arc[i]; #endif rk[6] = (t ^= rk[0]); @@ -183,16 +175,16 @@ int aesSetup(aesParam* ap, const byte* key, size_t keybits, cipherOperation op) { t = rk[7]; #if WORDS_BIGENDIAN - t = (_ae4[(t >> 16) & 0xff] & 0xff000000U) ^ - (_ae4[(t >> 8) & 0xff] & 0x00ff0000U) ^ - (_ae4[(t ) & 0xff] & 0x0000ff00U) ^ - (_ae4[(t >> 24) ] & 0x000000ffU) ^ + t = (_ae4[(t >> 16) & 0xff] & 0xff000000) ^ + (_ae4[(t >> 8) & 0xff] & 0x00ff0000) ^ + (_ae4[(t ) & 0xff] & 0x0000ff00) ^ + (_ae4[(t >> 24) ] & 0x000000ff) ^ _arc[i]; #else - t = (_ae4[(t >> 8) & 0xff] & 0x000000ffU) ^ - (_ae4[(t >> 16) & 0xff] & 0x0000ff00U) ^ - (_ae4[(t >> 24) ] & 0x00ff0000U) ^ - (_ae4[(t ) & 0xff] & 0xff000000U) ^ + t = (_ae4[(t >> 8) & 0xff] & 0x000000ff) ^ + (_ae4[(t >> 16) & 0xff] & 0x0000ff00) ^ + (_ae4[(t >> 24) ] & 0x00ff0000) ^ + (_ae4[(t ) & 0xff] & 0xff000000) ^ _arc[i]; #endif rk[8] = (t ^= rk[0]); @@ -202,15 +194,15 @@ int aesSetup(aesParam* ap, const byte* key, size_t keybits, cipherOperation op) if (++i == 7) break; #if WORDS_BIGENDIAN - t = (_ae4[(t >> 24) ] & 0xff000000U) ^ - (_ae4[(t >> 16) & 0xff] & 0x00ff0000U) ^ - (_ae4[(t >> 8) & 0xff] & 0x0000ff00U) ^ - (_ae4[(t ) & 0xff] & 0x000000ffU); + t = (_ae4[(t >> 24) ] & 0xff000000) ^ + (_ae4[(t >> 16) & 0xff] & 0x00ff0000) ^ + (_ae4[(t >> 8) & 0xff] & 0x0000ff00) ^ + (_ae4[(t ) & 0xff] & 0x000000ff); #else - t = (_ae4[(t ) & 0xff] & 0x000000ffU) ^ - (_ae4[(t >> 8) & 0xff] & 0x0000ff00U) ^ - (_ae4[(t >> 16) & 0xff] & 0x00ff0000U) ^ - (_ae4[(t >> 24) ] & 0xff000000U); + t = (_ae4[(t ) & 0xff] & 0x000000ff) ^ + (_ae4[(t >> 8) & 0xff] & 0x0000ff00) ^ + (_ae4[(t >> 16) & 0xff] & 0x00ff0000) ^ + (_ae4[(t >> 24) ] & 0xff000000); #endif rk[12] = (t ^= rk[4]); rk[13] = (t ^= rk[5]); @@ -235,9 +227,9 @@ int aesSetup(aesParam* ap, const byte* key, size_t keybits, cipherOperation op) { rk += 4; #if WORDS_BIGENDIAN - rk[0] = - _ad0[_ae4[(rk[0] >> 24) ] & 0xff] ^ - _ad1[_ae4[(rk[0] >> 16) & 0xff] & 0xff] ^ + rk[0] = + _ad0[_ae4[(rk[0] >> 24) ] & 0xff] ^ + _ad1[_ae4[(rk[0] >> 16) & 0xff] & 0xff] ^ _ad2[_ae4[(rk[0] >> 8) & 0xff] & 0xff] ^ _ad3[_ae4[(rk[0] ) & 0xff] & 0xff]; rk[1] = @@ -252,9 +244,9 @@ int aesSetup(aesParam* ap, const byte* key, size_t keybits, cipherOperation op) _ad3[_ae4[(rk[2] ) & 0xff] & 0xff]; rk[3] = _ad0[_ae4[(rk[3] >> 24) ] & 0xff] ^ - _ad1[_ae4[(rk[3] >> 16) & 0xff] & 0xff] ^ - _ad2[_ae4[(rk[3] >> 8) & 0xff] & 0xff] ^ - _ad3[_ae4[(rk[3] ) & 0xff] & 0xff]; + _ad1[_ae4[(rk[3] >> 16) & 0xff] & 0xff] ^ + _ad2[_ae4[(rk[3] >> 8) & 0xff] & 0xff] ^ + _ad3[_ae4[(rk[3] ) & 0xff] & 0xff]; #else rk[0] = _ad0[_ae4[(rk[0] ) & 0xff] & 0xff] ^ @@ -287,12 +279,10 @@ int aesSetup(aesParam* ap, const byte* key, size_t keybits, cipherOperation op) #ifndef ASM_AESSETIV int aesSetIV(aesParam* ap, const byte* iv) { -/*@-mayaliasunique@*/ if (iv) memcpy(ap->fdback, iv, 16); else memset(ap->fdback, 0, 16); -/*@=mayaliasunique@*/ return 0; } @@ -394,6 +384,3 @@ uint32_t* aesFeedback(aesParam* ap) { return ap->fdback; } -/*@=bitwisesigned@*/ -/*!\} - */ diff --git a/beecrypt/aes.h b/beecrypt/aes.h index 89b1c11..5051223 100644 --- a/beecrypt/aes.h +++ b/beecrypt/aes.h @@ -26,12 +26,25 @@ #ifndef _AES_H #define _AES_H -/** \ingroup BC_aes_m +#include "beecrypt/beecrypt.h" +#include "beecrypt/aesopt.h" + +/*!\brief Holds all the parameters necessary for the AES cipher. + * \ingroup BC_aes_m */ typedef struct { + /*!\var k + * \brief Holds the key expansion. + */ uint32_t k[64]; + /*!\var nr + * \brief Number of rounds to be used in encryption/decryption. + */ uint32_t nr; + /*!\var fdback + * \brief Buffer to be used by block chaining or feedback modes. + */ uint32_t fdback[4]; } aesParam; @@ -39,83 +52,58 @@ typedef struct extern "C" { #endif -/** \ingroup BC_aes_m +/*!\var aes + * \brief Holds the full API description of the AES algorithm. */ -/*@observer@*/ /*@unchecked@*/ extern const BEECRYPTAPI blockCipher aes; -/** \ingroup BC_aes_m - * The cipher's setup function. - * - * This function expands the key depending on whether the ENCRYPT or DECRYPT - * operation was selected. - * - * @param ap parameter block - * @param key key value - * @param keybits number of bits in the key (128, 192 or 256) - * @param op ENCRYPT or DECRYPT. - * @retval 0 on success, -1 on failure. +/*!\fn int aesSetup(aesParam* ap, const byte* key, size_t keybits, cipherOperation op) + * \brief This function performs the cipher's key expansion. + * \param ap The cipher's parameter block. + * \param key The key value. + * \param keybits The number of bits in the key; legal values are: + * 128, 192 and 256. + * \param op ENCRYPT or DECRYPT. + * \retval 0 on success. + * \retval -1 on failure. */ -/*@-exportlocal@*/ BEECRYPTAPI -int aesSetup (aesParam* ap, const byte* key, size_t keybits, cipherOperation op) - /*@modifies ap @*/; -/*@=exportlocal@*/ +int aesSetup (aesParam* ap, const byte* key, size_t keybits, cipherOperation op); -/** \ingroup BC_aes_m - * The Initialization Vector setup function. - * - * This function is only necessary in block chaining or feedback modes. - * - * @param ap parameter block - * @param iv initialization vector (or NULL) - * @retval 0 on success. +/*!\fn int aesSetIV(aesParam* ap, const byte* iv) + * \brief This function sets the Initialization Vector. + * \note This function is only useful in block chaining or feedback modes. + * \param ap The cipher's parameter block. + * \param iv The initialization vector; may be null. + * \retval 0 on success. */ -/*@-exportlocal@*/ BEECRYPTAPI -int aesSetIV (aesParam* ap, /*@null@*/ const byte* iv) - /*@modifies ap @*/; -/*@=exportlocal@*/ +int aesSetIV (aesParam* ap, const byte* iv); -/** \ingroup BC_aes_m - * The raw encryption function. - * - * This function encrypts one block of data; the size of a block is 128 bits. - * - * @param ap parameter block - * @param dst ciphertext (aligned on 32-bit boundary) - * @param src cleartext (aligned on 32-bit boundary) - * @retval 0 on success. +/*!\fn aesEncrypt(aesParam* ap, uint32_t* dst, const uint32_t* src) + * \brief This function performs the raw AES encryption; it encrypts one block + * of 128 bits. + * \param ap The cipher's parameter block. + * \param dst The ciphertext; should be aligned on 32-bit boundary. + * \param src The cleartext; should be aligned on 32-bit boundary. + * \retval 0 on success. */ -/*@-exportlocal@*/ BEECRYPTAPI -int aesEncrypt(aesParam* ap, uint32_t* dst, const uint32_t* src) - /*@modifies dst @*/; -/*@=exportlocal@*/ +int aesEncrypt (aesParam* ap, uint32_t* dst, const uint32_t* src); -/** \ingroup BC_aes_m - * The raw decryption function. - * - * This function decrypts one block of data; the size of a block is 128 bits. - * - * @param ap parameter block - * @param dst cleartext (aligned on 32-bit boundary) - * @param src ciphertext (aligned on 32-bit boundary) - * @retval 0 on success. +/*!\fn aesDecrypt(aesParam* ap, uint32_t* dst, const uint32_t* src) + * \brief This function performs the raw AES decryption; it decrypts one block + * of 128 bits. + * \param ap The cipher's parameter block. + * \param dst The cleartext; should be aligned on 32-bit boundary. + * \param src The ciphertext; should be aligned on 32-bit boundary. + * \retval 0 on success. */ -/*@-exportlocal@*/ BEECRYPTAPI -int aesDecrypt(aesParam* ap, uint32_t* dst, const uint32_t* src) - /*@modifies dst @*/; -/*@=exportlocal@*/ +int aesDecrypt (aesParam* ap, uint32_t* dst, const uint32_t* src); -/** \ingroup BC_aes_m - */ -/*@-exportlocal@*/ -BEECRYPTAPI /*@observer@*/ -uint32_t* aesFeedback(aesParam* ap) - /*@*/; -/*@=exportlocal@*/ +BEECRYPTAPI +uint32_t* aesFeedback(aesParam* ap); #ifdef __cplusplus } diff --git a/beecrypt/aes_be.h b/beecrypt/aes_be.h index a3a8525..16fcbea 100644 --- a/beecrypt/aes_be.h +++ b/beecrypt/aes_be.h @@ -17,7 +17,6 @@ * */ -/*@observer@*/ /*@unchecked@*/ const uint32_t _ae0[256] = { 0xc66363a5, 0xf87c7c84, 0xee777799, 0xf67b7b8d, 0xfff2f20d, 0xd66b6bbd, 0xde6f6fb1, 0x91c5c554, @@ -85,7 +84,6 @@ const uint32_t _ae0[256] = { 0x7bb0b0cb, 0xa85454fc, 0x6dbbbbd6, 0x2c16163a }; -/*@observer@*/ /*@unchecked@*/ const uint32_t _ae1[256] = { 0xa5c66363, 0x84f87c7c, 0x99ee7777, 0x8df67b7b, 0x0dfff2f2, 0xbdd66b6b, 0xb1de6f6f, 0x5491c5c5, @@ -153,7 +151,6 @@ const uint32_t _ae1[256] = { 0xcb7bb0b0, 0xfca85454, 0xd66dbbbb, 0x3a2c1616 }; -/*@observer@*/ /*@unchecked@*/ const uint32_t _ae2[256] = { 0x63a5c663, 0x7c84f87c, 0x7799ee77, 0x7b8df67b, 0xf20dfff2, 0x6bbdd66b, 0x6fb1de6f, 0xc55491c5, @@ -221,7 +218,6 @@ const uint32_t _ae2[256] = { 0xb0cb7bb0, 0x54fca854, 0xbbd66dbb, 0x163a2c16 }; -/*@observer@*/ /*@unchecked@*/ const uint32_t _ae3[256] = { 0x6363a5c6, 0x7c7c84f8, 0x777799ee, 0x7b7b8df6, 0xf2f20dff, 0x6b6bbdd6, 0x6f6fb1de, 0xc5c55491, @@ -289,7 +285,6 @@ const uint32_t _ae3[256] = { 0xb0b0cb7b, 0x5454fca8, 0xbbbbd66d, 0x16163a2c }; -/*@observer@*/ /*@unchecked@*/ const uint32_t _ae4[256] = { 0x63636363, 0x7c7c7c7c, 0x77777777, 0x7b7b7b7b, 0xf2f2f2f2, 0x6b6b6b6b, 0x6f6f6f6f, 0xc5c5c5c5, @@ -357,7 +352,6 @@ const uint32_t _ae4[256] = { 0xb0b0b0b0, 0x54545454, 0xbbbbbbbb, 0x16161616 }; -/*@observer@*/ /*@unchecked@*/ const uint32_t _ad0[256] = { 0x51f4a750, 0x7e416553, 0x1a17a4c3, 0x3a275e96, 0x3bab6bcb, 0x1f9d45f1, 0xacfa58ab, 0x4be30393, @@ -425,7 +419,6 @@ const uint32_t _ad0[256] = { 0x7bcb8461, 0xd532b670, 0x486c5c74, 0xd0b85742 }; -/*@observer@*/ /*@unchecked@*/ const uint32_t _ad1[256] = { 0x5051f4a7, 0x537e4165, 0xc31a17a4, 0x963a275e, 0xcb3bab6b, 0xf11f9d45, 0xabacfa58, 0x934be303, @@ -493,7 +486,6 @@ const uint32_t _ad1[256] = { 0x617bcb84, 0x70d532b6, 0x74486c5c, 0x42d0b857 }; -/*@observer@*/ /*@unchecked@*/ const uint32_t _ad2[256] = { 0xa75051f4, 0x65537e41, 0xa4c31a17, 0x5e963a27, 0x6bcb3bab, 0x45f11f9d, 0x58abacfa, 0x03934be3, @@ -561,7 +553,6 @@ const uint32_t _ad2[256] = { 0x84617bcb, 0xb670d532, 0x5c74486c, 0x5742d0b8 }; -/*@observer@*/ /*@unchecked@*/ const uint32_t _ad3[256] = { 0xf4a75051, 0x4165537e, 0x17a4c31a, 0x275e963a, 0xab6bcb3b, 0x9d45f11f, 0xfa58abac, 0xe303934b, @@ -629,7 +620,6 @@ const uint32_t _ad3[256] = { 0xcb84617b, 0x32b670d5, 0x6c5c7448, 0xb85742d0 }; -/*@observer@*/ /*@unchecked@*/ const uint32_t _ad4[256] = { 0x52525252, 0x09090909, 0x6a6a6a6a, 0xd5d5d5d5, 0x30303030, 0x36363636, 0xa5a5a5a5, 0x38383838, @@ -697,7 +687,6 @@ const uint32_t _ad4[256] = { 0x55555555, 0x21212121, 0x0c0c0c0c, 0x7d7d7d7d }; -/*@observer@*/ /*@unchecked@*/ static const uint32_t _arc[] = { 0x01000000, 0x02000000, 0x04000000, 0x08000000, 0x10000000, 0x20000000, 0x40000000, 0x80000000, diff --git a/beecrypt/aes_le.h b/beecrypt/aes_le.h index 8c911d0..6b62ea3 100644 --- a/beecrypt/aes_le.h +++ b/beecrypt/aes_le.h @@ -17,7 +17,6 @@ * */ -/*@observer@*/ /*@unchecked@*/ #if defined(OPTIMIZE_MMX) && (defined(OPTIMIZE_I586) || defined(OPTIMIZE_I686)) const uint64_t _ae0[256] = { #else @@ -89,7 +88,6 @@ const uint32_t _ae0[256] = { 0xcbb0b07b, 0xfc5454a8, 0xd6bbbb6d, 0x3a16162c }; -/*@observer@*/ /*@unchecked@*/ #if defined(OPTIMIZE_MMX) && (defined(OPTIMIZE_I586) || defined(OPTIMIZE_I686)) const uint64_t _ae1[256] = { #else @@ -161,7 +159,6 @@ const uint32_t _ae1[256] = { 0xb0b07bcb, 0x5454a8fc, 0xbbbb6dd6, 0x16162c3a }; -/*@observer@*/ /*@unchecked@*/ #if defined(OPTIMIZE_MMX) && (defined(OPTIMIZE_I586) || defined(OPTIMIZE_I686)) const uint64_t _ae2[256] = { #else @@ -233,7 +230,6 @@ const uint32_t _ae2[256] = { 0xb07bcbb0, 0x54a8fc54, 0xbb6dd6bb, 0x162c3a16 }; -/*@observer@*/ /*@unchecked@*/ #if defined(OPTIMIZE_MMX) && (defined(OPTIMIZE_I586) || defined(OPTIMIZE_I686)) const uint64_t _ae3[256] = { #else @@ -305,7 +301,6 @@ const uint32_t _ae3[256] = { 0x7bcbb0b0, 0xa8fc5454, 0x6dd6bbbb, 0x2c3a1616 }; -/*@observer@*/ /*@unchecked@*/ const uint32_t _ae4[256] = { 0x63636363, 0x7c7c7c7c, 0x77777777, 0x7b7b7b7b, 0xf2f2f2f2, 0x6b6b6b6b, 0x6f6f6f6f, 0xc5c5c5c5, @@ -373,7 +368,6 @@ const uint32_t _ae4[256] = { 0xb0b0b0b0, 0x54545454, 0xbbbbbbbb, 0x16161616 }; -/*@observer@*/ /*@unchecked@*/ #if defined(OPTIMIZE_MMX) && (defined(OPTIMIZE_I586) || defined(OPTIMIZE_I686)) const uint64_t _ad0[256] = { #else @@ -445,7 +439,6 @@ const uint32_t _ad0[256] = { 0x6184cb7b, 0x70b632d5, 0x745c6c48, 0x4257b8d0 }; -/*@observer@*/ /*@unchecked@*/ #if defined(OPTIMIZE_MMX) && (defined(OPTIMIZE_I586) || defined(OPTIMIZE_I686)) const uint64_t _ad1[256] = { #else @@ -517,7 +510,6 @@ const uint32_t _ad1[256] = { 0x84cb7b61, 0xb632d570, 0x5c6c4874, 0x57b8d042 }; -/*@observer@*/ /*@unchecked@*/ #if defined(OPTIMIZE_MMX) && (defined(OPTIMIZE_I586) || defined(OPTIMIZE_I686)) const uint64_t _ad2[256] = { #else @@ -589,7 +581,6 @@ const uint32_t _ad2[256] = { 0xcb7b6184, 0x32d570b6, 0x6c48745c, 0xb8d04257 }; -/*@observer@*/ /*@unchecked@*/ #if defined(OPTIMIZE_MMX) && (defined(OPTIMIZE_I586) || defined(OPTIMIZE_I686)) const uint64_t _ad3[256] = { #else @@ -661,7 +652,6 @@ const uint32_t _ad3[256] = { 0x7b6184cb, 0xd570b632, 0x48745c6c, 0xd04257b8 }; -/*@observer@*/ /*@unchecked@*/ const uint32_t _ad4[256] = { 0x52525252, 0x09090909, 0x6a6a6a6a, 0xd5d5d5d5, 0x30303030, 0x36363636, 0xa5a5a5a5, 0x38383838, @@ -729,7 +719,6 @@ const uint32_t _ad4[256] = { 0x55555555, 0x21212121, 0x0c0c0c0c, 0x7d7d7d7d }; -/*@observer@*/ /*@unchecked@*/ static const uint32_t _arc[] = { 0x00000001, 0x00000002, 0x00000004, 0x00000008, 0x00000010, 0x00000020, 0x00000040, 0x00000080, diff --git a/beecrypt/aesopt.h b/beecrypt/aesopt.h index bad0961..10abae4 100644 --- a/beecrypt/aesopt.h +++ b/beecrypt/aesopt.h @@ -26,6 +26,9 @@ #ifndef _AESOPT_H #define _AESOPT_H +#include "beecrypt/beecrypt.h" +#include "beecrypt/aes.h" + #ifdef __cplusplus extern "C" { #endif @@ -50,11 +53,13 @@ extern "C" { #if defined(__INTEL_COMPILER) # if defined(OPTIMIZE_I586) || defined(OPTIMIZE_I686) +# if defined(OPTIMIZE_MMX) # define ASM_AESENCRYPT # define ASM_AESENCRYPTECB # define ASM_AESDECRYPT # define ASM_AESDECRYPTECB # endif +# endif #endif #if defined(__SUNPRO_C) || defined(__SUNPRO_CC) diff --git a/beecrypt/beecrypt.api.h b/beecrypt/api.h similarity index 85% rename from beecrypt/beecrypt.api.h rename to beecrypt/api.h index 1ed54d9..71cab12 100644 --- a/beecrypt/beecrypt.api.h +++ b/beecrypt/api.h @@ -17,7 +17,7 @@ * */ -/*!\file beecrypt.api.h +/*!\file api.h * \brief BeeCrypt API, portability headers. * \author Bob Deblier */ @@ -30,15 +30,23 @@ #endif #if WIN32 && !__CYGWIN32__ -# include "beecrypt.win.h" +# include "beecrypt/win.h" # ifdef BEECRYPT_DLL_EXPORT # define BEECRYPTAPI __declspec(dllexport) # else # define BEECRYPTAPI __declspec(dllimport) # endif +# ifdef BEECRYPT_CXX_DLL_EXPORT +# define BEECRYPTCXXAPI __declspec(dllexport) +# define BEECRYPTCXXTEMPLATE +# else +# define BEECRYPTCXXAPI __declspec(dllimport) +# define BEECRYPTCXXTEMPLATE extern +# endif #else -# include "beecrypt.gnu.h" +# include "beecrypt/gnu.h" # define BEECRYPTAPI +# define BEECRYPTCXXAPI #endif #ifndef ROTL32 @@ -50,16 +58,12 @@ typedef uint8_t byte; -/*@-typeuse@*/ typedef int8_t javabyte; typedef int16_t javashort; typedef int32_t javaint; -/*@=typeuse@*/ typedef int64_t javalong; -/*@-typeuse@*/ typedef uint16_t javachar; -/*@=typeuse@*/ #if (MP_WBITS == 64) typedef uint64_t mpw; @@ -70,9 +74,7 @@ typedef uint32_t mphw; typedef uint64_t mpdw; # endif typedef uint32_t mpw; -/*@-typeuse@*/ typedef uint16_t mphw; -/*@=typeuse@*/ #else # error #endif diff --git a/beecrypt/autogen.sh b/beecrypt/autogen.sh index fa4e4d8c..3e2b8a0 100755 --- a/beecrypt/autogen.sh +++ b/beecrypt/autogen.sh @@ -1,44 +1,8 @@ -#!/bin/sh - +#! /bin/sh export CFLAGS export LDFLAGS - -LTV="libtoolize (GNU libtool) 1.5.6" -ACV="autoconf (GNU Autoconf) 2.59" -AMV="automake (GNU automake) 1.9" -USAGE=" -This script documents the versions of the tools I'm using to build rpm: - libtool-1.5.6 - autoconf-2.59 - automake-1.9 -Simply edit this script to change the libtool/autoconf/automake versions -checked if you need to, as rpm should build (and has built) with all -recent versions of libtool/autoconf/automake. -" - -[ "`libtoolize --version | head -1`" != "$LTV" ] && echo "$USAGE" && exit 1 -[ "`autoconf --version | head -1`" != "$ACV" ] && echo "$USAGE" && exit 1 -[ "`automake --version | head -1 | sed -e 's/1\.4[a-z]/1.4/'`" != "$AMV" ] && echo "$USAGE" && exit 1 - -libtoolize --copy --force +libtoolize --force --copy aclocal -autoheader automake -a -c autoconf - -if [ "$1" = "--noconfigure" ]; then - exit 0; -fi - -if [ X"$@" = X -a "X`uname -s`" = "XLinux" ]; then - if [ -d /usr/share/man ]; then - mandir=/usr/share/man - infodir=/usr/share/info - else - mandir=/usr/man - infodir=/usr/info - fi - CPPFLAGS="-Wall -g" ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --infodir=${infodir} --mandir=${mandir} --enable-static --with-python "$@" -else - ./configure "$@" -fi +autoheader diff --git a/beecrypt/base64.c b/beecrypt/base64.c index 1a89053..789eba1 100644 --- a/beecrypt/base64.c +++ b/beecrypt/base64.c @@ -1,4 +1,3 @@ -/*@-type@*/ /* * Copyright (c) 2000, 2001, 2002 Virtual Unlimited B.V. * @@ -23,15 +22,19 @@ * \author Bob Deblier */ -#include "system.h" -#include "base64.h" -#include "endianness.h" -#include "debug.h" +#define BEECRYPT_DLL_EXPORT -/*@unchecked@*/ -static int _debug = 0; +#if HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/base64.h" +#include "beecrypt/endianness.h" + +#if HAVE_CTYPE_H +# include +#endif -/*@unchecked@*/ /*@observer@*/ static const char* to_b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; /* encode 64 characters per line */ @@ -55,10 +58,10 @@ char* b64enc(const memchunk* chunk) while (div > 0) { - buf[0] = to_b64[ ((unsigned)data[0] >> 2) & 0x3f]; - buf[1] = to_b64[(((unsigned)data[0] << 4) & 0x30) | (((unsigned)data[1] >> 4) & 0xf)]; - buf[2] = to_b64[(((unsigned)data[1] << 2) & 0x3c) | (((unsigned)data[2] >> 6) & 0x3)]; - buf[3] = to_b64[ (unsigned)data[2] & 0x3f]; + buf[0] = to_b64[ (data[0] >> 2) & 0x3f]; + buf[1] = to_b64[((data[0] << 4) & 0x30) | ((data[1] >> 4) & 0xf)]; + buf[2] = to_b64[((data[1] << 2) & 0x3c) | ((data[2] >> 6) & 0x3)]; + buf[3] = to_b64[ data[2] & 0x3f]; data += 3; buf += 4; div--; @@ -73,16 +76,16 @@ char* b64enc(const memchunk* chunk) switch (rem) { case 2: - buf[0] = to_b64[ ((unsigned)data[0] >> 2) & 0x3f]; - buf[1] = to_b64[(((unsigned)data[0] << 4) & 0x30) + (((unsigned)data[1] >> 4) & 0xf)]; - buf[2] = to_b64[ ((unsigned)data[1] << 2) & 0x3c]; + buf[0] = to_b64[ (data[0] >> 2) & 0x3f]; + buf[1] = to_b64[((data[0] << 4) & 0x30) + ((data[1] >> 4) & 0xf)]; + buf[2] = to_b64[ (data[1] << 2) & 0x3c]; buf[3] = '='; buf += 4; chars += 4; break; case 1: - buf[0] = to_b64[ ((unsigned)data[0] >> 2) & 0x3f]; - buf[1] = to_b64[ ((unsigned)data[0] << 4) & 0x30]; + buf[0] = to_b64[ (data[0] >> 2) & 0x3f]; + buf[1] = to_b64[ (data[0] << 4) & 0x30]; buf[2] = '='; buf[3] = '='; buf += 4; @@ -94,9 +97,7 @@ char* b64enc(const memchunk* chunk) *buf = '\0'; } - /*@-dependenttrans@*/ /* FIX: buf = string makes string dependent */ return string; - /*@=dependenttrans@*/ } memchunk* b64dec(const char* string) @@ -128,7 +129,7 @@ memchunk* b64dec(const char* string) for (i = 0; i < vrfy; i++) { if (isspace(tmp[i])) - /*@innercontinue@*/ continue; + continue; if (tmp[i] == '=') { @@ -140,7 +141,7 @@ memchunk* b64dec(const char* string) return 0; /* end-of-message recognized */ - /*@innerbreak@*/ break; + break; } else { @@ -172,12 +173,11 @@ memchunk* b64dec(const char* string) for (i = 0; i < length; i++) { register char ch = string[i]; - register byte bits; + register byte bits = 0; if (isspace(ch)) continue; - bits = 0; if ((ch >= 'A') && (ch <= 'Z')) { bits = (byte) (ch - 'A'); @@ -205,18 +205,18 @@ memchunk* b64dec(const char* string) { case 0: data[tw+0] = (bits << 2) & 0xfc; - /*@switchbreak@*/ break; + break; case 1: data[tw+0] |= (bits >> 4) & 0x03; data[tw+1] = (bits << 4) & 0xf0; - /*@switchbreak@*/ break; + break; case 2: data[tw+1] |= (bits >> 2) & 0x0f; data[tw+2] = (bits << 6) & 0xc0; - /*@switchbreak@*/ break; + break; case 3: data[tw+2] |= bits & 0x3f; - /*@switchbreak@*/ break; + break; } if (qw == 4) @@ -237,11 +237,9 @@ int b64encode_chars_per_line = B64ENCODE_CHARS_PER_LINE; const char * b64encode_eolstr = B64ENCODE_EOLSTR; -/*@-internalglobs -modfilesys @*/ -char * b64encode (const void * data, size_t ns) +char* b64encode(const void* data, size_t ns) { - static char b64enc[] = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + static char b64enc[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; const char *e; const unsigned char *s = data; unsigned char *t, *te; @@ -256,198 +254,187 @@ char * b64encode (const void * data, size_t ns) nt = ((ns + 2) / 3) * 4; /* Add additional bytes necessary for eol string(s). */ - if (b64encode_chars_per_line > 0 && b64encode_eolstr != NULL) { - lc = (nt + b64encode_chars_per_line - 1) / b64encode_chars_per_line; - if (((nt + b64encode_chars_per_line - 1) % b64encode_chars_per_line) != 0) - ++lc; - nt += lc * strlen(b64encode_eolstr); + if (b64encode_chars_per_line > 0 && b64encode_eolstr != NULL) + { + lc = (nt + b64encode_chars_per_line - 1) / b64encode_chars_per_line; + if (((nt + b64encode_chars_per_line - 1) % b64encode_chars_per_line) != 0) + ++lc; + nt += lc * strlen(b64encode_eolstr); } t = te = malloc(nt + 1); lc = 0; if (te) - while (ns > 0) { - -if (_debug) -fprintf(stderr, "%7u %02x %02x %02x -> %02x %02x %02x %02x\n", -(unsigned)ns, (unsigned)s[0], (unsigned)s[1], (unsigned)s[2], -(unsigned)(s[0] >> 2), -(unsigned)((s[0] & 0x3) << 4) | (s[1] >> 4), -(unsigned)((s[1] & 0xf) << 2) | (s[2] >> 6), -(unsigned)(s[2]& 0x3f)); - c = *s++; - *te++ = b64enc[ (c >> 2) ], lc++; - *te++ = b64enc[ ((c & 0x3) << 4) | (*s >> 4) ], lc++; - if (--ns == 0) { - *te++ = '='; - *te++ = '='; - continue; - } - c = *s++; - *te++ = b64enc[ ((c & 0xf) << 2) | (*s >> 6) ], lc++; - if (--ns == 0) { - *te++ = '='; - continue; - } - *te++ = b64enc[ (int)(*s & 0x3f) ], lc++; - - /* Append eol string if desired. */ - if (b64encode_chars_per_line > 0 && b64encode_eolstr != NULL) { - if (lc >= b64encode_chars_per_line) { - for (e = b64encode_eolstr; *e != '\0'; e++) - *te++ = *e; - lc = 0; - } - } - s++; - --ns; - } + while (ns > 0) + { + c = *s++; + *te++ = b64enc[ (c >> 2) ], lc++; + *te++ = b64enc[ ((c & 0x3) << 4) | (*s >> 4) ], lc++; + if (--ns == 0) + { + *te++ = '='; + *te++ = '='; + continue; + } + c = *s++; + *te++ = b64enc[ ((c & 0xf) << 2) | (*s >> 6) ], lc++; + if (--ns == 0) + { + *te++ = '='; + continue; + } + *te++ = b64enc[ (int)(*s & 0x3f) ], lc++; - if (te) { - /* Append eol string if desired. */ - if (b64encode_chars_per_line > 0 && b64encode_eolstr != NULL) { - if (lc != 0) { - for (e = b64encode_eolstr; *e != '\0'; e++) - *te++ = *e; - } + /* Append eol string if desired. */ + if (b64encode_chars_per_line > 0 && b64encode_eolstr != NULL) + { + if (lc >= b64encode_chars_per_line) + { + for (e = b64encode_eolstr; *e != '\0'; e++) + *te++ = *e; + lc = 0; + } + } + s++; + --ns; } - *te = '\0'; + + if (te) + { + /* Append eol string if desired. */ + if (b64encode_chars_per_line > 0 && b64encode_eolstr != NULL) + { + if (lc != 0) + { + for (e = b64encode_eolstr; *e != '\0'; e++) + *te++ = *e; + } + } + *te = '\0'; } - /*@-mustfree -compdef @*/ - return (char *) t; - /*@=mustfree =compdef @*/ + return (char*) t; } -/*@=globs =internalglobs =modfilesys @*/ -/*@-internalglobs -modfilesys @*/ #define CRC24_INIT 0xb704ceL #define CRC24_POLY 0x1864cfbL -char * b64crc (const unsigned char * data, size_t ns) +char* b64crc (const unsigned char* data, size_t ns) { const unsigned char *s = data; uint32_t crc = CRC24_INIT; - while (ns-- > 0) { - int i; - crc ^= (*s++) << 16; - for (i = 0; i < 8; i++) { - crc <<= 1; - if (crc & 0x1000000) - crc ^= CRC24_POLY; - } + while (ns-- > 0) + { + int i; + crc ^= (*s++) << 16; + for (i = 0; i < 8; i++) + { + crc <<= 1; + if (crc & 0x1000000) + crc ^= CRC24_POLY; + } } crc &= 0xffffff; - /*@-unrecog@*/ /* FIX: include endianness.h? */ #if !WORDS_BIGENDIAN crc = swapu32(crc); #endif - /*@=unrecog@*/ data = (byte *)&crc; data++; ns = 3; - return b64encode(data, ns); + + return b64encode(data, ns); } -/*@=internalglobs =modfilesys @*/ -const char * b64decode_whitespace = B64DECODE_WHITESPACE; +const char* b64decode_whitespace = B64DECODE_WHITESPACE; -/*@-internalglobs -modfilesys @*/ -int b64decode (const char * s, void ** datap, size_t *lenp) +int b64decode(const char* s, void** datap, size_t* lenp) { - unsigned char b64dec[256]; - const unsigned char *t; - unsigned char *te; - int ns, nt; - unsigned a, b, c, d; + unsigned char b64dec[256]; + const unsigned char *t; + unsigned char *te; + int ns, nt; + unsigned a, b, c, d; if (s == NULL) return 1; /* Setup character lookup tables. */ memset(b64dec, 0x80, sizeof(b64dec)); for (c = 'A'; c <= 'Z'; c++) - b64dec[ c ] = 0 + (c - 'A'); + b64dec[ c ] = 0 + (c - 'A'); for (c = 'a'; c <= 'z'; c++) - b64dec[ c ] = 26 + (c - 'a'); + b64dec[ c ] = 26 + (c - 'a'); for (c = '0'; c <= '9'; c++) - b64dec[ c ] = 52 + (c - '0'); - b64dec[(unsigned)'+'] = 62; - b64dec[(unsigned)'/'] = 63; - b64dec[(unsigned)'='] = 0; + b64dec[ c ] = 52 + (c - '0'); + b64dec[(unsigned)'+'] = 62; + b64dec[(unsigned)'/'] = 63; + b64dec[(unsigned)'='] = 0; /* Mark whitespace characters. */ - if (b64decode_whitespace) { - const char *e; - for (e = b64decode_whitespace; *e != '\0'; e++) { - if (b64dec[ (unsigned)*e ] == 0x80) - b64dec[ (unsigned)*e ] = 0x81; - } + if (b64decode_whitespace) + { + const char *e; + for (e = b64decode_whitespace; *e != '\0'; e++) + { + if (b64dec[ (unsigned)*e ] == 0x80) + b64dec[ (unsigned)*e ] = 0x81; + } } /* Validate input buffer */ ns = 0; - for (t = (unsigned char *) s; *t != '\0'; t++) { - switch (b64dec[(unsigned)*t]) { - case 0x80: /* invalid chararcter */ -if (_debug) -fprintf(stderr, "--- b64decode %c(%02x) %02x\n", *t, (unsigned)(*t & 0xff), (unsigned)b64dec[ (unsigned)*t ]); - return 3; - /*@notreached@*/ /*@switchbreak@*/ break; - case 0x81: /* white space */ - /*@switchbreak@*/ break; - default: - ns++; - /*@switchbreak@*/ break; - } + for (t = (unsigned char*) s; *t != '\0'; t++) + { + switch (b64dec[(unsigned) *t]) + { + case 0x80: /* invalid chararcter */ + return 3; + case 0x81: /* white space */ + break; + default: + ns++; + break; + } } - if (((unsigned)ns) & 0x3) return 2; + if (((unsigned) ns) & 0x3) return 2; nt = (ns / 4) * 3; t = te = malloc(nt + 1); - while (ns > 0) { - - /* Get next 4 characters, ignoring whitespace. */ - while ((a = b64dec[ (unsigned)*s++ ]) == 0x81) - {}; - while ((b = b64dec[ (unsigned)*s++ ]) == 0x81) - {}; - while ((c = b64dec[ (unsigned)*s++ ]) == 0x81) - {}; - while ((d = b64dec[ (unsigned)*s++ ]) == 0x81) - {}; - -if (_debug) -fprintf(stderr, "%7u %02x %02x %02x %02x -> %02x %02x %02x\n", -(unsigned)ns, a, b, c, d, -(((a << 2) | (b >> 4)) & 0xff), -(((b << 4) | (c >> 2)) & 0xff), -(((c << 6) | d) & 0xff)); - - ns -= 4; - *te++ = (a << 2) | (b >> 4); - if (s[-2] == '=') break; - *te++ = (b << 4) | (c >> 2); - if (s[-1] == '=') break; - *te++ = (c << 6) | d; + while (ns > 0) + { + /* Get next 4 characters, ignoring whitespace. */ + while ((a = b64dec[ (unsigned)*s++ ]) == 0x81) + ; + while ((b = b64dec[ (unsigned)*s++ ]) == 0x81) + ; + while ((c = b64dec[ (unsigned)*s++ ]) == 0x81) + ; + while ((d = b64dec[ (unsigned)*s++ ]) == 0x81) + ; + + ns -= 4; + *te++ = (a << 2) | (b >> 4); + if (s[-2] == '=') break; + *te++ = (b << 4) | (c >> 2); + if (s[-1] == '=') break; + *te++ = (c << 6) | d; } - if (ns != 0) { /* XXX can't happen, just in case */ - if (t) free((void *)t); - return 1; + if (ns != 0) + { /* XXX can't happen, just in case */ + if (t) free((void *)t); + return 1; } if (lenp) - *lenp = (te - t); + *lenp = (te - t); if (datap) - *datap = (void *)t; + *datap = (void *)t; else - if (t) free((void *)t); + if (t) free((void *)t); return 0; } -/*@=globs =internalglobs =modfilesys @*/ -/*@=type@*/ diff --git a/beecrypt/base64.h b/beecrypt/base64.h index 139b3b5..16ed450 100644 --- a/beecrypt/base64.h +++ b/beecrypt/base64.h @@ -19,84 +19,72 @@ /*!\file base64.h * \brief Base64 encoding and decoding, headers. - * \author Bob Deblier + * \author Bob Deblier */ #ifndef _BASE64_H #define _BASE64_H -#include "beecrypt.h" +#include "beecrypt/beecrypt.h" -/** +/*!\ * Decode white space character set (default). */ -/*@-exportlocal@*/ -/*@unchecked@*/ /*@observer@*/ /*@null@*/ -extern const char * b64decode_whitespace; -/*@=exportlocal@*/ +extern const char* b64decode_whitespace; #define B64DECODE_WHITESPACE " \f\n\r\t\v" -/** +/*!\ * Encode 72 characters per line (default). */ -/*@-exportlocal@*/ -/*@unchecked@*/ extern int b64encode_chars_per_line; -/*@=exportlocal@*/ #define B64ENCODE_CHARS_PER_LINE 72 -/** +/*!\ * Encode end-of-line string (default). */ -/*@-exportlocal@*/ -/*@unchecked@*/ /*@observer@*/ /*@null@*/ -extern const char * b64encode_eolstr; -/*@=exportlocal@*/ +extern const char* b64encode_eolstr; #define B64ENCODE_EOLSTR "\n" #ifdef __cplusplus extern "C" { #endif -/** +/*! * Encode chunks of 3 bytes of binary input into 4 bytes of base64 output. - * @param data binary data - * @param ns no. bytes of data (0 uses strlen(data)) - * @return (malloc'd) base64 string + * \param data binary data + * \param ns no. bytes of data (0 uses strlen(data)) + * \return (malloc'd) base64 string */ -BEECRYPTAPI /*@only@*/ /*@null@*/ /*@unused@*/ -char * b64encode (const void * data, size_t ns) - /*@*/; +BEECRYPTAPI +char* b64encode(const void* data, size_t ns); -/** +/*! * Encode crc of binary input data into 5 bytes of base64 output. - * @param data binary data - * @param ns no. bytes of binary data - * @return (malloc'd) base64 string + * \param data binary data + * \param ns no. bytes of binary data + * \return (malloc'd) base64 string */ -BEECRYPTAPI /*@only@*/ /*@null@*/ /*@unused@*/ -char * b64crc (const unsigned char * data, size_t ns) - /*@*/; +BEECRYPTAPI +char* b64crc(const unsigned char* data, size_t ns); -/** +/*! * Decode chunks of 4 bytes of base64 input into 3 bytes of binary output. - * @param s base64 string - * @retval datap address of (malloc'd) binary data - * @retval lenp address of no. bytes of binary data - * @return 0 on success, 1: s == NULL, 2: bad length, 3: bad char + * \param s base64 string + * \retval datap address of (malloc'd) binary data + * \retval lenp address of no. bytes of binary data + * \return 0 on success, 1: s == NULL, 2: bad length, 3: bad char */ -BEECRYPTAPI /*@unused@*/ -int b64decode (const char * s, /*@out@*/ void ** datap, /*@out@*/ size_t *lenp) - /*@modifies *datap, *lenp @*/; +BEECRYPTAPI +int b64decode(const char* s, void** datap, size_t* lenp); -/** +/*! */ -BEECRYPTAPI /*@only@*/ /*@null@*/ /*@unused@*/ +BEECRYPTAPI char* b64enc(const memchunk*); -/** +/*! */ -BEECRYPTAPI /*@only@*/ /*@null@*/ /*@unused@*/ +BEECRYPTAPI memchunk* b64dec(const char*); #ifdef __cplusplus diff --git a/beecrypt/beecrypt.c b/beecrypt/beecrypt.c index 49ffd8a..b8bc974 100644 --- a/beecrypt/beecrypt.c +++ b/beecrypt/beecrypt.c @@ -1,4 +1,3 @@ -/*@-compdef -sizeoftype@*/ /* * Copyright (c) 1999, 2000, 2001, 2002 Virtual Unlimited B.V. * @@ -23,27 +22,31 @@ * \ingroup ES_m PRNG_m HASH_m HMAC_m BC_m */ -#include "system.h" -#include "beecrypt.h" +#define BEECRYPT_DLL_EXPORT -#include "entropy.h" -#include "fips186.h" -#include "hmacmd5.h" -#include "hmacsha1.h" -#include "hmacsha256.h" -#include "md5.h" -#include "mp.h" -#include "mtprng.h" -#include "sha1.h" -#include "sha256.h" +#if HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/beecrypt.h" + +#include "beecrypt/entropy.h" -#include "aes.h" -#include "blowfish.h" -#include "blockmode.h" +#include "beecrypt/fips186.h" +#include "beecrypt/mtprng.h" -#include "debug.h" +#include "beecrypt/md5.h" +#include "beecrypt/sha1.h" +#include "beecrypt/sha256.h" + +#include "beecrypt/hmacmd5.h" +#include "beecrypt/hmacsha1.h" +#include "beecrypt/hmacsha256.h" + +#include "beecrypt/aes.h" +#include "beecrypt/blowfish.h" +#include "beecrypt/blockmode.h" -/*@observer@*/ /*@unchecked@*/ static entropySource entropySourceList[] = { #if WIN32 @@ -108,10 +111,7 @@ const entropySource* entropySourceDefault() { return entropySourceList+0; } - else - { - return (const entropySource*) 0; - } + return (const entropySource*) 0; } int entropyGatherNext(byte* data, size_t size) @@ -138,7 +138,6 @@ int entropyGatherNext(byte* data, size_t size) return -1; } -/*@observer@*/ /*@unchecked@*/ static const randomGenerator* randomGeneratorList[] = { &fips186prng, @@ -157,9 +156,7 @@ const randomGenerator* randomGeneratorGet(int index) if ((index < 0) || (index >= RANDOMGENERATORS)) return (const randomGenerator*) 0; - /*@-compmempass@*/ return randomGeneratorList[index]; - /*@=compmempass@*/ } const randomGenerator* randomGeneratorFind(const char* name) @@ -169,9 +166,7 @@ const randomGenerator* randomGeneratorFind(const char* name) for (index = 0; index < RANDOMGENERATORS; index++) { if (strcmp(name, randomGeneratorList[index]->name) == 0) - /*@-compmempass@*/ return randomGeneratorList[index]; - /*@=compmempass@*/ } return (const randomGenerator*) 0; } @@ -183,9 +178,7 @@ const randomGenerator* randomGeneratorDefault() if (selection) return randomGeneratorFind(selection); else - /*@-compmempass @*/ return &fips186prng; - /*@=compmempass @*/ } int randomGeneratorContextInit(randomGeneratorContext* ctxt, const randomGenerator* rng) @@ -197,40 +190,42 @@ int randomGeneratorContextInit(randomGeneratorContext* ctxt, const randomGenerat return -1; ctxt->rng = rng; - ctxt->param = (randomGeneratorParam*) calloc(rng->paramsize, 1); - /*@-nullstate@*/ /* FIX: ctxt->param may be NULL */ - if (ctxt->param == (randomGeneratorParam*) 0) - return -1; + if (rng->paramsize) + { + ctxt->param = (randomGeneratorParam*) calloc(rng->paramsize, 1); + if (ctxt->param == (randomGeneratorParam*) 0) + return -1; + } + else + ctxt->param = (randomGeneratorParam*) 0; return ctxt->rng->setup(ctxt->param); - /*@=nullstate@*/ } int randomGeneratorContextFree(randomGeneratorContext* ctxt) { - register int rc; + register int rc = 0; - /*@-mustfree@*/ if (ctxt == (randomGeneratorContext*) 0) return -1; if (ctxt->rng == (randomGenerator*) 0) return -1; - if (ctxt->param == (randomGeneratorParam*) 0) - return -1; - /*@=mustfree@*/ - - rc = ctxt->rng->cleanup(ctxt->param); + if (ctxt->rng->paramsize) + { + if (ctxt->param == (randomGeneratorParam*) 0) + return -1; + + rc = ctxt->rng->cleanup(ctxt->param); - free(ctxt->param); + free(ctxt->param); - ctxt->param = (randomGeneratorParam*) 0; + ctxt->param = (randomGeneratorParam*) 0; + } - /*@-nullstate@*/ /* FIX: ctxt->param may be NULL */ return rc; - /*@=nullstate@*/ } int randomGeneratorContextNext(randomGeneratorContext* ctxt, byte* data, size_t size) @@ -238,7 +233,11 @@ int randomGeneratorContextNext(randomGeneratorContext* ctxt, byte* data, size_t return ctxt->rng->next(ctxt->param, data, size); } -/*@observer@*/ /*@unchecked@*/ +int randomGeneratorContextSeed(randomGeneratorContext* ctxt, const byte* data, size_t size) +{ + return ctxt->rng->seed(ctxt->param, data, size); +} + static const hashFunction* hashFunctionList[] = { &md5, @@ -260,9 +259,7 @@ const hashFunction* hashFunctionDefault() if (selection) return hashFunctionFind(selection); else - /*@-compmempass @*/ return &sha1; - /*@=compmempass @*/ } const hashFunction* hashFunctionGet(int index) @@ -270,9 +267,7 @@ const hashFunction* hashFunctionGet(int index) if ((index < 0) || (index >= HASHFUNCTIONS)) return (const hashFunction*) 0; - /*@-compmempass@*/ return hashFunctionList[index]; - /*@=compmempass@*/ } const hashFunction* hashFunctionFind(const char* name) @@ -282,9 +277,7 @@ const hashFunction* hashFunctionFind(const char* name) for (index = 0; index < HASHFUNCTIONS; index++) { if (strcmp(name, hashFunctionList[index]->name) == 0) - /*@-compmempass@*/ return hashFunctionList[index]; - /*@=compmempass@*/ } return (const hashFunction*) 0; } @@ -300,31 +293,25 @@ int hashFunctionContextInit(hashFunctionContext* ctxt, const hashFunction* hash) ctxt->algo = hash; ctxt->param = (hashFunctionParam*) calloc(hash->paramsize, 1); - /*@-nullstate@*/ /* FIX: ctxt->param may be NULL */ if (ctxt->param == (hashFunctionParam*) 0) return -1; return ctxt->algo->reset(ctxt->param); - /*@=nullstate@*/ } int hashFunctionContextFree(hashFunctionContext* ctxt) { - /*@-mustfree@*/ if (ctxt == (hashFunctionContext*) 0) return -1; if (ctxt->param == (hashFunctionParam*) 0) return -1; - /*@=mustfree@*/ free(ctxt->param); ctxt->param = (hashFunctionParam*) 0; - /*@-nullstate@*/ /* FIX: ctxt->param may be NULL */ return 0; - /*@=nullstate@*/ } int hashFunctionContextReset(hashFunctionContext* ctxt) @@ -389,22 +376,25 @@ int hashFunctionContextUpdateMP(hashFunctionContext* ctxt, const mpnumber* n) if (n != (mpnumber*) 0) { int rc; - byte* tmp = (byte*) malloc(MP_WORDS_TO_BYTES(n->size) + 1); + + /* get the number of significant bits in the number */ + size_t sig = mpbits(n->size, n->data); + + /* calculate how many bytes we need for a java-style encoding; + * if the most significant bit of the most significant byte + * is set, then we need to prefix a zero byte. + */ + size_t req = ((sig+7) >> 3) + (((sig&7) == 0) ? 1 : 0); + + byte* tmp = (byte*) malloc(req); if (tmp == (byte*) 0) return -1; - if (mpmsbset(n->size, n->data)) - { - tmp[0] = 0; - (void) i2osp(tmp+1, MP_WORDS_TO_BYTES(n->size), n->data, n->size); - rc = ctxt->algo->update(ctxt->param, tmp, MP_WORDS_TO_BYTES(n->size) + 1); - } - else - { - (void) i2osp(tmp, MP_WORDS_TO_BYTES(n->size), n->data, n->size); - rc = ctxt->algo->update(ctxt->param, tmp, MP_WORDS_TO_BYTES(n->size)); - } + i2osp(tmp, req, n->data, n->size); + + rc = ctxt->algo->update(ctxt->param, tmp, req); + free(tmp); return rc; @@ -477,12 +467,9 @@ int hashFunctionContextDigestMatch(hashFunctionContext* ctxt, const mpnumber* d) mpnfree(&match); - /*@-mustfree@*/ /* dig.data is OK */ return rc; - /*@=mustfree@*/ } -/*@observer@*/ /*@unchecked@*/ static const keyedHashFunction* keyedHashFunctionList[] = { &hmacmd5, @@ -504,9 +491,7 @@ const keyedHashFunction* keyedHashFunctionDefault() if (selection) return keyedHashFunctionFind(selection); else - /*@-compmempass @*/ return &hmacsha1; - /*@=compmempass @*/ } const keyedHashFunction* keyedHashFunctionGet(int index) @@ -514,9 +499,7 @@ const keyedHashFunction* keyedHashFunctionGet(int index) if ((index < 0) || (index >= KEYEDHASHFUNCTIONS)) return (const keyedHashFunction*) 0; - /*@-compmempass@*/ return keyedHashFunctionList[index]; - /*@=compmempass@*/ } const keyedHashFunction* keyedHashFunctionFind(const char* name) @@ -526,9 +509,7 @@ const keyedHashFunction* keyedHashFunctionFind(const char* name) for (index = 0; index < KEYEDHASHFUNCTIONS; index++) { if (strcmp(name, keyedHashFunctionList[index]->name) == 0) - /*@-compmempass@*/ return keyedHashFunctionList[index]; - /*@=compmempass@*/ } return (const keyedHashFunction*) 0; } @@ -544,17 +525,14 @@ int keyedHashFunctionContextInit(keyedHashFunctionContext* ctxt, const keyedHash ctxt->algo = mac; ctxt->param = (keyedHashFunctionParam*) calloc(mac->paramsize, 1); - /*@-nullstate@*/ /* FIX: ctxt->param may be NULL */ if (ctxt->param == (keyedHashFunctionParam*) 0) return -1; return ctxt->algo->reset(ctxt->param); - /*@=nullstate@*/ } int keyedHashFunctionContextFree(keyedHashFunctionContext* ctxt) { - /*@-mustfree@*/ if (ctxt == (keyedHashFunctionContext*) 0) return -1; @@ -563,15 +541,12 @@ int keyedHashFunctionContextFree(keyedHashFunctionContext* ctxt) if (ctxt->param == (keyedHashFunctionParam*) 0) return -1; - /*@=mustfree@*/ free(ctxt->param); ctxt->param = (keyedHashFunctionParam*) 0; - /*@-nullstate@*/ /* FIX: ctxt->param may be NULL */ return 0; - /*@=nullstate@*/ } int keyedHashFunctionContextSetup(keyedHashFunctionContext* ctxt, const byte* key, size_t keybits) @@ -652,23 +627,27 @@ int keyedHashFunctionContextUpdateMP(keyedHashFunctionContext* ctxt, const mpnum if (n != (mpnumber*) 0) { - register int rc; - register byte* temp = (byte*) malloc(MP_WORDS_TO_BYTES(n->size)+1); - if (temp == (byte*) 0) + int rc; + + /* get the number of significant bits in the number */ + size_t sig = mpbits(n->size, n->data); + + /* calculate how many bytes we need a java-style encoding; if the + * most significant bit of the most significant byte is set, then + * we need to prefix a zero byte. + */ + size_t req = ((sig+7) >> 3) + (((sig&7) == 0) ? 1 : 0); + + byte* tmp = (byte*) malloc(req); + + if (tmp == (byte*) 0) return -1; - if (mpmsbset(n->size, n->data)) - { - temp[0] = 0; - (void) i2osp(temp+1, MP_WORDS_TO_BYTES(n->size), n->data, n->size); - rc = ctxt->algo->update(ctxt->param, temp, MP_WORDS_TO_BYTES(n->size)+1); - } - else - { - (void) i2osp(temp, MP_WORDS_TO_BYTES(n->size), n->data, n->size); - rc = ctxt->algo->update(ctxt->param, temp, MP_WORDS_TO_BYTES(n->size)); - } - free(temp); + i2osp(tmp, req, n->data, n->size); + + rc = ctxt->algo->update(ctxt->param, tmp, req); + + free(tmp); return rc; } @@ -692,7 +671,7 @@ int keyedHashFunctionContextDigest(keyedHashFunctionContext* ctxt, byte* digest) return ctxt->algo->digest(ctxt->param, digest); } -int keyedHashFunctionContextDigestMP(keyedHashFunctionContext* ctxt, const mpnumber* d) +int keyedHashFunctionContextDigestMP(keyedHashFunctionContext* ctxt, mpnumber* d) { if (ctxt == (keyedHashFunctionContext*) 0) return -1; @@ -740,12 +719,9 @@ int keyedHashFunctionContextDigestMatch(keyedHashFunctionContext* ctxt, const mp mpnfree(&match); - /*@-mustfree@*/ /* dig.data is OK */ return rc; - /*@=mustfree@*/ } -/*@observer@*/ /*@unchecked@*/ static const blockCipher* blockCipherList[] = { &aes, @@ -766,9 +742,7 @@ const blockCipher* blockCipherDefault() if (selection) return blockCipherFind(selection); else - /*@-compmempass @*/ return &aes; - /*@=compmempass @*/ } const blockCipher* blockCipherGet(int index) @@ -776,9 +750,7 @@ const blockCipher* blockCipherGet(int index) if ((index < 0) || (index >= BLOCKCIPHERS)) return (const blockCipher*) 0; - /*@-compmempass@*/ return blockCipherList[index]; - /*@=compmempass@*/ } const blockCipher* blockCipherFind(const char* name) @@ -788,9 +760,7 @@ const blockCipher* blockCipherFind(const char* name) for (index = 0; index < BLOCKCIPHERS; index++) { if (strcmp(name, blockCipherList[index]->name) == 0) - /*@-compmempass@*/ return blockCipherList[index]; - /*@=compmempass@*/ } return (const blockCipher*) 0; @@ -808,12 +778,10 @@ int blockCipherContextInit(blockCipherContext* ctxt, const blockCipher* ciph) ctxt->param = (blockCipherParam*) calloc(ciph->paramsize, 1); ctxt->op = NOCRYPT; - /*@-nullstate@*/ /* FIX: ctxt->param may be NULL */ if (ctxt->param == (blockCipherParam*) 0) return -1; return 0; - /*@=nullstate@*/ } int blockCipherContextSetup(blockCipherContext* ctxt, const byte* key, size_t keybits, cipherOperation op) @@ -853,78 +821,62 @@ int blockCipherContextSetIV(blockCipherContext* ctxt, const byte* iv) int blockCipherContextFree(blockCipherContext* ctxt) { - /*@-mustfree@*/ if (ctxt == (blockCipherContext*) 0) return -1; if (ctxt->param == (blockCipherParam*) 0) return -1; - /*@=mustfree@*/ free(ctxt->param); ctxt->param = (blockCipherParam*) 0; - /*@-nullstate@*/ /* FIX: ctxt->param is NULL */ return 0; - /*@=nullstate@*/ } -int blockCipherContextECB(blockCipherContext* ctxt, uint32_t* dst, const uint32_t* src, size_t nblocks) +int blockCipherContextECB(blockCipherContext* ctxt, uint32_t* dst, const uint32_t* src, int nblocks) { switch (ctxt->op) { case NOCRYPT: -/*@-mayaliasunique@*/ memcpy(dst, src, nblocks * ctxt->algo->blocksize); -/*@=mayaliasunique@*/ return 0; - /*@notreached@*/ break; case ENCRYPT: return (ctxt->algo->ecb.encrypt) ? ctxt->algo->ecb.encrypt(ctxt->param, dst, src, nblocks) : blockEncryptECB(ctxt->algo, ctxt->param, dst, src, nblocks); - /*@notreached@*/ break; case DECRYPT: return (ctxt->algo->ecb.decrypt) ? ctxt->algo->ecb.decrypt(ctxt->param, dst, src, nblocks) : blockDecryptECB(ctxt->algo, ctxt->param, dst, src, nblocks); - /*@notreached@*/ break; } - /*@notreached@*/ return -1; } -int blockCipherContextCBC(blockCipherContext* ctxt, uint32_t* dst, const uint32_t* src, size_t nblocks) +int blockCipherContextCBC(blockCipherContext* ctxt, uint32_t* dst, const uint32_t* src, int nblocks) { switch (ctxt->op) { case NOCRYPT: -/*@-mayaliasunique@*/ memcpy(dst, src, nblocks * ctxt->algo->blocksize); -/*@=mayaliasunique@*/ return 0; - /*@notreached@*/ break; case ENCRYPT: return (ctxt->algo->cbc.encrypt) ? ctxt->algo->cbc.encrypt(ctxt->param, dst, src, nblocks) : blockEncryptCBC(ctxt->algo, ctxt->param, dst, src, nblocks); - /*@notreached@*/ break; case DECRYPT: return (ctxt->algo->cbc.decrypt) ? ctxt->algo->cbc.decrypt(ctxt->param, dst, src, nblocks) : blockDecryptCBC(ctxt->algo, ctxt->param, dst, src, nblocks); - /*@notreached@*/ break; } - /*@notreached@*/ return -1; } #if WIN32 __declspec(dllexport) -BOOL WINAPI DllMain(HINSTANCE hInst, DWORD wDataSeg, LPVOID lpReserved) +BOOL WINAPI DllMain(HINSTANCE hInst, DWORD fdwReason, LPVOID lpReserved) { - switch (wDataSeg) + switch (fdwReason) { case DLL_PROCESS_ATTACH: entropy_provider_setup(hInst); @@ -933,7 +885,7 @@ BOOL WINAPI DllMain(HINSTANCE hInst, DWORD wDataSeg, LPVOID lpReserved) entropy_provider_cleanup(); break; } - return TRUE; + + return TRUE; } #endif -/*@=compdef =sizeoftype@*/ diff --git a/beecrypt/beecrypt.h b/beecrypt/beecrypt.h index 2acfc01..f383267 100644 --- a/beecrypt/beecrypt.h +++ b/beecrypt/beecrypt.h @@ -30,150 +30,119 @@ #ifndef _BEECRYPT_H #define _BEECRYPT_H -#include "beecrypt.api.h" +#include "beecrypt/api.h" -#include "memchunk.h" -#include "mpnumber.h" -#include "mp.h" +#include "beecrypt/memchunk.h" +#include "beecrypt/mpnumber.h" -/** \name Entropy sources */ -/*@{*/ +/* + * Entropy Sources + */ -/** \ingroup ES_m - * Return an array of 32-bit unsigned integers of given size with - * entropy data. - * - * @retval data entropy data - * @param size no. of ints of data - * @return 0 on success, -1 on failure +/*!\typedef entropyNext + * \brief Prototype definition for an entropy-generating function. + * \ingroup ES_m */ -typedef int (*entropyNext) (/*@out@*/ byte* data, size_t size) - /*@modifies data @*/; +typedef int (*entropyNext)(byte*, size_t); -/** \ingroup ES_m - * Methods and parameters for entropy sources. - * Each specific entropy source MUST be written to be multithread-safe. +/*!\brief This struct holds information and pointers to code specific to each + * source of entropy. + * \ingroup ES_m */ -typedef struct +#ifdef __cplusplus +struct BEECRYPTAPI entropySource +#else +struct _entropySource +#endif { -/*@observer@*/ - const char* name; /*!< entropy source name */ -/*@unused@*/ - const entropyNext next; /*!< return entropy function */ -} entropySource; + /*!\var name + * \brief The entropy source's name. + */ + const char* name; + /*!\var next + * \brief Points to the function which produces the entropy. + */ + const entropyNext next; +}; + +#ifndef __cplusplus +typedef struct _entropySource entropySource; +#endif #ifdef __cplusplus extern "C" { #endif -/** \ingroup ES_m - * Return the number of entropy sources available. - * @return number of entropy sources available +/*!\fn int entropySourceCount() + * \brief This function returns the number of entropy sources implemented by + * the library. + * \return The number of implemented entropy sources. */ -BEECRYPTAPI /*@unused@*/ -int entropySourceCount(void) - /*@*/; +BEECRYPTAPI +int entropySourceCount(void); -/** \ingroup ES_m - * Retrieve a entropy source by index. - * @param n entropy source index - * @return entropy source pointer (or NULL) +/*!\fn const entropySource* entropySourceGet(int n) + * \brief This function returns the \a n -th entropy source implemented by + * the library. + * \param n Index of the requested entropy source; legal values are 0 + * through entropySourceCount() - 1. + * \return A pointer to an entropy source or null, if the index was out of + * range. */ -BEECRYPTAPI /*@observer@*/ /*@null@*/ /*@unused@*/ -const entropySource* entropySourceGet(int n) - /*@*/; +BEECRYPTAPI +const entropySource* entropySourceGet(int n); -/** \ingroup ES_m - * Retrieve a entropy source by name. - * @param name entropy source name - * @return entropy source pointer (or NULL) +/*!\fn const entropySource* entropySourceFind(const char* name) + * \brief This function returns the entropy source specified by the given name. + * \param name Name of the requested entropy source. + * \return A pointer to an entropy source or null, if the name wasn't found. */ -/*@-exportlocal@*/ -BEECRYPTAPI /*@observer@*/ /*@null@*/ -const entropySource* entropySourceFind(const char* name) - /*@*/; -/*@=exportlocal@*/ +BEECRYPTAPI +const entropySource* entropySourceFind(const char* name); -/** \ingroup ES_m - * Retrieve the default entropy source. - * If the BEECRYPT_ENTROPY environment variable is set, use that - * entropy source. Otherwise, use the 1st entry in the internal table. - * @return entropy source pointer (or NULL) +/*!\fn const entropySource* entropySourceDefault() + * \brief This functions returns the default entropy source; the default value + * can be specified by setting environment variable BEECRYPT_ENTROPY. + * \return A pointer to an entropy source or null, in case an error occured. */ -BEECRYPTAPI /*@observer@*/ /*@null@*/ /*@unused@*/ -const entropySource* entropySourceDefault(void) - /*@*/; +BEECRYPTAPI +const entropySource* entropySourceDefault(void); -/** \ingroup ES_m - * Gather entropy from multiple sources (if BEECRYPT_ENTROPY is not set). +/*!\fn int entropyGatherNext(byte* data, size_t size) + * \brief This function gathers \a size bytes of entropy into \a data. * - * @retval data entropy data - * @param size no. of ints of data - * @return 0 on success, -1 on failure + * Unless environment variable BEECRYPT_ENTROPY is set, this function will + * try each successive entropy source to gather up the requested amount. + * + * \param data Points to where the entropy should be stored. + * \param size Indicates how many bytes of entropy should be gathered. + * \retval 0 On success. + * \retval -1 On failure. */ BEECRYPTAPI -int entropyGatherNext(byte* data, size_t size) - /*@*/; +int entropyGatherNext(byte*, size_t); #ifdef __cplusplus } #endif -/*@}*/ -/** \name Pseudo-random Number Generators */ -/*@{*/ - -/** \ingroup PRNG_m - */ -typedef void randomGeneratorParam; - -/** \ingroup PRNG_m - * Initialize the parameters for use, and seed the generator - * with entropy from the default entropy source. - * - * @param param generator parameters - * @return 0 on success, -1 on failure - */ -typedef int (*randomGeneratorSetup) (randomGeneratorParam* param) - /*@modifies *param @*/; - -/** \ingroup PRNG_m - * Re-seed the random generator with user-provided entropy. - * - * @param param generator parameters - * @param data user entropy - * @param size no. of ints of entropy - * @return 0 on success, -1 on failure +/* + * Pseudo-random Number Generators */ -typedef int (*randomGeneratorSeed) (randomGeneratorParam* param, const byte* data, size_t size) - /*@modifies *param @*/; -/** \ingroup PRNG_m - * Return an array of 32-bit unsigned integers of given size with - * pseudo-random data. - * - * @param param generator parameters - * @retval data pseudo-random data - * @param size no. of ints of data - * @return 0 on success, -1 on failure - */ -typedef int (*randomGeneratorNext) (randomGeneratorParam* param, /*@out@*/ byte* data, size_t size) - /*@modifies *param, *data @*/; +typedef void randomGeneratorParam; -/** \ingroup PRNG_m - * Cleanup after using a generator. - * - * @param param generator parameters - * @return 0 on success, -1 on failure - */ -typedef int (*randomGeneratorCleanup) (randomGeneratorParam* param) - /*@modifies *param @*/; +typedef int (*randomGeneratorSetup )(randomGeneratorParam*); +typedef int (*randomGeneratorSeed )(randomGeneratorParam*, const byte*, size_t); +typedef int (*randomGeneratorNext )(randomGeneratorParam*, byte*, size_t); +typedef int (*randomGeneratorCleanup)(randomGeneratorParam*); -/** \ingroup PRNG_m - * Methods and parameters for random generators. - * Each specific random generator MUST be written to be multithread safe. +/* + * The struct 'randomGenerator' holds information and pointers to code specific + * to each random generator. Each specific random generator MUST be written to + * be multithread safe. * - * @warning Each randomGenerator, when used in cryptographic applications, MUST + * WARNING: each randomGenerator, when used in cryptographic applications, MUST * be guaranteed to be of suitable quality and strength (i.e. don't use the * random() function found in most UN*X-es). * @@ -183,506 +152,406 @@ typedef int (*randomGeneratorCleanup) (randomGeneratorParam* param) * field. * */ -typedef struct -{ -/*@observer@*/ - const char* name; /*!< random generator name */ - const size_t paramsize; - const randomGeneratorSetup setup; - const randomGeneratorSeed seed; - const randomGeneratorNext next; - const randomGeneratorCleanup cleanup; -} randomGenerator; +/*!\brief This struct holds information and pointers to code specific to each + * pseudo-random number generator. + * \ingroup PRNG_m + */ #ifdef __cplusplus -extern "C" { +struct BEECRYPTAPI randomGenerator +#else +struct _randomGenerator +#endif +{ + /*!\var name + * \brief The random generator's name. + */ + const char* name; + /*!\var paramsize + * \brief The size of the random generator's parameters. + * \note The implementor should set this by using sizeof(). + */ + const size_t paramsize; + /*!\var setup + * \brief Points to the setup function. + */ + const randomGeneratorSetup setup; + /*!\var seed + * \brief Points to the seeding function. + */ + const randomGeneratorSeed seed; + /*!\var seed + * \brief Points to the function which generates the random data. + */ + const randomGeneratorNext next; + /*!\var seed + * \brief Points to the cleanup function. + */ + const randomGeneratorCleanup cleanup; +}; + +#ifndef __cplusplus +typedef struct _randomGenerator randomGenerator; #endif -/** \ingroup PRNG_m - * Return the number of generators available. - * @return number of generators available - */ -BEECRYPTAPI /*@unused@*/ -int randomGeneratorCount(void) - /*@*/; - -/** \ingroup PRNG_m - * Retrieve a generator by index. - * @param index generator index - * @return generator pointer (or NULL) +/* + * You can use the following functions to find random generators implemented by + * the library: + * + * randomGeneratorCount returns the number of generators available. + * + * randomGeneratorGet returns the random generator with a given index (starting + * at zero, up to randomGeneratorCount() - 1), or NULL if the index was out of + * bounds. + * + * randomGeneratorFind returns the random generator with the given name, or + * NULL if no random generator exists with that name. */ -BEECRYPTAPI /*@observer@*/ /*@null@*/ /*@unused@*/ -const randomGenerator* randomGeneratorGet(int index) - /*@*/; -/** \ingroup PRNG_m - * Retrieve a generator by name. - * @param name generator name - * @return generator pointer (or NULL) - */ -/*@-exportlocal@*/ -BEECRYPTAPI /*@observer@*/ /*@null@*/ -const randomGenerator* randomGeneratorFind(const char* name) - /*@*/; -/*@=exportlocal@*/ +#ifdef __cplusplus +extern "C" { +#endif -/** \ingroup PRNG_m - * Retrieve the default generator. - * If the BEECRYPT_RANDOM environment variable is set, use that - * generator. Otherwise, use "fips186prng". - * @return generator pointer - */ -BEECRYPTAPI /*@observer@*/ /*@null@*/ /*@unused@*/ -const randomGenerator* randomGeneratorDefault(void) - /*@*/; +BEECRYPTAPI +int randomGeneratorCount(void); +BEECRYPTAPI +const randomGenerator* randomGeneratorGet(int); +BEECRYPTAPI +const randomGenerator* randomGeneratorFind(const char*); +BEECRYPTAPI +const randomGenerator* randomGeneratorDefault(void); #ifdef __cplusplus } #endif -/** \ingroup PRNG_m - * A randomGenerator instance, global functions and specific parameters. +/* + * The struct 'randomGeneratorContext' is used to contain both the functional + * part (the randomGenerator), and its parameters. */ -typedef struct -{ -/*@observer@*/ /*@dependent@*/ - const randomGenerator* rng; /*!< global functions and parameters */ -/*@only@*/ - randomGeneratorParam* param; /*!< specific parameters */ -} randomGeneratorContext; #ifdef __cplusplus -extern "C" { +struct BEECRYPTAPI randomGeneratorContext +#else +struct _randomGeneratorContext +#endif +{ + const randomGenerator* rng; + randomGeneratorParam* param; + + #ifdef __cplusplus + randomGeneratorContext(); + randomGeneratorContext(const randomGenerator*); + ~randomGeneratorContext(); + #endif +}; + +#ifndef __cplusplus +typedef struct _randomGeneratorContext randomGeneratorContext; #endif -/** \ingroup PRNG_m - * Initialize a randomGenerator instance. +/* + * The following functions can be used to initialize and free a + * randomGeneratorContext. Initializing will allocate a buffer of the size + * required by the randomGenerator, freeing will deallocate that buffer. */ -BEECRYPTAPI /*@unused@*/ -int randomGeneratorContextInit(/*@special@*/ /*@null@*/ randomGeneratorContext* ctxt, /*@observer@*/ /*@dependent@*/ /*@null@*/ const randomGenerator* rng) - /*@defines ctxt->rng, ctxt->param @*/ - /*@modifies ctxt->rng, ctxt->param @*/; -/** \ingroup PRNG_m - * Destroy a randomGenerator instance. - */ -BEECRYPTAPI /*@unused@*/ -int randomGeneratorContextFree(/*@special@*/ randomGeneratorContext* ctxt) - /*@uses ctxt->rng @*/ - /*@releases ctxt->param @*/ - /*@modifies ctxt->rng, ctxt->param @*/; +#ifdef __cplusplus +extern "C" { +#endif -BEECRYPTAPI /*@unused@*/ -int randomGeneratorContextNext(randomGeneratorContext* ctxt, /*@out@*/ byte* data, size_t size) - /*@modifies ctxt->param, *data @*/; +BEECRYPTAPI +int randomGeneratorContextInit(randomGeneratorContext*, const randomGenerator*); +BEECRYPTAPI +int randomGeneratorContextFree(randomGeneratorContext*); +BEECRYPTAPI +int randomGeneratorContextNext(randomGeneratorContext*, byte*, size_t); +BEECRYPTAPI +int randomGeneratorContextSeed(randomGeneratorContext*, const byte*, size_t); #ifdef __cplusplus } #endif -/*@}*/ -/** \name Hash Functions */ -/*@{*/ +/* + * Hash Functions + */ -/** \ingroup HASH_m +/*!typedef void hashFunctionParam + * \ingroup HASH_m */ -BEECRYPTAPI typedef void hashFunctionParam; -/** \ingroup HASH_m - * Re-initialize the parameters of the hash function. - * - * @param param hash parameters - * @return 0 on success, -1 on failure - */ -typedef int (*hashFunctionReset) (hashFunctionParam* param) - /*@modifies *param @*/; +typedef int (*hashFunctionReset )(hashFunctionParam*); +typedef int (*hashFunctionUpdate)(hashFunctionParam*, const byte*, size_t); +typedef int (*hashFunctionDigest)(hashFunctionParam*, byte*); -/** \ingroup HASH_m - * Update the hash function with an array of bytes. +/* + * The struct 'hashFunction' holds information and pointers to code specific + * to each hash function. Specific hash functions MAY be written to be + * multithread-safe. * - * @param param hash parameters - * @param data array of bytes - * @param size no. of bytes - * @return 0 on success, -1 on failure + * NOTE: data MUST have a size (in bytes) of at least 'digestsize' as described + * in the hashFunction struct. + * NOTE: for safety reasons, after calling digest, each specific implementation + * MUST reset itself so that previous values in the parameters are erased. */ -typedef int (*hashFunctionUpdate) (hashFunctionParam* param, const byte* data, size_t size) - /*@modifies *param @*/; +#ifdef __cplusplus +struct BEECRYPTAPI hashFunction +#else +struct _hashFunction +#endif +{ + const char* name; + const size_t paramsize; /* in bytes */ + const size_t blocksize; /* in bytes */ + const size_t digestsize; /* in bytes */ + const hashFunctionReset reset; + const hashFunctionUpdate update; + const hashFunctionDigest digest; +}; + +#ifndef __cplusplus +typedef struct _hashFunction hashFunction; +#endif -/** \ingroup HASH_m - * Compute the digest of all the data passed to the hash function, and return - * the result in data. +/* + * You can use the following functions to find hash functions implemented by + * the library: * - * @note data must be at least have a bytesize of 'digestsize' as described - * in the hashFunction struct. + * hashFunctionCount returns the number of hash functions available. * - * @note For safety reasons, after calling digest, each specific implementation - * MUST reset itself so that previous values in the parameters are erased. + * hashFunctionGet returns the hash function with a given index (starting + * at zero, up to hashFunctionCount() - 1), or NULL if the index was out of + * bounds. * - * @param param hash parameters - * @retval data digest - * @return 0 on success, -1 on failure + * hashFunctionFind returns the hash function with the given name, or + * NULL if no hash function exists with that name. */ -typedef int (*hashFunctionDigest) (hashFunctionParam* param, /*@out@*/ byte* data) - /*@modifies *param, *data @*/; - -/** \ingroup HASH_m - * Methods and parameters for hash functions. - * Specific hash functions MAY be written to be multithread-safe. - */ -typedef struct -{ -/*@observer@*/ - const char* name; /*!< hash function name */ - const size_t paramsize; /*!< in bytes */ - const size_t blocksize; /*!< in bytes */ - const size_t digestsize; /*!< in bytes */ - const hashFunctionReset reset; - const hashFunctionUpdate update; - const hashFunctionDigest digest; -} hashFunction; #ifdef __cplusplus extern "C" { #endif -/** \ingroup HASH_m - * Return the number of hash functions available. - * @return number of hash functions available - */ -BEECRYPTAPI /*@unused@*/ -int hashFunctionCount(void) - /*@*/; - -/** \ingroup HASH_m - * Retrieve a hash function by index. - * @param index hash function index - * @return hash function pointer (or NULL) - */ -BEECRYPTAPI /*@observer@*/ /*@null@*/ /*@unused@*/ -const hashFunction* hashFunctionGet(int index) - /*@*/; - -/** \ingroup HASH_m - * Retrieve a hash function by name. - * @param name hash function name - * @return hash function pointer (or NULL) - */ -/*@-exportlocal@*/ -BEECRYPTAPI /*@observer@*/ /*@null@*/ -const hashFunction* hashFunctionFind(const char* name) - /*@*/; -/*@=exportlocal@*/ - -/** \ingroup HASH_m - * Retrieve the default hash function. - * If the BEECRYPT_HASH environment variable is set, use that - * hash function. Otherwise, use "sha1". - * @return hash function pointer (or NULL) - */ -BEECRYPTAPI /*@observer@*/ /*@null@*/ /*@unused@*/ -const hashFunction* hashFunctionDefault(void) - /*@*/; +BEECRYPTAPI +int hashFunctionCount(void); +BEECRYPTAPI +const hashFunction* hashFunctionGet(int); +BEECRYPTAPI +const hashFunction* hashFunctionFind(const char*); +BEECRYPTAPI +const hashFunction* hashFunctionDefault(void); #ifdef __cplusplus } #endif -/** \ingroup HASH_m - * A hashFunction instance, global functions and specific parameters. +/* + * The struct 'hashFunctionContext' is used to contain both the functional + * part (the hashFunction), and its parameters. */ -typedef struct +#ifdef __cplusplus +struct BEECRYPTAPI hashFunctionContext +#else +struct _hashFunctionContext +#endif { -/*@observer@*/ /*@dependent@*/ - const hashFunction* algo; /*!< global functions and parameters */ -/*@only@*/ - hashFunctionParam* param; /*!< specific parameters */ -} hashFunctionContext; + const hashFunction* algo; + hashFunctionParam* param; + + #ifdef __cplusplus + hashFunctionContext(); + hashFunctionContext(const hashFunction*); + ~hashFunctionContext(); + #endif +}; + +#ifndef __cplusplus +typedef struct _hashFunctionContext hashFunctionContext; +#endif + +/* + * The following functions can be used to initialize and free a + * hashFunctionContext. Initializing will allocate a buffer of the size + * required by the hashFunction, freeing will deallocate that buffer. + */ #ifdef __cplusplus extern "C" { #endif -/** \ingroup HASH_m - * Initialize a hashFunction instance. - */ BEECRYPTAPI -int hashFunctionContextInit(/*@special@*/ hashFunctionContext* ctxt, /*@observer@*/ /*@dependent@*/ const hashFunction* hash) - /*@defines ctxt->algo, ctxt->param @*/ - /*@modifies ctxt->algo, ctxt->param @*/; - -/** \ingroup HASH_m - * Destroy a hashFunction instance. - */ +int hashFunctionContextInit(hashFunctionContext*, const hashFunction*); BEECRYPTAPI -int hashFunctionContextFree(/*@special@*/ hashFunctionContext* ctxt) - /*@releases ctxt->param @*/ - /*@modifies ctxt->algo, ctxt->param @*/; - -/** \ingroup HASH_m - */ +int hashFunctionContextFree(hashFunctionContext*); BEECRYPTAPI -int hashFunctionContextReset(hashFunctionContext* ctxt) - /*@modifies ctxt @*/; - -/** \ingroup HASH_m - */ -BEECRYPTAPI /*@unused@*/ -int hashFunctionContextUpdate(hashFunctionContext* ctxt, const byte* data, size_t size) - /*@modifies ctxt @*/; - -/** \ingroup HASH_m - */ -BEECRYPTAPI /*@unused@*/ -int hashFunctionContextUpdateMC(hashFunctionContext* ctxt, const memchunk* m) - /*@modifies ctxt @*/; - -/** \ingroup HASH_m - */ +int hashFunctionContextReset(hashFunctionContext*); BEECRYPTAPI -int hashFunctionContextUpdateMP(hashFunctionContext* ctxt, const mpnumber* n) - /*@modifies ctxt @*/; - -/** \ingroup HASH_m - */ +int hashFunctionContextUpdate(hashFunctionContext*, const byte*, size_t); BEECRYPTAPI -int hashFunctionContextDigest(hashFunctionContext* ctxt, byte* digest) - /*@modifies ctxt, *digest @*/; - -/** \ingroup HASH_m - */ -/*@-exportlocal@*/ +int hashFunctionContextUpdateMC(hashFunctionContext*, const memchunk*); BEECRYPTAPI -int hashFunctionContextDigestMP(hashFunctionContext* ctxt, mpnumber* d) - /*@modifies ctxt, *d @*/; -/*@=exportlocal@*/ - -/** \ingroup HASH_m - */ -BEECRYPTAPI /*@unused@*/ -int hashFunctionContextDigestMatch(hashFunctionContext* ctxt, const mpnumber* d) - /*@modifies ctxt @*/; +int hashFunctionContextUpdateMP(hashFunctionContext*, const mpnumber*); +BEECRYPTAPI +int hashFunctionContextDigest(hashFunctionContext*, byte*); +BEECRYPTAPI +int hashFunctionContextDigestMP(hashFunctionContext*, mpnumber*); +BEECRYPTAPI +int hashFunctionContextDigestMatch(hashFunctionContext*, const mpnumber*); #ifdef __cplusplus } #endif -/*@}*/ -/** \name Keyed Hash Functions, a.k.a. Message Authentication Codes */ -/*@{*/ - -/** \ingroup HMAC_m +/* + * Keyed Hash Functions, a.k.a. Message Authentication Codes */ -typedef void keyedHashFunctionParam; -/** \ingroup HMAC_m - * Setup the keyed hash function parameters with the given secret key. - * This can also be used to reset the parameters. - * - * @note After use, it is recommended to wipe the parameters by calling setup - * again with another (dummy) key. - * - * @param param keyed hash parameters - * @param key secret key - * @param keybits no. bits in secret key - * @return 0 on success, -1 on failure +/*!\typedef void keyedHashFunctionParam + * \ingroup HMAC_m */ -typedef int (*keyedHashFunctionSetup) (keyedHashFunctionParam* param, const byte* key, size_t keybits) - /*@modifies *param @*/; +typedef void keyedHashFunctionParam; -/** \ingroup HMAC_m - * Re-initialize the parameters of a keyed hash function. - * - * @param param keyed hash parameters - * @return 0 on success, -1 on failure - */ -typedef int (*keyedHashFunctionReset) (keyedHashFunctionParam* param) - /*@modifies *param @*/; +typedef int (*keyedHashFunctionSetup )(keyedHashFunctionParam*, const byte*, size_t); +typedef int (*keyedHashFunctionReset )(keyedHashFunctionParam*); +typedef int (*keyedHashFunctionUpdate )(keyedHashFunctionParam*, const byte*, size_t); +typedef int (*keyedHashFunctionDigest )(keyedHashFunctionParam*, byte*); -/** \ingroup HMAC_m - * Update the keyed hash function with an array of bytes. +/* + * The struct 'keyedHashFunction' holds information and pointers to code + * specific to each keyed hash function. Specific keyed hash functions MAY be + * written to be multithread-safe. * - * @param param keyed hash parameters - * @param data array of bytes - * @param size no. of bytes - * @return 0 on success, -1 on failure + * The struct field 'keybitsmin' contains the minimum number of bits a key + * must contains, 'keybitsmax' the maximum number of bits a key may contain, + * 'keybitsinc', the increment in bits that may be used between min and max. + * + * NOTE: data must be at least have a bytesize of 'digestsize' as described + * in the keyedHashFunction struct. + * NOTE: for safety reasons, after calling digest, each specific implementation + * MUST reset itself so that previous values in the parameters are erased. */ -typedef int (*keyedHashFunctionUpdate) (keyedHashFunctionParam* param, const byte* data, size_t size) - /*@modifies *param @*/; +#ifdef __cplusplus +struct BEECRYPTAPI keyedHashFunction +#else +struct _keyedHashFunction +#endif +{ + const char* name; + const size_t paramsize; /* in bytes */ + const size_t blocksize; /* in bytes */ + const size_t digestsize; /* in bytes */ + const size_t keybitsmin; /* in bits */ + const size_t keybitsmax; /* in bits */ + const size_t keybitsinc; /* in bits */ + const keyedHashFunctionSetup setup; + const keyedHashFunctionReset reset; + const keyedHashFunctionUpdate update; + const keyedHashFunctionDigest digest; +}; + +#ifndef __cplusplus +typedef struct _keyedHashFunction keyedHashFunction; +#endif -/** \ingroup HMAC_m - * Compute the digest (or authentication code) of all the data passed to - * the keyed hash function, and return the result in data. +/* + * You can use the following functions to find keyed hash functions implemented + * by the library: * - * @note data must be at least have a bytesize of 'digestsize' as described - * in the keyedHashFunction struct. + * keyedHashFunctionCount returns the number of keyed hash functions available. * - * @note For safety reasons, after calling digest, each specific implementation - * MUST reset itself so that previous values in the parameters are erased. + * keyedHashFunctionGet returns the keyed hash function with a given index + * (starting at zero, up to keyedHashFunctionCount() - 1), or NULL if the index + * was out of bounds. * - * @param param keyed hash parameters - * @retval data digest (or authentication code) - * @return 0 on success, -1 on failure + * keyedHashFunctionFind returns the keyed hash function with the given name, + * or NULL if no keyed hash function exists with that name. */ -typedef int (*keyedHashFunctionDigest) (keyedHashFunctionParam* param, /*@out@*/ byte* data) - /*@modifies *param, *data @*/; - -/** \ingroup HMAC_m - * Methods and parameters for keyed hash functions. - * Specific keyed hash functions MAY be written to be multithread-safe. - */ -typedef struct -{ -/*@observer@*/ - const char* name; /*!< keyed hash function name */ - const size_t paramsize; /*!< in bytes */ - const size_t blocksize; /*!< in bytes */ - const size_t digestsize; /*!< in bytes */ - const size_t keybitsmin; /*!< min keysize in bits */ - const size_t keybitsmax; /*!< max keysize in bits */ - const size_t keybitsinc; /*!< keysize increment in bits */ - const keyedHashFunctionSetup setup; - const keyedHashFunctionReset reset; - const keyedHashFunctionUpdate update; - const keyedHashFunctionDigest digest; -} keyedHashFunction; #ifdef __cplusplus extern "C" { #endif -/** \ingroup HMAC_m - * Return the number of keyed hash functions available. - * @return number of keyed hash functions available - */ -BEECRYPTAPI /*@unused@*/ -int keyedHashFunctionCount(void) - /*@*/; - -/** \ingroup HMAC_m - * Retrieve a keyed hash function by index. - * @param index keyed hash function index - * @return keyed hash function pointer (or NULL) - */ -BEECRYPTAPI /*@observer@*/ /*@null@*/ /*@unused@*/ -const keyedHashFunction* keyedHashFunctionGet(int index) - /*@*/; - -/** \ingroup HMAC_m - * Retrieve a keyed hash function by name. - * @param name keyed hash function name - * @return keyed hash function pointer (or NULL) - */ -/*@-exportlocal@*/ -BEECRYPTAPI /*@observer@*/ /*@null@*/ -const keyedHashFunction* keyedHashFunctionFind(const char* name) - /*@*/; -/*@=exportlocal@*/ - -/** \ingroup HMAC_m - * Retrieve the default keyed hash function. - * If the BEECRYPT_KEYEDHASH environment variable is set, use that keyed - * hash function. Otherwise, use "hmacsha1". - * @return keyed hash function pointer - */ -BEECRYPTAPI /*@observer@*/ /*@null@*/ /*@unused@*/ -const keyedHashFunction* keyedHashFunctionDefault(void) - /*@*/; +BEECRYPTAPI +int keyedHashFunctionCount(void); +BEECRYPTAPI +const keyedHashFunction* keyedHashFunctionGet(int); +BEECRYPTAPI +const keyedHashFunction* keyedHashFunctionFind(const char*); +BEECRYPTAPI +const keyedHashFunction* keyedHashFunctionDefault(void); #ifdef __cplusplus } #endif -/** \ingroup HMAC_m - * A keyedHashFunction instance, global functions and specific parameters. +/* + * The struct 'keyedHashFunctionContext' is used to contain both the functional + * part (the keyedHashFunction), and its parameters. */ -typedef struct +#ifdef __cplusplus +struct BEECRYPTAPI keyedHashFunctionContext +#else +struct _keyedHashFunctionContext +#endif { -/*@observer@*/ /*@dependent@*/ - const keyedHashFunction* algo; /*!< global functions and parameters */ -/*@only@*/ - keyedHashFunctionParam* param; /*!< specific parameters */ -} keyedHashFunctionContext; + const keyedHashFunction* algo; + keyedHashFunctionParam* param; + + #ifdef __cplusplus + keyedHashFunctionContext(); + keyedHashFunctionContext(const keyedHashFunction*); + ~keyedHashFunctionContext(); + #endif +}; + +#ifndef __cplusplus +typedef struct _keyedHashFunctionContext keyedHashFunctionContext; +#endif + +/* + * The following functions can be used to initialize and free a + * keyedHashFunctionContext. Initializing will allocate a buffer of the size + * required by the keyedHashFunction, freeing will deallocate that buffer. + */ #ifdef __cplusplus extern "C" { #endif -/** \ingroup HMAC_m - * Initialize a keyedHashFunction instance. - */ BEECRYPTAPI -int keyedHashFunctionContextInit(/*@special@*/ keyedHashFunctionContext* ctxt, /*@observer@*/ /*@dependent@*/ const keyedHashFunction* mac) - /*@defines ctxt->algo, ctxt->param @*/ - /*@modifies ctxt->algo, ctxt->param @*/; - -/** \ingroup HMAC_m - * Destroy a keyedHashFunction instance. - */ +int keyedHashFunctionContextInit(keyedHashFunctionContext*, const keyedHashFunction*); BEECRYPTAPI -int keyedHashFunctionContextFree(/*@special@*/ keyedHashFunctionContext* ctxt) - /*@uses ctxt->algo @*/ - /*@releases ctxt->param @*/ - /*@modifies ctxt->algo, ctxt->param @*/; - -/** \ingroup HMAC_m - */ +int keyedHashFunctionContextFree(keyedHashFunctionContext*); BEECRYPTAPI -int keyedHashFunctionContextSetup(keyedHashFunctionContext* ctxt, const byte* key, size_t keybits) - /*@modifies ctxt @*/; - -/** \ingroup HMAC_m - */ -BEECRYPTAPI /*@unused@*/ -int keyedHashFunctionContextReset(keyedHashFunctionContext* ctxt) - /*@modifies ctxt @*/; - -/** \ingroup HMAC_m - */ -BEECRYPTAPI /*@unused@*/ -int keyedHashFunctionContextUpdate(keyedHashFunctionContext* ctxt, const byte* data, size_t size) - /*@modifies ctxt @*/; - -/** \ingroup HMAC_m - */ +int keyedHashFunctionContextSetup(keyedHashFunctionContext*, const byte*, size_t); BEECRYPTAPI -int keyedHashFunctionContextUpdateMC(keyedHashFunctionContext* ctxt, const memchunk* m) - /*@modifies ctxt @*/; - -/** \ingroup HMAC_m - */ -BEECRYPTAPI /*@unused@*/ -int keyedHashFunctionContextUpdateMP(keyedHashFunctionContext* ctxt, const mpnumber* n) - /*@modifies ctxt @*/; - -/** \ingroup HMAC_m - */ -BEECRYPTAPI /*@unused@*/ -int keyedHashFunctionContextDigest(keyedHashFunctionContext* ctxt, byte* digest) - /*@modifies ctxt, *digest @*/; - +int keyedHashFunctionContextReset(keyedHashFunctionContext*); BEECRYPTAPI -int keyedHashFunctionContextDigestMP(keyedHashFunctionContext* ctxt, const mpnumber* d) - /*@modifies ctxt, d @*/; - -/** \ingroup HMAC_m - */ +int keyedHashFunctionContextUpdate(keyedHashFunctionContext*, const byte*, size_t); BEECRYPTAPI -int keyedHashFunctionContextDigestMatch(keyedHashFunctionContext* ctxt, const mpnumber* d) - /*@modifies ctxt @*/; +int keyedHashFunctionContextUpdateMC(keyedHashFunctionContext*, const memchunk*); +BEECRYPTAPI +int keyedHashFunctionContextUpdateMP(keyedHashFunctionContext*, const mpnumber*); +BEECRYPTAPI +int keyedHashFunctionContextDigest(keyedHashFunctionContext*, byte*); +BEECRYPTAPI +int keyedHashFunctionContextDigestMP(keyedHashFunctionContext*, mpnumber*); +BEECRYPTAPI +int keyedHashFunctionContextDigestMatch(keyedHashFunctionContext*, const mpnumber*); #ifdef __cplusplus } #endif -/*@}*/ -/** \name Block ciphers */ -/*@{*/ - -typedef void blockCipherParam; +/* + * Block ciphers + */ -/** \ingroup BC_m - * Block cipher operations. +/*!\enum cipherOperation + * \brief Specifies whether to perform encryption or decryption. + * \ingroup BC_m */ typedef enum { @@ -691,55 +560,52 @@ typedef enum DECRYPT } cipherOperation; -/** \ingroup BC_m - * Setup the blockcipher parameters with the given secret key for either - * encryption or decryption. - * - * @note After use, it is recommended to wipe the parameters by calling setup - * again with another (dummy) key. - * - * @param param blockcipher parameters - * @param key secret key - * @param keybits no. bits in secret key - * @param cipherOperation - * @return 0 on success, -1 on failure - */ -typedef int (*blockCipherSetup) (blockCipherParam* param, const byte* key, size_t keybits, cipherOperation cipherOperation) - /*@modifies param @*/; - -/** \ingroup BC_m - * Initialize IV for blockcipher. - * @param param blockcipher parameters - * @param data iv data - * @return 0 on success, -1 on failure - */ -typedef int (*blockCipherSetIV) (blockCipherParam* param, const byte* data) - /*@modifies param @*/; - -/** \ingroup BC_m - * Encrypt/decrypt a block of data. - * @note This is raw encryption, without padding, etc. - * - * @param param blockcipher parameters - * @retval dst ciphertext block - * @param src plaintext block - * @return 0 on success, -1 on failure +/*!\typedef void blockCipherParam + * \brief Placeholder type definition for blockcipher parameters. + * \sa aesParam, blowfishParam. + * \ingroup BC_m */ -typedef int (*blockCipherRawcrypt) (blockCipherParam* param, uint32_t* dst, const uint32_t* src) - /*@modifies param, dst @*/; +typedef void blockCipherParam; -/** \ingroup BC_m - * Encrypt/decrypt multiple blocks of data. - * @note This is raw decryption, without padding, etc. - * - * @param param blockcipher parameters - * @retval dst plaintext block - * @param src ciphertext block - * @param nblocks no. of blocks - * @return 0 on success, -1 on failure - */ -typedef int (*blockCipherModcrypt) (blockCipherParam* param, uint32_t* dst, const uint32_t* src, unsigned int nblocks) - /*@modifies param, dst @*/; +/*!\brief Prototype definition for a setup function. + * \ingroup BC_m + */ +typedef int (*blockCipherSetup )(blockCipherParam*, const byte*, size_t, cipherOperation); + +/*!\typedef int (*blockCipherSetIV)(blockCipherPatam* bp, const byte* iv) + * \brief Prototype definition for an initialization vector setup function. + * \param bp The blockcipher's parameters. + * \param iv The blockciphers' IV value. + * \note iv length must be equal to the cipher's block size. + * \retval 0 on success. + * \retval -1 on failure. + * \ingroup BC_m + */ +typedef int (*blockCipherSetIV )(blockCipherParam*, const byte*); + +/*!\typedef int (*blockCipherRawcrypt)(blockCipherParam* bp, uint32_t* dst, const uint32_t* src) + * \brief Prototype for a \e raw encryption or decryption function. + * \param bp The blockcipher's parameters. + * \param dst The ciphertext address; must be aligned on 32-bit boundary. + * \param src The cleartext address; must be aligned on 32-bit boundary. + * \retval 0 on success. + * \retval -1 on failure. + * \ingroup BC_m + */ +typedef int (*blockCipherRawcrypt)(blockCipherParam*, uint32_t*, const uint32_t*); + +/*!\typedef int (*blockCipherModcrypt)(blockCipherParam* bp, uint32_t* dst, const uint32_t* src, unsigned int nblocks) + * \brief Prototype for a \e encryption or decryption function which operates + * on multiple blocks in a certain mode. + * \param bp The blockcipher's parameters. + * \param dst The ciphertext address; must be aligned on 32-bit boundary. + * \param src The cleartext address; must be aligned on 32-bit boundary. + * \param nblocks The number of blocks to process. + * \retval 0 on success. + * \retval -1 on failure. + * \ingroup BC_m + */ +typedef int (*blockCipherModcrypt)(blockCipherParam*, uint32_t*, const uint32_t*, unsigned int); typedef uint32_t* (*blockCipherFeedback)(blockCipherParam*); @@ -755,132 +621,177 @@ typedef struct const blockCipherModcrypt decrypt; } blockCipherMode; -/** \ingroup BC_m - * Methods and parameters for block ciphers. - * Specific block ciphers MAY be written to be multithread-safe. +/*!\brief Holds information and pointers to code specific to each cipher. + * + * Specific block ciphers \e may be written to be multithread-safe. + * + * \ingroup BC_m */ -typedef struct +#ifdef __cplusplus +struct BEECRYPTAPI blockCipher +#else +struct _blockCipher +#endif { -/*@observer@*/ - const char* name; /*!< block cipher name */ - const size_t paramsize; /*!< in bytes */ - const size_t blocksize; /*!< in bytes */ - const size_t keybitsmin; /*!< min keysize in bits */ - const size_t keybitsmax; /*!< max keysize in bits */ - const size_t keybitsinc; /*!< keysize increment in bits */ - const blockCipherSetup setup; - const blockCipherSetIV setiv; - const blockCipherRaw raw; - const blockCipherMode ecb; - const blockCipherMode cbc; - const blockCipherFeedback getfb; -} blockCipher; + /*!\var name + * \brief The blockcipher's name. + */ + const char* name; + /*!\var paramsize + * \brief The size of the parameters required by this cipher, in bytes. + */ + const size_t paramsize; + /*!\var blocksize + * \brief The size of one block of data, in bytes. + */ + const size_t blocksize; + /*!\var keybitsmin + * \brief The minimum number of key bits. + */ + const size_t keybitsmin; + /*!\var keybitsmax + * \brief The maximum number of key bits. + */ + const size_t keybitsmax; + /*!\var keybitsinc + * \brief The allowed increment in key bits between min and max. + * \see keybitsmin and keybitsmax. + */ + const size_t keybitsinc; + /*!\var setup + * \brief Pointer to the cipher's setup function. + */ + const blockCipherSetup setup; + /*!\var setiv + * \brief Pointer to the cipher's initialization vector setup function. + */ + const blockCipherSetIV setiv; + /*!\var raw + * \brief The cipher's raw functions. + */ + const blockCipherRaw raw; + /*!\var ecb + * \brief The cipher's ECB functions. + */ + const blockCipherMode ecb; + const blockCipherMode cbc; + /*!\var getfb + * \brief Pointer to the cipher's feedback-returning function. + */ + const blockCipherFeedback getfb; +}; + +#ifndef __cplusplus +typedef struct _blockCipher blockCipher; +#endif + #ifdef __cplusplus extern "C" { #endif -/** \ingroup BC_m - * Return the number of blockciphers available. - * @return number of blockciphers available +/*!\fn int blockCipherCount() + * \brief This function returns the number of blockciphers implemented + * by the library. + * \return The number of implemented blockciphers. */ -BEECRYPTAPI /*@unused@*/ -int blockCipherCount(void) - /*@*/; +BEECRYPTAPI +int blockCipherCount(void); -/** \ingroup BC_m - * Retrieve a blockcipher by index. - * @param index blockcipher index - * @return blockcipher pointer (or NULL) +/*!\fn const blockCipher* blockCipherGet(int n) + * \brief This function returns the \a n -th blockcipher implemented by + * the library. + * \param n Index of the requested blockcipher; legal values are 0 + * through blockCipherCount() - 1. + * \return A pointer to a blockcipher or null, if the index was out of + * range. */ -BEECRYPTAPI /*@observer@*/ /*@null@*/ /*@unused@*/ -const blockCipher* blockCipherGet(int index) - /*@*/; +BEECRYPTAPI +const blockCipher* blockCipherGet(int); -/** \ingroup BC_m - * Retrieve a blockcipher by name. - * @param name blockcipher name - * @return blockcipher pointer (or NULL) +/*!\fn const blockCIiher* blockCipherFind(const char* name) + * \brief This function returns the blockcipher specified by the given name. + * \param name Name of the requested blockcipher. + * \return A pointer to a blockcipher or null, if the name wasn't found. */ -/*@-exportlocal@*/ -BEECRYPTAPI /*@observer@*/ /*@null@*/ -const blockCipher* blockCipherFind(const char* name) - /*@*/; -/*@=exportlocal@*/ +BEECRYPTAPI +const blockCipher* blockCipherFind(const char*); -/** \ingroup BC_m - * Retrieve the default blockcipher. - * If the BEECRYPT_CIPHER environment variable is set, use that blockcipher. - * Otherwise, use "blowfish". - * @return blockcipher pointer +/*!\fn const blockCipher* blockCipherDefault() + * \brief This functions returns the default blockcipher; the default value + * can be specified by setting environment variable BEECRYPT_CIPHER. + * \return A pointer to a blockcipher or null, in case an error occured. */ -BEECRYPTAPI /*@observer@*/ /*@null@*/ /*@unused@*/ -const blockCipher* blockCipherDefault(void) - /*@*/; +BEECRYPTAPI +const blockCipher* blockCipherDefault(void); #ifdef __cplusplus } #endif -/** \ingroup BC_m - * A blockCipher instance, global functions and specific parameters. +/*!\brief Holds a pointer to a blockcipher as well as its parameters. + * \warning A context can be used by only one thread at the same time. + * \ingroup BC_m */ -typedef struct +#ifdef __cplusplus +struct BEECRYPTAPI blockCipherContext +#else +struct _blockCipherContext +#endif { -/*@observer@*/ /*@dependent@*/ - const blockCipher* algo; /*!< global functions and parameters */ -/*@only@*/ - blockCipherParam* param; /*!< specific parameters */ - cipherOperation op; -} blockCipherContext; + /*!\var algo + * \brief Pointer to a blockCipher. + */ + const blockCipher* algo; + /*!\var param + * \brief Pointer to the parameters used by algo. + */ + blockCipherParam* param; + /*!\var op + */ + cipherOperation op; + + #ifdef __cplusplus + blockCipherContext(); + blockCipherContext(const blockCipher*); + ~blockCipherContext(); + #endif +}; + +#ifndef __cplusplus +typedef struct _blockCipherContext blockCipherContext; +#endif + +/* + * The following functions can be used to initialize and free a + * blockCipherContext. Initializing will allocate a buffer of the size + * required by the blockCipher, freeing will deallocate that buffer. + */ #ifdef __cplusplus extern "C" { #endif -/** \ingroup BC_m - * Initialize a blockCipher instance. - */ BEECRYPTAPI -int blockCipherContextInit(/*@special@*/ blockCipherContext* ctxt, /*@observer@*/ /*@dependent@*/ const blockCipher* ciph) - /*@defines ctxt->algo, ctxt->param, ctxt->op @*/ - /*@modifies ctxt->algo, ctxt->param, ctxt->op @*/; +int blockCipherContextInit(blockCipherContext*, const blockCipher*); -/** \ingroup BC_m - */ BEECRYPTAPI -int blockCipherContextSetup(blockCipherContext* ctxt, const byte* key, size_t keybits, cipherOperation op) - /*@modifies ctxt @*/; +int blockCipherContextSetup(blockCipherContext*, const byte*, size_t, cipherOperation); -/** \ingroup BC_m - */ -BEECRYPTAPI /*@unused@*/ -int blockCipherContextSetIV(blockCipherContext* ctxt, const byte* iv) - /*@modifies ctxt @*/; +BEECRYPTAPI +int blockCipherContextSetIV(blockCipherContext*, const byte*); -/** \ingroup BC_m - * Destroy a blockCipher instance. - */ BEECRYPTAPI -int blockCipherContextFree(/*@special@*/ blockCipherContext* ctxt) - /*@releases ctxt->param @*/ - /*@modifies ctxt->algo, ctxt->param @*/; +int blockCipherContextFree(blockCipherContext*); -/** \ingroup BC_m - */ -BEECRYPTAPI /*@unused@*/ -int blockCipherContextECB(blockCipherContext* ctxt, uint32_t* dst, const uint32_t* src, size_t nblocks) - /*@modifies ctxt->param, dst @*/; +BEECRYPTAPI +int blockCipherContextECB(blockCipherContext*, uint32_t*, const uint32_t*, int); -/** \ingroup BC_m - */ -BEECRYPTAPI /*@unused@*/ -int blockCipherContextCBC(blockCipherContext* ctxt, uint32_t* dst, const uint32_t* src, size_t nblocks) - /*@modifies ctxt->param, dst @*/; +BEECRYPTAPI +int blockCipherContextCBC(blockCipherContext*, uint32_t*, const uint32_t*, int); #ifdef __cplusplus } #endif -/*@}*/ #endif diff --git a/beecrypt/beecrypt.mcp b/beecrypt/beecrypt.mcp deleted file mode 100644 index ca09a5a1f6aba39efdc0b0775bdfdf053d375e5a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 60170 zcmeI531C#!xyNrNBPfa>2Grm(2nY`}$SQ&hAqfyjAcnAr8_8q{fk`ILBrLAD)M9Jv zQv0-ZskQE1T;e9bJjAvXNGjWbFz62kfPr8aurt^P><;z> z`+~he1dIT~Kp7YbJ|?M6U?=#lV0%ywb^tqqeqa!2K<5b12o{2BFdNJPwV(-9ffK;od;Ku``+APM#YJzx}A3r2w9U?h;sLELT_*cTiPjseGl#~Dk&Qg9?# z2D-pe;COH-mdz#qY{!SBFx;Cb*A zcmcc!&I9Ly_rW*7x4;*`MsO+k4)`iK6MPAr4ZaAz1}+32fd2*;fs4V{!TI0Q-$d=p#-t^k*VE5Sd(S>S5$5%>yt1pFLa0=^CYQ$acd4W^Ho=iR9#7Kvo8Yz^C%ou+EEF*v35LvrLV9<$QaldOC@@e(O5$=wxWGq#mb7z z42brCxy@^utK!Y6R4i4osyS&NZ*P~?Hbm-|ENd|L?IzofwDV$S*39yrL=6LNV0*9& zI1?T4*vyKfE|IDstc?J$Ad+n7R&|nKpj{P z>cK!T1@r|2!0uoVa1iJZ27%qcu3$bW0Xu^b*a7SXhJqu&K43dA8dQKd=m4Ey0Z4#V zU@F)b91Es_DA);%2a~~ppbQKKL%`l(F&GC*!NFh@h=GY<5*P#a2YtZi1SyY{MbZ_! zN&Y1bv4{AF_=S{H>@K#Ie2QJfPGSeKnb=T#M{Ff_a_3!qLF^|s6+213_XA=hv7MAn z>=psTfY@a?5dRqoq+X?LV}X?K03f#gw1IPnDO;Gbg=Yi&H{1ZQbC@!QDPx%Og(+W{ z@`Wj1nEZt)UzoZMQ^qj$6UMi~O<*Cwhr{#10zkcm8v$hxW2-QB2vh#>T!0UT>p(rg z&SCr^j30!l*D&=Erar>dg$((^)I~S~YJi+eV3%F$M(WQBc9SD}QllaBuN9a3FXtgh zyFhB1jLlW*I*;WOndhyFRM*uRv)YrX?#RMeTSu(3+i0#xFs80w5~&(jHFj)d-P9?v zv!uPVvC5FYu~ekCqbrf@HtO12l$u%#T2{Gtt#mm2IF6b)LC#bWHR>1EMXD-V<8h0b z=dbKcwMS8`h_|;G^=qTa?zl;3x3*85V6u6!WM?d{JBw1Wq|%JkoOBCeOCk-;sc3WD zDx%~|aucbJwe+;vxf5=tRXKlQZPn7LQ>rWKYG)c9srb>JT#LY!bF0J)tLGiA8uJsKF{7#{)t%^w%!{pGn@F~%jLK*@s959 z_Rh8x&JvGB>YKZ|%suOrHS4;Q%_+mQTw5#|v5s-}8+$st+dE>0oLFwTXU94XwS85h zql*-iMr~tcK^I!>C$Qtnq2+~XHHoqB)U7D)-#g8`Xo~553fox4`Sb)<*{wRZZRnO+ z^**bqfr8^~W*%zRMPpTd4n;(AFBaG>!-bae;j6LCDTc13$?rHdvQ1x1b4c&i-N8eeT~ zx>lQesWq)#2egWMEZ)}K(Hs}n+1lRR*-2HKJKf1d*Lv8B_O8_UsRyRn6xhm+<|vzv zF0MOk)522|TtfFcdpcTTN!_tBBD!5kN+Qzku4HE$B(<`6yr$KH4^NqdOnp^sk}hl) zBf0dBCx(_o66}ap)Nufo@8~dF2wE;P|1HhY)jb}=C8I`Vsv~0h-hx@P(x#JacC1~U zs%W1~)6<;laL(8oTVb2QDva7hcGBA2)RA?V)`cflif;-g+KER~>pK~wQZQvvqkC;a zD{*ElRwd(D&lN6Nu5M4sz|nGyRSYEC;yq&0%Id|H4YgEsos(cM%`yYHqb` zJz??`yXIOaD@&%DiR7>8AZ$$!p<+-L%eGFIzcI$rJ)Pn^a#%W6cgCySQf^(@%)mC9 zySFOFZjBa@@uQ3l?d_ABTCp}i~E zIHH~9RnG7<_`qUJ9t#|I9AgJY=UXn6nD?XUdlSuw+?y6drUlGP%Dl3;Z#DhjeMgw7 z?b^50c;z5>jp?v?w~+3qS;gu}8*!T@HMI-tcd6~{mb>llNX@#gcp}OD$YzC4dH80X ztEjvcTA;5!jQZ4_`4;cU+$Er$4)G4r+P$tl#Y0Z}pcn`f)scIu))8k^Z)QZg zik%2gHD`#msxzciw-Ks2X9o?Dcx@2 zsH$r?g3PClSuxpmwjKlrdxpmQ`-esbdWpsd_=?8*dyGZ~`Hd$!uvCHe(8DvIrKatr z@%}#Oj?DB#cbwZFRUYJ(8tw0!8tLnyuDDF6aYbc$tH$~JtVa5Jt}D*pe_aXz8S?dI zJuK6sBl;{khkx1{0Ul~c2m7e45#*(Ie1M#u%rDQ#2uSe zBkss-C$VD#+{BLdcNBMQfUCGw0<-4tF7~17Fjn30PAJP!oEVRTIO0slaALd;;m9qf zZ-X3hh67|qq$}Qu$f$59!c)S1sanq~v@6t+dMeTpyDQKu^;DcUD(jT)igHu~ zujt^m*{<8*);X=g8w{t-PD>l)eVFzB%|F&tEPs_ie{3Li+p^A~=4-WS4W9g{%r`eq zTtHqNg{+)7QFcBYb7xvLE5^qSCD$%JSAM-xPfop2SEopBTH0PE>a3oH(akjx4i8-WaDW8FH=k45?k&j@T};N8%Kg4uDTa%v-^LBH6y@rKE%79r!6^I(3kaga*-w#)k|h`qF9@Qao@ z&k-%PnIk%5v=wxM23pvFxZIbado&Y}K)UDfiIkySkk;^PW2{7SwlI#0U;ARk z2DL6$tWVowMdWN*9F^en=5AH26mqpGmWF?eV#NivCsuT>*2K~9Z%bV9J}rqW*6&iW zq61nHD>9%Bu_6On5GyiA`{5*=*?Od7{M!yII;iDHAMD#MSg}E^h7}vwW?0cVS`0n6 z^&zNln__9?Xf5nvtz?07Xg)>uZ#*=Sz}7?Kb6jX14PUQx zWz?^QbVcWMNta&WkYbux!><|AgRx6cN2(ff;pfPuPZ!}jFwf|7T0k@CN+CzybN3;d zMqulr@zU1jC|=GE)|EtX1(1S&yXrbRMqj^@r*8AHcBLtslstd%nK_6% zwSfwZ&$<|VH8Z*kU!CkLCQ!}Y?gT11El;qD{p8B$OML4y3cL03O~Tzr1}Zq$ov%t` ztRvAKvtIc5dsbyncjAC<^A|b(3cl^2@5$VKvaf=)M>(BGyKUct#T=fF+gD5SkY7tO zl3z>G%H^PvO0M|qk$`WOB^l{UgCd=NI!GhCbMe)b^5pb5GbcJ{iEj#?Varzdp;$3X zMGJgJEg)Y8c7m|$7q(%(#FpQ^@566sKKT2lO`p-C6|?;*Ex_~=`X&FTOz5+Hxck!h zq$MfM{)x~hO^V~Pes1(B()z3)Dh*gEj_ORHB0tIZ3o}f^nYQE4C$pjRBNy*a#y+2) ziu+j+nfLcS{T4OUR&<%u#`x=7AD{CpAJ6Z5ioeqFvzAO_B2&M}lo*qNOm#97i0Nb+ z5|PVPB=S?&{eeu2B2$t`dDkeXjPpu%C^=D@-E@%i^lp#@|9@u}mA)aLojrCWOEWm;{$8*r z$>aX|*Q z7`9~#tnBXYnl^6SD&Fl@ql6wNN<61YqxDecB>{9#f>lRpfX$t6Yp3V&q6N#P&zM<$#UK8Su^ zCbJYi1}+m%3a^CA1eC&;!DS*!;VF1T`Iq3slwSegSNSdQ;mUswAEEsB@R7;r|VnJ5J%(!sV`0!cXA# zh4DOG?m{Je1eZHd3A=OKIl-dFRQN>Yi{WxtDj@}zJ6{PGz~!z~!p(5GGnVi;oJlLq z@D5z=U?uF#aD<60%`gT&UHMG7OcpDl87_Ci5>A23U9g02!tLSNZSWbUlyku=mH!n! zQ+YpbkE@iAg;y(|1+P)w0-vRPJ$$zEOW<>q-vzH#{sNo{I?eDgoQXQkFqF%)PWd5l zChj!DG4T1yPk}S>rx`ATHz>aw&V-?6cm~d-pl0|0Zg+cwxs6~FQ8P@0FH*i3zF2t* zzC`)?aC-oE1N=ypKL}r@{CW6M%HM~}WV#aiGc=c%3lc`akF}_ADEv6(i{Z z&w{rozZ4!-elxsP`NQy-^54N%D1Q&$rhEX8O;#!&0dH464ZceGJoswm9q_pFbKxDz zuZG*Vzz@I^Dt`@b&lpv@qcsVzL=A)6laNe?r&Rw4xIN8L65gZoufW$RzaG9;`2+BE z%3p-9SNw6?}neJ{HyTum0u6PK>0)PuPJ{PexdSr;a^w2;{a>caoHUPzewd%;TJ2P z3;%}lX81Rie*u1p@@wFiDt{Dynew;bmn-i-(3%xpcE`i7Q2Ao`x0Rm=zf$=n@b4(U z8-A7Y-@>m}{t^5d-PlyASQHDkW)j)vc%@;UH3mAAux zr2HKCUCM8Q->v*f_&v(shyPf4S(!CszwAzd->34$@cWhbz<;9rBKZF(zYG3=@)zL` zD*p)nkn%kSTQmC0?gaS5DqjSDM0pDSGvyb-A65P%_|KI;1^WC|?eLR{1IL z=agRte_r{$@E4T741ZC1$?n#Q0kS&={*ua%fWNG~3;v4oZ@_=A{C@Z!l)nUjRe5L+ zYc&Gd-536v%4^`SD_;Tslk&6RZz#VW{%7UCguki$efV3-2bEhZA;|6o_+M4t1pk}z zHSo8Ue;xjg@*l(huKaoUyUPCse^2?IL#^whTW^ z9cf4DN=*JSTe<))1ejTx50X(G%JhjVG0;S6|0 z`Ni;I%5Q+<_GY*Tj=P%SF*xpLhG*a-mHz?0pYm7XVn+#Y!$(`xU~)F|eq46@z{jY3 z2z;#a;qd*HPlO+!T%IRXD4!1>r~FvB)RTk+e7r>sdH*m$`Iq4nm0t{>r2ISZ$;#!K z!xZKB!VgmZOZZgfFTxL2{uX?ia(T5pUHKsRA}Blv9P55ngte*#{s{8{*1e7W*R;myjQhqowy9UfKw9=uh# zJd=qj9|~Wgd^EgG`62L?%4^{5%9p`cDPIj=t-J>wSAHtIL;2b8PUV-w6UuLdcPYOM ze!TLB;YsE4oF}FH1$ejeH{ds3AoeuDDd;U_8|4nIlx zf$)=+PlunPyas-%@-4O5iPlyA;nso~8K3ZMscaR`yA@b~F3Z@oY17|m;u#~z-(o0Q zz#5O?7n|@8x&2Eoaz(!$t^$nxaxQK~f1Y04sv157FjmM~$ZAhyj5WiIK?+{LO2&>d zmXR?h=P|uj##c1uoBdUtjD6%d8B39m&HlP>YqJewp)g~hFk_#rMZy@<(4$*HuKV8n zrer&#x^DK;=<4=X`Hj$$g$-35(KYe{Y%^LFsfW+PS16VRv;U@zYe$KZi{VpRV2jVX z&B$p7%8<`9^A*$c{gge-&v#Icc;~AqxwH6Be1}&2`pT(}ZT;)3&(AL_Kx!v znacwG;MS}W@*8jcMYSuwNQ)Nuyj#HU=k}lXGP}!He4^#HMv;ejmt{`blA}8qVAM4< zRQ7_cmdCrgdL^CJ=PcmSO76hQ*HW;YN~u)5SJGLLTs601RdPknljV;bSY5TmezlTc zJ6L0RRpUbYHA}Eo{+Q)WOKX}cR(5yT?;i3W;;&(*Bj1|)N1M_@>MPPvYrozJOsRl$ zX3Xkp?~Qbfo@l~;?Gu=v0wR`2lPUYPOabbFD$6CNA{uAe;XoZ(5kBvAVWyLF5l~s2 zJbya*Mw`1Dre`#>g0qIx`(89;*DRB$@7 z$Tpz_tl+z&QnpehvM*mT$hS!Hw%9EbJ&6}cuv!+22mLJ|KLgEla+b>URGkSixZ+J~UG@uI-&~PSKKoetVLkR-fpp9n;&SPjW=5K!V8x0=i~aK6S7|}Zs>0Ig z1^ZZYqPb>P%gE8tt!_*=v#vhx*vC~96fL7jx;v|`p;yxBt+7~S?#u=LId!D<4NGj# z2rO4iqR#YI=crG_dUtG?=lV;xP=Te|%pNyyI=M4ccz$wsDVvc_&V&k1C$=tUI)!+G z+4AP>m&_i{8c77(c{6+5DO2rlm@@OYc|C5vbPDWogUhvfJ#OA~3hi+N%Vp&!6|+AX z%QRoX`&-*RN=tlY&fZ@N#x$Mz+rysjUP(vJ*J~pQ?&ET|KytR6Vfp+7b6e*KB}TF# ze@~es0Xu4jHAZmFu4>2Vw(PS$MxbaJMbh2P93up#(_3SNUVUDZ#{tuQPGG4vvro>O zPVNj9o}b)Z;AW(gGogah`A_%B!FJX@xxhX!IGxSw19PPF8SirfOV+Y^eNJFH(hT)R zpW~YO+P9(Wv(>fWz1q^{d1lHi+P+qC3w!IyYayc=_j!YO@w?(6%M|5B3luF7WPy(- z%5V0b*yXD`jVb-<@G+(QRwvfJ<_VgUJ4^O;PyVF|$QSGK3&QSPD`EqDww7YpM>6Vm;M1G02uBFZV(a?1zOZ6Ai^5vEJI)<&BfsH3PXYh#G zxq>+~`dF*7%E{#v@`JE-_WOcN{o;Pn0!0hBEx;V9=EYLHV%%0K@}dQb7T6XoV2?w# z#j+R6Y+1nl%b%i6iWc~!7ATIXKB?u3$9-NbAlE>N`AuKbf(7ZXi^GkHL^m^c7!8XW z`9-z$fnOhMA=}~X*3{L`l3#wymZt;emfwh)TlodH$mN&vvTe}qV%^Fw=SALMw>#^W zZwyWOK;7~ycXNN3Zgu)(PpY51i`9;3$Q)qL$ zn{Ii2V(ypgmf4of{kgj310{2xZz0VspCy^wzHDuC$@AVp^$Y7FmGc+Y@|&!dWOK4T zX8s&pPD!+R2+v*8hro?ptuJdAR?EtndW`%$PmbZUOY<1^%`LTKZX>#_(Jhk}neu76 zoyzv`3rhALd_l>^l2zgG#mrGT`3qG0Eu$BQEIDT|gIF9Z86om#`Gx$=4pI};YF<65 zA!;kHp46bYUcU26jZv$4^`s`{F;l+uq^9wjyn5mZ@?0eXCXAMPnY zPg=Y+1?WkOxV8X2X))IopeHS=%srLQe$t|!P=FpP#Za`sHg5r|PcO_2{w+~q#}>7U z7WjNvU~8M*Y7k~+v|`TqHI^;+Q09!Na<$4kUwNZ@0AK)b&Y;T8f;oGt+{%psvYia% zxJf{M%QZ!}jQY%(z!UbH~b0!0fHEl{*T(E>#a6fID+K+ytQ*aF@bV#J<1i0>^Xkbfzxo37uyOGP6?V!Dz5Rk}OTBp7QZJMWeNnWf zUhI5cUc~V7F)WLRkz7AusOa75}ON&MTh`oK%1wFPFn77of+>rxmqODkRF6{@L(u|T%mR#aiowSMTia^~#+cz;uM~n_4Sdp94f0yT6a0tC z9+l!wJ_~#v7m~PNzPI|6A>ZfZz5imXxR8WXW!w5f63Zjlf>)NwZfCkwvChfI@P`}d zc!vB*X^43+(U~Eag>dD~XM3hx9-Pq8O8S3tJvKQxj+_SKXm^RF_A8`5YD}MILYK_Q)F}<|2H?ideF1kA8CuKI$~XBIG;5ME>e?v&}_O zCE~K%_(M9~sk(+fbDGi%q)y~(%UU`L(SLYZlMxYRLicXgt8bCN99fiJPf*|JJGT^g@kod=Y8O&;3h0z1ZS8=t>pD z-%|HOF6kfl@SM;Cdc=ju%T(Soq&D=R%CEr=&uM-h>{}c9smf1xrPKY&oY2E6zsZ%( zduP{%9#Q#A$XnoY-ecdM6Z)CTW${+qp09nmHuR{*7U9mS|Had4Lr<&xTije- zr}}-bnGHK^e@=2HuRjzpCApp-tUjphF(y)EFc?!$5Y)MQvY^1?AI(J z&x5#lmskD*mGUu4sSNpg(vfG1?HTfCaQ<77C*t08%E*jek7w4G8`tQG|Hv1Tc0Dd> zDL1ZC`4c#g?GG<(EH|!J`3maYw*QE;%8eUUejhjFw%xurV5lLNn}kELTMJvU&zBA< zH?B3MhVc+L$hO^fd9U2KQ{@}*e>LZCOSnO{>+#aj<;Lx*U$w#Ulb_t9cztZ%g@SCo{ zKj~jY{`+KUdV%;8c_w#qe${M(DypH2D`H2umuLg|I#fCtMgDrKG`+xm zHU9H2+6Ysha@mXB-+Uj}ujZ%mma_E1_jhw%+{DzM@?4oQR{iHbmmQ`*T4wC8@=Gy} zZRdk`A8Z_;@>gB*6YnWADpX!U!)UiZgRd3iykR6CaC-y$ZdbP>7z1ZqROvDZnqmZUQ%XEQu+DoD65|Luvf~A$toZ6 zoYOv>{#uzaMdklMze4p_yjW%&r1InEJAShNrZQuy%D4ZW(@w6rw9GhIkq+0e)YsTwml@Ml{(oMDx`F@z diff --git a/beecrypt/beecrypt.rc b/beecrypt/beecrypt.rc index 47fb46c..27d63d0 100644 --- a/beecrypt/beecrypt.rc +++ b/beecrypt/beecrypt.rc @@ -1,8 +1,8 @@ #include 1 VERSIONINFO - FILEVERSION 3,0,0,0 - PRODUCTVERSION 3,0,0,0 + FILEVERSION 3,1,0,0 + PRODUCTVERSION 3,1,0,0 FILEFLAGSMASK VS_FFI_FILEFLAGSMASK FILEFLAGS 0x0L FILEOS VOS__WINDOWS32 @@ -15,13 +15,13 @@ BEGIN BEGIN VALUE "CompanyName", "Virtual Unlimited B.V.\0" VALUE "FileDescription", "BeeCrypt Cryptography Library\0" - VALUE "FileVersion", "3.0.0\0" + VALUE "FileVersion", "3.1.0\0" VALUE "InternalName", "beecrypt\0" VALUE "LegalCopyright", "Copyright (c) 1997-2003 Virtual Unlimited B.V.\0" VALUE "LegalTradeMarks", "BeeCrypt is a trademark of Virtual Unlimited B.V.\0" VALUE "OriginalFileName", "BEECRYPT.DLL\0" VALUE "ProductName", "BeeCrypt\0" - VALUE "ProductVersion", "3.0.0\0" + VALUE "ProductVersion", "3.1.0\0" END END BLOCK "VarFileInfo" diff --git a/beecrypt/beecrypt.spec.in b/beecrypt/beecrypt.spec.in deleted file mode 100644 index 4b77336..0000000 --- a/beecrypt/beecrypt.spec.in +++ /dev/null @@ -1,63 +0,0 @@ -Summary: The BeeCrypt Cryptography Library -Name: beecrypt -Version: 2.2.0 -Release: 1 -Copyright: LGPL -Group: Development/Libraries -Source0: http://beecrypt.virtualunlimited.com/download/beecrypt-%{version}.tar.gz -URL: http://beecrypt.virtualunlimited.com/ -Buildroot: %{_tmppath}/%{name}-root - -%description -The BeeCrypt Cryptography Library. - -%package devel -Summary: The BeeCrypt Cryptography Library headers -Group: Development/Libraries -Requires: beecrypt = %{version} - -%description devel -The BeeCrypt Cryptography Library headers. - -%prep -%setup -q - -%build -%configure --enable-static -make -make apidocs - -%install -rm -rf ${RPM_BUILD_ROOT} -make DESTDIR="${RPM_BUILD_ROOT}" install - -%clean -rm -rf ${RPM_BUILD_ROOT} - -%post -p /sbin/ldconfig - -%postun -p /sbin/ldconfig - -%files -%defattr(-,root,root) -%doc BENCHMARKS NEWS README* -%{_libdir}/libbeecrypt.so.@VERSION@ - -%files devel -%defattr(-,root,root) -%doc BUGS ChangeLog apidocs/* -%{_libdir}/libbeecrypt.so.2 -%{_libdir}/libbeecrypt.so -%{_libdir}/libbeecrypt.la -%{_libdir}/libbeecrypt.a -%{_includedir}/beecrypt - -%changelog -* Mon Oct 8 2001 Jeff Johnson -- upgrade to 2.2.0pre. - -* Mon Sep 24 2001 Jeff Johnsopn -- add static libraries. - -* Tue Sep 18 2001 Jeff Johnson -- repackage. diff --git a/beecrypt/blockmode.c b/beecrypt/blockmode.c index 90b3825..6a19ed5 100644 --- a/beecrypt/blockmode.c +++ b/beecrypt/blockmode.c @@ -23,14 +23,13 @@ * \ingroup BC_m */ -#include "system.h" -#include "blockmode.h" -#include "mp.h" -#include "debug.h" +#define BEECRYPT_DLL_EXPORT -/*!\addtogroup BC_m - * \{ - */ +#if HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/blockmode.h" int blockEncryptECB(const blockCipher* bc, blockCipherParam* bp, uint32_t* dst, const uint32_t* src, unsigned int nblocks) { @@ -38,9 +37,7 @@ int blockEncryptECB(const blockCipher* bc, blockCipherParam* bp, uint32_t* dst, while (nblocks > 0) { -/*@-noeffectuncon@*/ - (void) bc->raw.encrypt(bp, dst, src); -/*@=noeffectuncon@*/ + bc->raw.encrypt(bp, dst, src); dst += blockwords; src += blockwords; @@ -57,9 +54,7 @@ int blockDecryptECB(const blockCipher* bc, blockCipherParam* bp, uint32_t* dst, while (nblocks > 0) { -/*@-noeffectuncon@*/ - (void) bc->raw.decrypt(bp, dst, src); -/*@=noeffectuncon@*/ + bc->raw.decrypt(bp, dst, src); dst += blockwords; src += blockwords; @@ -82,24 +77,20 @@ int blockEncryptCBC(const blockCipher* bc, blockCipherParam* bp, uint32_t* dst, for (i = 0; i < blockwords; i++) dst[i] = src[i] ^ fdback[i]; -/*@-noeffectuncon@*/ - (void) bc->raw.encrypt(bp, dst, dst); -/*@=noeffectuncon@*/ + bc->raw.encrypt(bp, dst, dst); src += blockwords; nblocks--; -/*@-usedef@*/ /* LCL: dst is initialized. */ while (nblocks > 0) { for (i = 0; i < blockwords; i++) dst[i+blockwords] = src[i] ^ dst[i]; + dst += blockwords; -/*@-noeffectuncon@*/ - (void) bc->raw.encrypt(bp, dst, dst); -/*@=noeffectuncon@*/ + bc->raw.encrypt(bp, dst, dst); src += blockwords; @@ -110,7 +101,6 @@ int blockEncryptCBC(const blockCipher* bc, blockCipherParam* bp, uint32_t* dst, for (i = 0; i < blockwords; i++) fdback[i] = dst[i]; -/*@=usedef@*/ } return 0; @@ -120,7 +110,7 @@ int blockDecryptCBC(const blockCipher* bc, blockCipherParam* bp, uint32_t* dst, { register const unsigned int blockwords = bc->blocksize >> 2; register uint32_t* fdback = bc->getfb(bp); - register uint32_t* buf = (uint32_t*) malloc(blockwords * sizeof(*buf)); + register uint32_t* buf = (uint32_t*) malloc(blockwords * sizeof(uint32_t)); if (buf) { @@ -129,16 +119,12 @@ int blockDecryptCBC(const blockCipher* bc, blockCipherParam* bp, uint32_t* dst, register uint32_t tmp; register unsigned int i; -/*@-noeffectuncon@*/ - (void) bc->raw.decrypt(bp, buf, src); -/*@=noeffectuncon@*/ + bc->raw.decrypt(bp, buf, src); for (i = 0; i < blockwords; i++) { tmp = src[i]; -/*@-usedef@*/ /* LCL: buf is initialized. */ dst[i] = buf[i] ^ fdback[i]; -/*@-usedef@*/ fdback[i] = tmp; } @@ -153,6 +139,3 @@ int blockDecryptCBC(const blockCipher* bc, blockCipherParam* bp, uint32_t* dst, return -1; } - -/*!\} - */ diff --git a/beecrypt/blockmode.h b/beecrypt/blockmode.h index 8a67e07..4f21b81 100644 --- a/beecrypt/blockmode.h +++ b/beecrypt/blockmode.h @@ -27,63 +27,63 @@ #ifndef _BLOCKMODE_H #define _BLOCKMODE_H -#include "beecrypt.h" +#include "beecrypt/beecrypt.h" #ifdef __cplusplus extern "C" { #endif -/** - * Encrypts multiple blocks in Electronic Code Book (ECB) mode. - * @param bc blockcipher context - * @param bp blockcipher parameters - * @retval dst ciphertext data (aligned on a 32-bit boundary). - * @param src cleartext data (aligned on a 32-bit boundary). - * @param nblocks number of blocks to be encrypted. - * @retval 0 on success. +/*!\fn int blockEncryptECB(const blockCipher* bc, blockCipherParam* bp, uint32_t* dst, const uint32_t* src, unsigned int nblocks) + * \brief This function encrypts a number of data blocks in Electronic Code + * Book mode. + * \param bc The blockcipher. + * \param bp The cipher's parameter block. + * \param dst The ciphertext data; should be aligned on a 32-bit boundary. + * \param src The cleartext data; should be aligned on a 32-bit boundary. + * \param nblocks The number of blocks to be encrypted. + * \retval 0 on success. */ BEECRYPTAPI -int blockEncryptECB(const blockCipher* bc, blockCipherParam* bp, /*@out@*/ uint32_t* dst, const uint32_t* src, unsigned int nblocks) - /*@modifies bp, dst @*/; +int blockEncryptECB(const blockCipher* bc, blockCipherParam* bp, uint32_t* dst, const uint32_t* src, unsigned int nblocks); -/** - * Decrypts multiple blocks in Electronic Code Book (ECB) mode. - * @param bc blockcipher context - * @param bp blockcipher parameters - * @retval dst ciphertext data (aligned on a 32-bit boundary). - * @param src cleartext data (aligned on a 32-bit boundary). - * @param nblocks number of blocks to be encrypted. - * @retval 0 on success. +/*!\fn int blockDecryptECB(const blockCipher* bc, blockCipherParam* bp, uint32_t* dst, const uint32_t* src, unsigned int nblocks) + * \brief This function decrypts a number of data blocks in Electronic Code + * Book mode. + * \param bc The blockcipher. + * \param bp The cipher's parameter block. + * \param dst The cleartext data; should be aligned on a 32-bit boundary. + * \param src The ciphertext data; should be aligned on a 32-bit boundary. + * \param nblocks The number of blocks to be decrypted. + * \retval 0 on success. */ BEECRYPTAPI -int blockDecryptECB(const blockCipher* bc, blockCipherParam* bp, /*@out@*/ uint32_t* dst, const uint32_t* src, unsigned int nblocks) - /*@modifies bp, dst @*/; +int blockDecryptECB(const blockCipher* bc, blockCipherParam* bp, uint32_t* dst, const uint32_t* src, unsigned int nblocks); -/** - * Encrypts multiple blocks in Cipher Block Chaining (CBC) mode. - * @param bc blockcipher context - * @param bp blockcipher parameters - * @retval dst ciphertext data (aligned on a 32-bit boundary). - * @param src cleartext data (aligned on a 32-bit boundary). - * @param nblocks number of blocks to be encrypted. - * @retval 0 on success. +/*!\fn int blockEncryptCBC(const blockCipher* bc, blockCipherParam* bp, uint32_t* dst, const uint32_t* src, unsigned int nblocks) + * \brief This function encrypts a number of data blocks in Cipher Block + * Chaining mode. + * \param bc The blockcipher. + * \param bp The cipher's parameter block. + * \param dst The ciphertext data; should be aligned on a 32-bit boundary. + * \param src The cleartext data; should be aligned on a 32-bit boundary. + * \param nblocks The number of blocks to be encrypted. + * \retval 0 on success. */ BEECRYPTAPI -int blockEncryptCBC(const blockCipher* bc, blockCipherParam* bp, /*@out@*/ uint32_t* dst, const uint32_t* src, unsigned int nblocks) - /*@modifies bp, dst @*/; +int blockEncryptCBC(const blockCipher* bc, blockCipherParam* bp, uint32_t* dst, const uint32_t* src, unsigned int nblocks); -/** - * Decrypts multiple blocks in Cipher Block Chaining (CBC) mode. - * @param bc blockcipher context - * @param bp blockcipher parameters - * @retval dst ciphertext data (aligned on a 32-bit boundary). - * @param src cleartext data (aligned on a 32-bit boundary). - * @param nblocks number of blocks to be encrypted. - * @retval 0 on success. +/*!\fn int blockDecryptCBC(const blockCipher* bc, blockCipherParam* bp, uint32_t* dst, const uint32_t* src, unsigned int nblocks) + * \brief This function decrypts a number of data blocks in Cipher Block + * Chaining mode. + * \param bc The blockcipher. + * \param bp The cipher's parameter block. + * \param dst The cleartext data; should be aligned on a 32-bit boundary. + * \param src The ciphertext data; should be aligned on a 32-bit boundary. + * \param nblocks The number of blocks to be decrypted. + * \retval 0 on success. */ BEECRYPTAPI -int blockDecryptCBC(const blockCipher* bc, blockCipherParam* bp, /*@out@*/ uint32_t* dst, const uint32_t* src, unsigned int nblocks) - /*@modifies bp, dst @*/; +int blockDecryptCBC(const blockCipher* bc, blockCipherParam* bp, uint32_t* dst, const uint32_t* src, unsigned int nblocks); #ifdef __cplusplus } diff --git a/beecrypt/blockpad.c b/beecrypt/blockpad.c index 3e2fe73..9bc73f1 100644 --- a/beecrypt/blockpad.c +++ b/beecrypt/blockpad.c @@ -23,9 +23,13 @@ * \ingroup BC_m */ -#include "system.h" -#include "blockpad.h" -#include "debug.h" +#define BEECRYPT_DLL_EXPORT + +#if HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/blockpad.h" memchunk* pkcs5Pad(size_t blockbytes, memchunk* tmp) { @@ -46,14 +50,10 @@ memchunk* pkcs5Unpad(size_t blockbytes, memchunk* tmp) { if (tmp) { - byte padvalue; + byte padvalue = tmp->data[tmp->size - 1]; + unsigned int i; -/*@-usedef@*/ /* LCL: tmp->{data,size} not initialized? */ - if (tmp->data == (byte*) 0) - return (memchunk*) 0; - padvalue = tmp->data[tmp->size - 1]; -/*@=usedef@*/ if (padvalue > blockbytes) return (memchunk*) 0; @@ -64,12 +64,10 @@ memchunk* pkcs5Unpad(size_t blockbytes, memchunk* tmp) } tmp->size -= padvalue; -/* tmp->data = (byte*) realloc(tmp->data, tmp->size; */ +/* tmp->data = (byte*) realloc(tmp->data, tmp->size); */ } - /*@-temptrans -compdef @*/ return tmp; - /*@=temptrans =compdef @*/ } memchunk* pkcs5PadCopy(size_t blockbytes, const memchunk* src) @@ -91,7 +89,7 @@ memchunk* pkcs5PadCopy(size_t blockbytes, const memchunk* src) return tmp; } -memchunk* pkcs5UnpadCopy(/*@unused@*/ size_t blockbytes, const memchunk* src) +memchunk* pkcs5UnpadCopy(size_t blockbytes, const memchunk* src) { memchunk* tmp; byte padvalue; @@ -99,8 +97,6 @@ memchunk* pkcs5UnpadCopy(/*@unused@*/ size_t blockbytes, const memchunk* src) if (src == (memchunk*) 0) return (memchunk*) 0; - if (src->data == (byte*) 0) - return (memchunk*) 0; padvalue = src->data[src->size - 1]; diff --git a/beecrypt/blockpad.h b/beecrypt/blockpad.h index c705d9e..da382bc 100644 --- a/beecrypt/blockpad.h +++ b/beecrypt/blockpad.h @@ -26,52 +26,21 @@ #ifndef _BLOCKPAD_H #define _BLOCKPAD_H -#include "beecrypt.h" +#include "beecrypt/beecrypt.h" #ifdef __cplusplus extern "C" { #endif -/** - * Enlarge buffer to boundary. - * @param blockbytes desired block alignment/pad boundary - * @param tmp buffer to pad - * @return buffer with pad added - */ -BEECRYPTAPI /*@only@*/ /*@null@*/ /*@unused@*/ -memchunk* pkcs5Pad (size_t blockbytes, /*@only@*/ /*@null@*/ memchunk* tmp) - /*@*/; - -/** - * Shrink buffer to boundary. - * @param blockbytes desired block alignment/pad boundary - * @param tmp buffer to unpad - * @return buffer with pad removed - */ -BEECRYPTAPI /*@only@*/ /*@null@*/ -memchunk* pkcs5Unpad(size_t blockbytes, - /*@returned@*/ /*@null@*/ /*@out@*/ memchunk* tmp) - /*@modifies tmp @*/; +BEECRYPTAPI +memchunk* pkcs5Pad (size_t, memchunk*); +BEECRYPTAPI +memchunk* pkcs5Unpad(size_t, memchunk*); -/** - * Copy/enlarge buffer to boundary. - * @param blockbytes desired block alignment/pad boundary - * @param src buffer to pad - * @return copy of buffer with pad added - */ -BEECRYPTAPI /*@only@*/ /*@null@*/ -memchunk* pkcs5PadCopy (size_t blockbytes, const memchunk* src) - /*@*/; - -/** - * Copy/shrink buffer to boundary. - * @param blockbytes desired block alignment/pad boundary - * @param src buffer to unpad - * @return copy of buffer with pad removed - */ -BEECRYPTAPI /*@only@*/ /*@null@*/ /*@unused@*/ -memchunk* pkcs5UnpadCopy(size_t blockbytes, const memchunk* src) - /*@*/; +BEECRYPTAPI +memchunk* pkcs5PadCopy (size_t, const memchunk*); +BEECRYPTAPI +memchunk* pkcs5UnpadCopy(size_t, const memchunk*); #ifdef __cplusplus } diff --git a/beecrypt/blowfish.c b/beecrypt/blowfish.c index 0381ba8..47eca2a 100644 --- a/beecrypt/blowfish.c +++ b/beecrypt/blowfish.c @@ -23,12 +23,14 @@ * \ingroup BC_m BC_blowfish_m */ -#include "system.h" -#include "beecrypt.h" -#include "blowfishopt.h" -#include "blowfish.h" -#include "endianness.h" -#include "debug.h" +#define BEECRYPT_DLL_EXPORT + +#if HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/blowfish.h" +#include "beecrypt/endianness.h" #ifdef ASM_BLOWFISHENCRYPTECB extern int blowfishEncryptECB(blowfishparam*, uint32_t*, const uint32_t*, unsigned int); @@ -38,13 +40,6 @@ extern int blowfishEncryptECB(blowfishparam*, uint32_t*, const uint32_t*, unsign extern int blowfishDecryptECB(blowfishparam*, uint32_t*, const uint32_t*, unsigned int); #endif -/*!\addtogroup BC_blowfish_m - * \{ - */ - -/** - */ -/*@observer@*/ /*@unchecked@*/ static uint32_t _bf_p[BLOWFISHPSIZE] = { 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89, @@ -53,9 +48,6 @@ static uint32_t _bf_p[BLOWFISHPSIZE] = { 0x9216d5d9, 0x8979fb1b }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static uint32_t _bf_s[1024] = { 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99, @@ -318,15 +310,13 @@ static uint32_t _bf_s[1024] = { #define EROUND(l,r) l ^= *(p++); r ^= ((s[((l>>24)&0xff)+0x000]+s[((l>>16)&0xff)+0x100])^s[((l>>8)&0xff)+0x200])+s[((l>>0)&0xff)+0x300] #define DROUND(l,r) l ^= *(p--); r ^= ((s[((l>>24)&0xff)+0x000]+s[((l>>16)&0xff)+0x100])^s[((l>>8)&0xff)+0x200])+s[((l>>0)&0xff)+0x300] -/*@-sizeoftype@*/ -/*@-castfcnptr@*/ const blockCipher blowfish = { "Blowfish", sizeof(blowfishParam), - 8U, - 64U, - 448U, - 32U, + 8, + 64, + 448, + 32, (blockCipherSetup) blowfishSetup, (blockCipherSetIV) blowfishSetIV, /* raw */ @@ -354,8 +344,6 @@ const blockCipher blowfish = { }, (blockCipherFeedback) blowfishFeedback }; -/*@=castfcnptr@*/ -/*@=sizeoftype@*/ int blowfishSetup(blowfishParam* bp, const byte* key, size_t keybits, cipherOperation op) { @@ -370,7 +358,7 @@ int blowfishSetup(blowfishParam* bp, const byte* key, size_t keybits, cipherOper uint32_t tmp, work[2]; - memcpy(s, _bf_s, 1024 * sizeof(*s)); + memcpy(s, _bf_s, 1024 * sizeof(uint32_t)); for (i = 0, k = 0; i < BLOWFISHPSIZE; i++) { @@ -389,7 +377,7 @@ int blowfishSetup(blowfishParam* bp, const byte* key, size_t keybits, cipherOper for (i = 0; i < BLOWFISHPSIZE; i += 2, p += 2) { - (void) blowfishEncrypt(bp, work, work); + blowfishEncrypt(bp, work, work); #if WORDS_BIGENDIAN p[0] = work[0]; p[1] = work[1]; @@ -401,7 +389,7 @@ int blowfishSetup(blowfishParam* bp, const byte* key, size_t keybits, cipherOper for (i = 0; i < 1024; i += 2, s += 2) { - (void) blowfishEncrypt(bp, work, work); + blowfishEncrypt(bp, work, work); #if WORDS_BIGENDIAN s[0] = work[0]; s[1] = work[1]; @@ -423,21 +411,16 @@ int blowfishSetup(blowfishParam* bp, const byte* key, size_t keybits, cipherOper #ifndef ASM_BLOWFISHSETIV int blowfishSetIV(blowfishParam* bp, const byte* iv) { -/*@-mayaliasunique@*/ if (iv) - memcpy(bp->fdback, iv, sizeof(bp->fdback)); + memcpy(bp->fdback, iv, 8); else - memset(bp->fdback, 0, sizeof(bp->fdback)); -/*@=mayaliasunique@*/ + memset(bp->fdback, 0, 8); return 0; } #endif -/*@-exportheader@*/ -/*@unused@*/ int blowfishBlowit(blowfishParam* bp, uint32_t* dst, const uint32_t* src) - /*@modifies *dst @*/ { register uint32_t xl = src[0], xr = src[1]; register uint32_t* p = bp->p; @@ -450,7 +433,6 @@ int blowfishBlowit(blowfishParam* bp, uint32_t* dst, const uint32_t* src) return 0; } -/*@=exportheader@*/ #ifndef ASM_BLOWFISHENCRYPT int blowfishEncrypt(blowfishParam* bp, uint32_t* dst, const uint32_t* src) @@ -520,6 +502,3 @@ uint32_t* blowfishFeedback(blowfishParam* bp) { return bp->fdback; } - -/*!\} - */ diff --git a/beecrypt/blowfish.h b/beecrypt/blowfish.h index c52ed35..d8f752f 100644 --- a/beecrypt/blowfish.h +++ b/beecrypt/blowfish.h @@ -34,18 +34,28 @@ #ifndef _BLOWFISH_H #define _BLOWFISH_H -#include "beecrypt.h" -#include "blowfishopt.h" +#include "beecrypt/beecrypt.h" +#include "beecrypt/blowfishopt.h" #define BLOWFISHROUNDS 16 #define BLOWFISHPSIZE (BLOWFISHROUNDS+2) -/** \ingroup BC_blowfish_m +/*!\brief Holds all the parameters necessary for the Blowfish cipher. + * \ingroup BC_blowfish_m */ typedef struct { + /*!\var p + * \brief Holds the key expansion. + */ uint32_t p[BLOWFISHPSIZE]; + /*!\var s + * \brief Holds the s-boxes. + */ uint32_t s[1024]; + /*!\var fdback + * \brief Buffer to be used by block chaining or feedback modes. + */ uint32_t fdback[2]; } blowfishParam; @@ -53,50 +63,59 @@ typedef struct extern "C" { #endif -/** \ingroup BC_blowfish_m +/*!\var blowfish + * \brief Holds the full API description of the Blowfish algorithm. */ -/*@observer@*/ /*@checked@*/ extern const BEECRYPTAPI blockCipher blowfish; -/** \ingroup BC_blowfish_m +/*!\fn int blowfishSetup(blowfishParam* bp, const byte* key, size_t keybits, cipherOperation + op) + * \brief The function performs the cipher's key expansion. + * \param bp The cipher's parameter block. + * \param key The key value. + * \param keybits The number of bits in the key; legal values are: 32 to 448, + * in multiples of 8. + * \param op ENCRYPT or DECRYPT. + * \retval 0 on success. + * \retval -1 on failure. */ -/*@-exportlocal@*/ BEECRYPTAPI -int blowfishSetup (blowfishParam* bp, const byte* key, size_t keybits, cipherOperation op) - /*@modifies bp @*/; -/*@=exportlocal@*/ +int blowfishSetup (blowfishParam*, const byte*, size_t, cipherOperation); -/** \ingroup BC_blowfish_m +/*!\fn int blowfishSetIV(blowfishParam* bp, const byte* iv) + * \brief This function sets the Initialization Vector. + * \note This function is only useful in block chaining or feedback modes. + * \param bp The cipher's parameter block. + * \param iv The initialization vector; may be null. + * \retval 0 on success. */ -/*@-exportlocal@*/ BEECRYPTAPI -int blowfishSetIV (blowfishParam* bp, const byte* iv) - /*@modifies bp @*/; -/*@=exportlocal@*/ +int blowfishSetIV (blowfishParam*, const byte*); -/** \ingroup BC_blowfish_m +/*!\fn blowfishEncrypt(blowfishParam* bp, uint32_t* dst, const uint32_t* src) + * \brief This function performs the Blowfish encryption; it encrypts one block + * of 64 bits. + * \param bp The cipher's parameter block. + * \param dst The ciphertext; should be aligned on 32-bit boundary. + * \param src The cleartext; should be aligned on 32-bit boundary. + * \retval 0 on success. */ -/*@-exportlocal@*/ BEECRYPTAPI -int blowfishEncrypt(blowfishParam* bp, uint32_t* dst, const uint32_t* src) - /*@modifies bp, dst @*/; -/*@=exportlocal@*/ +int blowfishEncrypt (blowfishParam*, uint32_t*, const uint32_t*); -/** \ingroup BC_blowfish_m +/*!\fn blowfishDecrypt(blowfishParam* bp, uint32_t* dst, const uint32_t* src) + * \brief This function performs the Blowfish decryption; it Rderypts one block + * of 64 bits. + * \param bp The cipher's parameter block. + * \param dst The cleartext; should be aligned on 32-bit boundary. + * \param src The ciphertext; should be aligned on 32-bit boundary. + * \retval 0 on success. */ -/*@-exportlocal@*/ BEECRYPTAPI -int blowfishDecrypt(blowfishParam* bp, uint32_t* dst, const uint32_t* src) - /*@modifies bp, dst @*/; -/*@=exportlocal@*/ +int blowfishDecrypt (blowfishParam*, uint32_t*, const uint32_t*); -/** \ingroup BC_blowfish_m - */ -/*@-exportlocal@*/ -BEECRYPTAPI /*@observer@*/ -uint32_t* blowfishFeedback(blowfishParam* bp) - /*@*/; -/*@=exportlocal@*/ +BEECRYPTAPI +uint32_t* blowfishFeedback(blowfishParam*); #ifdef __cplusplus } diff --git a/beecrypt/blowfishopt.h b/beecrypt/blowfishopt.h index 8f72c7d..2150a43 100644 --- a/beecrypt/blowfishopt.h +++ b/beecrypt/blowfishopt.h @@ -19,13 +19,16 @@ /*!\file blowfishopt.h * \brief Blowfish block cipher, assembler-optimized routines, headers. - * \author Bob Deblier + * \author Bob Deblier * \ingroup BC_blowfish_m */ #ifndef _BLOWFISHOPT_H #define _BLOWFISHOPT_H +#include "beecrypt/beecrypt.h" +#include "beecrypt/blowfish.h" + #ifdef __cplusplus extern "C" { #endif diff --git a/beecrypt/c++/Makefile.am b/beecrypt/c++/Makefile.am new file mode 100644 index 0000000..11433b4 --- /dev/null +++ b/beecrypt/c++/Makefile.am @@ -0,0 +1,44 @@ +LIBBEECRYPT_CXX_LT_CURRENT = 8 +LIBBEECRYPT_CXX_LT_AGE = 2 +LIBBEECRYPT_CXX_LT_REVISION = 0 + +INCLUDES = -I$(top_srcdir)/.. + +AUTOMAKE_OPTIONS = gnu no-dependencies + +SUBDIRS = lang io util security crypto beeyond . provider + +libaltdir=$(prefix)/lib@LIBALT@ +cxxdir=$(pkgincludedir)/c++ + +libalt_LTLIBRARIES = libbeecrypt_cxx.la + +libbeecrypt_cxx_la_SOURCES = \ +adapter.cxx \ +bstream.cxx \ +resource.cxx + +libbeecrypt_cxx_la_LIBADD = ../libbeecrypt.la beeyond/libcxxbeeyond.la crypto/libcxxcrypto.la io/libcxxio.la lang/libcxxlang.la util/libcxxutil.la security/libcxxsecurity.la -licuuc -licuio +libbeecrypt_cxx_la_LDFLAGS = -no-undefined -version-info $(LIBBEECRYPT_CXX_LT_CURRENT):$(LIBBEECRYPT_CXX_LT_REVISION):$(LIBBEECRYPT_CXX_LT_AGE) + +cxx_HEADERS = \ +array.h \ +bstream.h \ +mutex.h + +noinst_HEADERS = \ +adapter.h \ +resource.h + +TESTS = testdsa testrsa testks + +check_PROGRAMS = testdsa testrsa testks + +testdsa_SOURCES = testdsa.cxx +testdsa_LDADD = libbeecrypt_cxx.la + +testrsa_SOURCES = testrsa.cxx +testrsa_LDADD = libbeecrypt_cxx.la + +testks_SOURCES = testks.cxx +testks_LDADD = libbeecrypt_cxx.la diff --git a/beecrypt/c++/Makefile.in b/beecrypt/c++/Makefile.in new file mode 100644 index 0000000..3be53cf --- /dev/null +++ b/beecrypt/c++/Makefile.in @@ -0,0 +1,734 @@ +# Makefile.in generated by automake 1.8.3 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + + +SOURCES = $(libbeecrypt_cxx_la_SOURCES) $(testdsa_SOURCES) $(testks_SOURCES) $(testrsa_SOURCES) + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +top_builddir = .. +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +INSTALL = @INSTALL@ +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +host_triplet = @host@ +check_PROGRAMS = testdsa$(EXEEXT) testrsa$(EXEEXT) testks$(EXEEXT) +subdir = c++ +DIST_COMMON = $(cxx_HEADERS) $(noinst_HEADERS) $(srcdir)/Makefile.am \ + $(srcdir)/Makefile.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \ + $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +am__installdirs = "$(DESTDIR)$(libaltdir)" "$(DESTDIR)$(cxxdir)" +libaltLTLIBRARIES_INSTALL = $(INSTALL) +LTLIBRARIES = $(libalt_LTLIBRARIES) +libbeecrypt_cxx_la_DEPENDENCIES = ../libbeecrypt.la \ + beeyond/libcxxbeeyond.la crypto/libcxxcrypto.la io/libcxxio.la \ + lang/libcxxlang.la util/libcxxutil.la \ + security/libcxxsecurity.la +am_libbeecrypt_cxx_la_OBJECTS = adapter.lo bstream.lo resource.lo +libbeecrypt_cxx_la_OBJECTS = $(am_libbeecrypt_cxx_la_OBJECTS) +am_testdsa_OBJECTS = testdsa.$(OBJEXT) +testdsa_OBJECTS = $(am_testdsa_OBJECTS) +testdsa_DEPENDENCIES = libbeecrypt_cxx.la +am_testks_OBJECTS = testks.$(OBJEXT) +testks_OBJECTS = $(am_testks_OBJECTS) +testks_DEPENDENCIES = libbeecrypt_cxx.la +am_testrsa_OBJECTS = testrsa.$(OBJEXT) +testrsa_OBJECTS = $(am_testrsa_OBJECTS) +testrsa_DEPENDENCIES = libbeecrypt_cxx.la +DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir) +depcomp = +am__depfiles_maybe = +CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) +LTCXXCOMPILE = $(LIBTOOL) --mode=compile $(CXX) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CXXFLAGS) $(CXXFLAGS) +CXXLD = $(CXX) +CXXLINK = $(LIBTOOL) --mode=link $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) \ + $(AM_LDFLAGS) $(LDFLAGS) -o $@ +SOURCES = $(libbeecrypt_cxx_la_SOURCES) $(testdsa_SOURCES) \ + $(testks_SOURCES) $(testrsa_SOURCES) +DIST_SOURCES = $(libbeecrypt_cxx_la_SOURCES) $(testdsa_SOURCES) \ + $(testks_SOURCES) $(testrsa_SOURCES) +RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \ + html-recursive info-recursive install-data-recursive \ + install-exec-recursive install-info-recursive \ + install-recursive installcheck-recursive installdirs-recursive \ + pdf-recursive ps-recursive uninstall-info-recursive \ + uninstall-recursive +cxxHEADERS_INSTALL = $(INSTALL_HEADER) +HEADERS = $(cxx_HEADERS) $(noinst_HEADERS) +ETAGS = etags +CTAGS = ctags +DIST_SUBDIRS = $(SUBDIRS) +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMDEP_FALSE = @AMDEP_FALSE@ +AMDEP_TRUE = @AMDEP_TRUE@ +AMTAR = @AMTAR@ +AR = @AR@ +AS = @AS@ +ASM_ALIGN = @ASM_ALIGN@ +ASM_ARCH = @ASM_ARCH@ +ASM_BIGENDIAN = @ASM_BIGENDIAN@ +ASM_CPU = @ASM_CPU@ +ASM_GLOBL = @ASM_GLOBL@ +ASM_GSYM_PREFIX = @ASM_GSYM_PREFIX@ +ASM_LSYM_PREFIX = @ASM_LSYM_PREFIX@ +ASM_OS = @ASM_OS@ +ASM_TEXTSEG = @ASM_TEXTSEG@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCAS = @CCAS@ +CCASFLAGS = @CCASFLAGS@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DLLTOOL = @DLLTOOL@ +ECHO = @ECHO@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +F77 = @F77@ +FFLAGS = @FFLAGS@ +INCLUDE_DLFCN_H = @INCLUDE_DLFCN_H@ +INCLUDE_INTTYPES_H = @INCLUDE_INTTYPES_H@ +INCLUDE_MALLOC_H = @INCLUDE_MALLOC_H@ +INCLUDE_PTHREAD_H = @INCLUDE_PTHREAD_H@ +INCLUDE_STDINT_H = @INCLUDE_STDINT_H@ +INCLUDE_STDIO_H = @INCLUDE_STDIO_H@ +INCLUDE_STDLIB_H = @INCLUDE_STDLIB_H@ +INCLUDE_STRING_H = @INCLUDE_STRING_H@ +INCLUDE_SYNCH_H = @INCLUDE_SYNCH_H@ +INCLUDE_THREAD_H = @INCLUDE_THREAD_H@ +INCLUDE_UNISTD_H = @INCLUDE_UNISTD_H@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +JAVAINC = @JAVAINC@ +LDFLAGS = @LDFLAGS@ +LIBALT = @LIBALT@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +MAYBE_LTLIB = @MAYBE_LTLIB@ +MAYBE_SUB = @MAYBE_SUB@ +MP_WBITS = @MP_WBITS@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PYTHONINC = @PYTHONINC@ +PYTHONLIB = @PYTHONLIB@ +RANLIB = @RANLIB@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +TYPEDEF_BC_COND_T = @TYPEDEF_BC_COND_T@ +TYPEDEF_BC_MUTEX_T = @TYPEDEF_BC_MUTEX_T@ +TYPEDEF_BC_THREAD_T = @TYPEDEF_BC_THREAD_T@ +TYPEDEF_INT16_T = @TYPEDEF_INT16_T@ +TYPEDEF_INT32_T = @TYPEDEF_INT32_T@ +TYPEDEF_INT64_T = @TYPEDEF_INT64_T@ +TYPEDEF_INT8_T = @TYPEDEF_INT8_T@ +TYPEDEF_SIZE_T = @TYPEDEF_SIZE_T@ +TYPEDEF_UINT16_T = @TYPEDEF_UINT16_T@ +TYPEDEF_UINT32_T = @TYPEDEF_UINT32_T@ +TYPEDEF_UINT64_T = @TYPEDEF_UINT64_T@ +TYPEDEF_UINT8_T = @TYPEDEF_UINT8_T@ +VERSION = @VERSION@ +ac_ct_AR = @ac_ct_AR@ +ac_ct_AS = @ac_ct_AS@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DLLTOOL = @ac_ct_DLLTOOL@ +ac_ct_F77 = @ac_ct_F77@ +ac_ct_OBJDUMP = @ac_ct_OBJDUMP@ +ac_ct_RANLIB = @ac_ct_RANLIB@ +ac_ct_STRIP = @ac_ct_STRIP@ +ac_cv_have_gcj = @ac_cv_have_gcj@ +ac_cv_have_java = @ac_cv_have_java@ +ac_cv_have_javac = @ac_cv_have_javac@ +ac_cv_have_python = @ac_cv_have_python@ +am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ +am__fastdepCC_TRUE = @am__fastdepCC_TRUE@ +am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@ +am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +datadir = @datadir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +sysconfdir = @sysconfdir@ +target = @target@ +target_alias = @target_alias@ +target_cpu = @target_cpu@ +target_os = @target_os@ +target_vendor = @target_vendor@ +LIBBEECRYPT_CXX_LT_CURRENT = 8 +LIBBEECRYPT_CXX_LT_AGE = 2 +LIBBEECRYPT_CXX_LT_REVISION = 0 +INCLUDES = -I$(top_srcdir)/.. +AUTOMAKE_OPTIONS = gnu no-dependencies +SUBDIRS = lang io util security crypto beeyond . provider +libaltdir = $(prefix)/lib@LIBALT@ +cxxdir = $(pkgincludedir)/c++ +libalt_LTLIBRARIES = libbeecrypt_cxx.la +libbeecrypt_cxx_la_SOURCES = \ +adapter.cxx \ +bstream.cxx \ +resource.cxx + +libbeecrypt_cxx_la_LIBADD = ../libbeecrypt.la beeyond/libcxxbeeyond.la crypto/libcxxcrypto.la io/libcxxio.la lang/libcxxlang.la util/libcxxutil.la security/libcxxsecurity.la -licuuc -licuio +libbeecrypt_cxx_la_LDFLAGS = -no-undefined -version-info $(LIBBEECRYPT_CXX_LT_CURRENT):$(LIBBEECRYPT_CXX_LT_REVISION):$(LIBBEECRYPT_CXX_LT_AGE) +cxx_HEADERS = \ +array.h \ +bstream.h \ +mutex.h + +noinst_HEADERS = \ +adapter.h \ +resource.h + +TESTS = testdsa testrsa testks +testdsa_SOURCES = testdsa.cxx +testdsa_LDADD = libbeecrypt_cxx.la +testrsa_SOURCES = testrsa.cxx +testrsa_LDADD = libbeecrypt_cxx.la +testks_SOURCES = testks.cxx +testks_LDADD = libbeecrypt_cxx.la +all: all-recursive + +.SUFFIXES: +.SUFFIXES: .cxx .lo .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ + && exit 0; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu c++/Makefile'; \ + cd $(top_srcdir) && \ + $(AUTOMAKE) --gnu c++/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +install-libaltLTLIBRARIES: $(libalt_LTLIBRARIES) + @$(NORMAL_INSTALL) + test -z "$(libaltdir)" || $(mkdir_p) "$(DESTDIR)$(libaltdir)" + @list='$(libalt_LTLIBRARIES)'; for p in $$list; do \ + if test -f $$p; then \ + f="`echo $$p | sed -e 's|^.*/||'`"; \ + echo " $(LIBTOOL) --mode=install $(libaltLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) '$$p' '$(DESTDIR)$(libaltdir)/$$f'"; \ + $(LIBTOOL) --mode=install $(libaltLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) "$$p" "$(DESTDIR)$(libaltdir)/$$f"; \ + else :; fi; \ + done + +uninstall-libaltLTLIBRARIES: + @$(NORMAL_UNINSTALL) + @list='$(libalt_LTLIBRARIES)'; for p in $$list; do \ + p="`echo $$p | sed -e 's|^.*/||'`"; \ + echo " $(LIBTOOL) --mode=uninstall rm -f '$(DESTDIR)$(libaltdir)/$$p'"; \ + $(LIBTOOL) --mode=uninstall rm -f "$(DESTDIR)$(libaltdir)/$$p"; \ + done + +clean-libaltLTLIBRARIES: + -test -z "$(libalt_LTLIBRARIES)" || rm -f $(libalt_LTLIBRARIES) + @list='$(libalt_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" = "$$p" && dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +libbeecrypt_cxx.la: $(libbeecrypt_cxx_la_OBJECTS) $(libbeecrypt_cxx_la_DEPENDENCIES) + $(CXXLINK) -rpath $(libaltdir) $(libbeecrypt_cxx_la_LDFLAGS) $(libbeecrypt_cxx_la_OBJECTS) $(libbeecrypt_cxx_la_LIBADD) $(LIBS) + +clean-checkPROGRAMS: + @list='$(check_PROGRAMS)'; for p in $$list; do \ + f=`echo $$p|sed 's/$(EXEEXT)$$//'`; \ + echo " rm -f $$p $$f"; \ + rm -f $$p $$f ; \ + done +testdsa$(EXEEXT): $(testdsa_OBJECTS) $(testdsa_DEPENDENCIES) + @rm -f testdsa$(EXEEXT) + $(CXXLINK) $(testdsa_LDFLAGS) $(testdsa_OBJECTS) $(testdsa_LDADD) $(LIBS) +testks$(EXEEXT): $(testks_OBJECTS) $(testks_DEPENDENCIES) + @rm -f testks$(EXEEXT) + $(CXXLINK) $(testks_LDFLAGS) $(testks_OBJECTS) $(testks_LDADD) $(LIBS) +testrsa$(EXEEXT): $(testrsa_OBJECTS) $(testrsa_DEPENDENCIES) + @rm -f testrsa$(EXEEXT) + $(CXXLINK) $(testrsa_LDFLAGS) $(testrsa_OBJECTS) $(testrsa_LDADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +.cxx.o: + $(CXXCOMPILE) -c -o $@ $< + +.cxx.obj: + $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +.cxx.lo: + $(LTCXXCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +distclean-libtool: + -rm -f libtool +uninstall-info-am: +install-cxxHEADERS: $(cxx_HEADERS) + @$(NORMAL_INSTALL) + test -z "$(cxxdir)" || $(mkdir_p) "$(DESTDIR)$(cxxdir)" + @list='$(cxx_HEADERS)'; for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + f="`echo $$p | sed -e 's|^.*/||'`"; \ + echo " $(cxxHEADERS_INSTALL) '$$d$$p' '$(DESTDIR)$(cxxdir)/$$f'"; \ + $(cxxHEADERS_INSTALL) "$$d$$p" "$(DESTDIR)$(cxxdir)/$$f"; \ + done + +uninstall-cxxHEADERS: + @$(NORMAL_UNINSTALL) + @list='$(cxx_HEADERS)'; for p in $$list; do \ + f="`echo $$p | sed -e 's|^.*/||'`"; \ + echo " rm -f '$(DESTDIR)$(cxxdir)/$$f'"; \ + rm -f "$(DESTDIR)$(cxxdir)/$$f"; \ + done + +# This directory's subdirectories are mostly independent; you can cd +# into them and run `make' without going through this Makefile. +# To change the values of `make' variables: instead of editing Makefiles, +# (1) if the variable is set in `config.status', edit `config.status' +# (which will cause the Makefiles to be regenerated when you run `make'); +# (2) otherwise, pass the desired values on the `make' command line. +$(RECURSIVE_TARGETS): + @set fnord $$MAKEFLAGS; amf=$$2; \ + dot_seen=no; \ + target=`echo $@ | sed s/-recursive//`; \ + list='$(SUBDIRS)'; for subdir in $$list; do \ + echo "Making $$target in $$subdir"; \ + if test "$$subdir" = "."; then \ + dot_seen=yes; \ + local_target="$$target-am"; \ + else \ + local_target="$$target"; \ + fi; \ + (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ + || case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \ + done; \ + if test "$$dot_seen" = "no"; then \ + $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \ + fi; test -z "$$fail" + +mostlyclean-recursive clean-recursive distclean-recursive \ +maintainer-clean-recursive: + @set fnord $$MAKEFLAGS; amf=$$2; \ + dot_seen=no; \ + case "$@" in \ + distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \ + *) list='$(SUBDIRS)' ;; \ + esac; \ + rev=''; for subdir in $$list; do \ + if test "$$subdir" = "."; then :; else \ + rev="$$subdir $$rev"; \ + fi; \ + done; \ + rev="$$rev ."; \ + target=`echo $@ | sed s/-recursive//`; \ + for subdir in $$rev; do \ + echo "Making $$target in $$subdir"; \ + if test "$$subdir" = "."; then \ + local_target="$$target-am"; \ + else \ + local_target="$$target"; \ + fi; \ + (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ + || case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \ + done && test -z "$$fail" +tags-recursive: + list='$(SUBDIRS)'; for subdir in $$list; do \ + test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \ + done +ctags-recursive: + list='$(SUBDIRS)'; for subdir in $$list; do \ + test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) ctags); \ + done + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: tags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + if (etags --etags-include --version) >/dev/null 2>&1; then \ + include_option=--etags-include; \ + else \ + include_option=--include; \ + fi; \ + list='$(SUBDIRS)'; for subdir in $$list; do \ + if test "$$subdir" = .; then :; else \ + test -f $$subdir/TAGS && \ + tags="$$tags $$include_option=$$here/$$subdir/TAGS"; \ + fi; \ + done; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(ETAGS_ARGS)$$tags$$unique" \ + || $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$tags $$unique +ctags: CTAGS +CTAGS: ctags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(CTAGS_ARGS)$$tags$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$tags $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && cd $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) $$here + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +check-TESTS: $(TESTS) + @failed=0; all=0; xfail=0; xpass=0; skip=0; \ + srcdir=$(srcdir); export srcdir; \ + list='$(TESTS)'; \ + if test -n "$$list"; then \ + for tst in $$list; do \ + if test -f ./$$tst; then dir=./; \ + elif test -f $$tst; then dir=; \ + else dir="$(srcdir)/"; fi; \ + if $(TESTS_ENVIRONMENT) $${dir}$$tst; then \ + all=`expr $$all + 1`; \ + case " $(XFAIL_TESTS) " in \ + *" $$tst "*) \ + xpass=`expr $$xpass + 1`; \ + failed=`expr $$failed + 1`; \ + echo "XPASS: $$tst"; \ + ;; \ + *) \ + echo "PASS: $$tst"; \ + ;; \ + esac; \ + elif test $$? -ne 77; then \ + all=`expr $$all + 1`; \ + case " $(XFAIL_TESTS) " in \ + *" $$tst "*) \ + xfail=`expr $$xfail + 1`; \ + echo "XFAIL: $$tst"; \ + ;; \ + *) \ + failed=`expr $$failed + 1`; \ + echo "FAIL: $$tst"; \ + ;; \ + esac; \ + else \ + skip=`expr $$skip + 1`; \ + echo "SKIP: $$tst"; \ + fi; \ + done; \ + if test "$$failed" -eq 0; then \ + if test "$$xfail" -eq 0; then \ + banner="All $$all tests passed"; \ + else \ + banner="All $$all tests behaved as expected ($$xfail expected failures)"; \ + fi; \ + else \ + if test "$$xpass" -eq 0; then \ + banner="$$failed of $$all tests failed"; \ + else \ + banner="$$failed of $$all tests did not behave as expected ($$xpass unexpected passes)"; \ + fi; \ + fi; \ + dashes="$$banner"; \ + skipped=""; \ + if test "$$skip" -ne 0; then \ + skipped="($$skip tests were not run)"; \ + test `echo "$$skipped" | wc -c` -gt `echo "$$banner" | wc -c` && \ + dashes="$$skipped"; \ + fi; \ + report=""; \ + if test "$$failed" -ne 0 && test -n "$(PACKAGE_BUGREPORT)"; then \ + report="Please report to $(PACKAGE_BUGREPORT)"; \ + test `echo "$$report" | wc -c` -gt `echo "$$banner" | wc -c` && \ + dashes="$$report"; \ + fi; \ + dashes=`echo "$$dashes" | sed s/./=/g`; \ + echo "$$dashes"; \ + echo "$$banner"; \ + test -n "$$skipped" && echo "$$skipped"; \ + test -n "$$report" && echo "$$report"; \ + echo "$$dashes"; \ + test "$$failed" -eq 0; \ + else :; fi + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \ + list='$(DISTFILES)'; for file in $$list; do \ + case $$file in \ + $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \ + $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \ + esac; \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test "$$dir" != "$$file" && test "$$dir" != "."; then \ + dir="/$$dir"; \ + $(mkdir_p) "$(distdir)$$dir"; \ + else \ + dir=''; \ + fi; \ + if test -d $$d/$$file; then \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + fi; \ + cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ + else \ + test -f $(distdir)/$$file \ + || cp -p $$d/$$file $(distdir)/$$file \ + || exit 1; \ + fi; \ + done + list='$(SUBDIRS)'; for subdir in $$list; do \ + if test "$$subdir" = .; then :; else \ + test -d "$(distdir)/$$subdir" \ + || mkdir "$(distdir)/$$subdir" \ + || exit 1; \ + (cd $$subdir && \ + $(MAKE) $(AM_MAKEFLAGS) \ + top_distdir="../$(top_distdir)" \ + distdir="../$(distdir)/$$subdir" \ + distdir) \ + || exit 1; \ + fi; \ + done +check-am: all-am + $(MAKE) $(AM_MAKEFLAGS) $(check_PROGRAMS) + $(MAKE) $(AM_MAKEFLAGS) check-TESTS +check: check-recursive +all-am: Makefile $(LTLIBRARIES) $(HEADERS) +installdirs: installdirs-recursive +installdirs-am: + for dir in "$(DESTDIR)$(libaltdir)" "$(DESTDIR)$(cxxdir)"; do \ + test -z "$$dir" || $(mkdir_p) "$$dir"; \ + done +install: install-recursive +install-exec: install-exec-recursive +install-data: install-data-recursive +uninstall: uninstall-recursive + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-recursive +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -rm -f $(CONFIG_CLEAN_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-recursive + +clean-am: clean-checkPROGRAMS clean-generic clean-libaltLTLIBRARIES \ + clean-libtool mostlyclean-am + +distclean: distclean-recursive + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-libtool distclean-tags + +dvi: dvi-recursive + +dvi-am: + +html: html-recursive + +info: info-recursive + +info-am: + +install-data-am: install-cxxHEADERS install-libaltLTLIBRARIES + +install-exec-am: + +install-info: install-info-recursive + +install-man: + +installcheck-am: + +maintainer-clean: maintainer-clean-recursive + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-recursive + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-recursive + +pdf-am: + +ps: ps-recursive + +ps-am: + +uninstall-am: uninstall-cxxHEADERS uninstall-info-am \ + uninstall-libaltLTLIBRARIES + +uninstall-info: uninstall-info-recursive + +.PHONY: $(RECURSIVE_TARGETS) CTAGS GTAGS all all-am check check-TESTS \ + check-am clean clean-checkPROGRAMS clean-generic \ + clean-libaltLTLIBRARIES clean-libtool clean-recursive ctags \ + ctags-recursive distclean distclean-compile distclean-generic \ + distclean-libtool distclean-recursive distclean-tags distdir \ + dvi dvi-am html html-am info info-am install install-am \ + install-cxxHEADERS install-data install-data-am install-exec \ + install-exec-am install-info install-info-am \ + install-libaltLTLIBRARIES install-man install-strip \ + installcheck installcheck-am installdirs installdirs-am \ + maintainer-clean maintainer-clean-generic \ + maintainer-clean-recursive mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool mostlyclean-recursive \ + pdf pdf-am ps ps-am tags tags-recursive uninstall uninstall-am \ + uninstall-cxxHEADERS uninstall-info-am \ + uninstall-libaltLTLIBRARIES + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/beecrypt/c++/adapter.cxx b/beecrypt/c++/adapter.cxx new file mode 100644 index 0000000..c673809 --- /dev/null +++ b/beecrypt/c++/adapter.cxx @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#if HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/adapter.h" + +using namespace beecrypt; + +int sraSetup(SecureRandom* random) +{ + return 0; +} + +int sraSeed(SecureRandom* random, const byte* data, size_t size) +{ + random->setSeed(data, size); + return 0; +} + +int sraNext(SecureRandom* random, byte* data, size_t size) +{ + random->nextBytes(data, size); + return 0; +} + +int sraCleanup(SecureRandom* random) +{ + return 0; +} + +const randomGenerator sraprng = { + "SecureRandom Adapter", + 0, + (randomGeneratorSetup) sraSetup, + (randomGeneratorSeed) sraSeed, + (randomGeneratorNext) sraNext, + (randomGeneratorCleanup) sraCleanup +}; + +randomGeneratorContextAdapter::randomGeneratorContextAdapter(SecureRandom* random) : randomGeneratorContext(&sraprng) +{ + param = (randomGeneratorParam*) random; +} + +// SecureRandom systemsr; diff --git a/beecrypt/c++/adapter.h b/beecrypt/c++/adapter.h new file mode 100644 index 0000000..330b9e1 --- /dev/null +++ b/beecrypt/c++/adapter.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file adapter.h + * \brief In-between layer for BeeCrypt C and C++ code. + * \author Bob Deblier + */ + +#ifndef _BEECRYPT_ADAPTER_H +#define _BEECRYPT_ADAPTER_H + +#include "beecrypt/beecrypt.h" + +#ifdef __cplusplus + +#include "beecrypt/c++/security/SecureRandom.h" +using beecrypt::security::SecureRandom; + +namespace beecrypt { + /*!\brief Class which transforms a SecureRandom generator into a randomGeneratorContext. + */ + struct BEECRYPTCXXAPI randomGeneratorContextAdapter : randomGeneratorContext + { + randomGeneratorContextAdapter(SecureRandom*); + }; +} + +#endif + +#endif diff --git a/beecrypt/c++/array.h b/beecrypt/c++/array.h new file mode 100644 index 0000000..b60611a --- /dev/null +++ b/beecrypt/c++/array.h @@ -0,0 +1,188 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file array.h + * \brief Array template class. + * \author Bob Deblier + * \ingroup CXX_m + */ + +#ifndef _TEMPLATE_ARRAY_H +#define _TEMPLATE_ARRAY_H + +#include "beecrypt/api.h" + +#ifdef __cplusplus + +#include + +namespace beecrypt { + + template + class array + { + private: + T* _data; + size_t _size; + + public: + array() throw () + { + _data = 0; + _size = 0; + } + + array(size_t size) throw (std::bad_alloc) + { + if (size) + { + _data = (T*) malloc(size * sizeof(T)); + if (_data == 0) + throw std::bad_alloc(); + } + else + _data = 0; + _size = size; + } + + array(const T* data, size_t size) throw (std::bad_alloc) + { + _data = (T*) malloc(size * sizeof(T)); + if (_data == 0) + throw std::bad_alloc(); + _size = size; + memcpy(_data, data, _size * sizeof(T)); + } + + array(const array& _copy) throw (std::bad_alloc) + { + _data = (T*) malloc(_copy._size * sizeof(T)); + if (_data == 0) + throw std::bad_alloc(); + _size = _copy._size; + memcpy(_data, _copy._data, _size * sizeof(T)); + } + + ~array() throw () + { + if (_data) + free(_data); + } + + const array& operator=(const array& _set) throw (std::bad_alloc) + { + resize(_set._size); + if (_size) + memcpy(_data, _set._data, _size * sizeof(T)); + + return *this; + } + + bool operator==(const array& _cmp) const throw () + { + if (_size != _cmp.size) + return false; + + if (_size == 0 && _cmp._size == 0) + return true; + + return !memcmp(_data, _cmp._data, _size * sizeof(T)); + } + + bool operator!=(const array& _cmp) const throw () + { + if (_size != _cmp._size) + return true; + + if (_size == 0 && _cmp._size == 0) + return false; + + return memcmp(_data, _cmp._data, _size * sizeof(T)); + } + + T* data() throw () + { + return _data; + } + + const T* data() const throw () + { + return _data; + } + + size_t size() const throw () + { + return _size; + } + + void resize(size_t _newsize) throw (std::bad_alloc) + { + if (_newsize) + { + _data = (T*) (_data ? realloc(_data, _newsize * sizeof(T)) : malloc(_newsize * sizeof(T))); + if (_data == 0) + throw std::bad_alloc(); + } + else + { + if (_data) + { + free(_data); + _data = 0; + } + } + _size = _newsize; + } + + T& operator[](size_t _n) throw () + { + return _data[_n]; + } + + const T operator[](size_t _n) const throw () + { + return _data[_n]; + } + + const array& operator+=(const array& _rhs) throw () + { + if (_rhs._size) + { + size_t _curr = _size; + resize(_size+_rhs._size); + memcpy(_data+_curr, _rhs._data, _rhs._size * sizeof(T)); + } + return *this; + } + }; + + template + array operator+(const array& _lhs, const array& _rhs) + { + array _con(_lhs); + + return _con += _rhs; + }; + + typedef array bytearray; + typedef array javachararray; +} + +#endif + +#endif diff --git a/beecrypt/c++/beeyond/AnyEncodedKeySpec.cxx b/beecrypt/c++/beeyond/AnyEncodedKeySpec.cxx new file mode 100644 index 0000000..17eec63 --- /dev/null +++ b/beecrypt/c++/beeyond/AnyEncodedKeySpec.cxx @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#include "beecrypt/c++/beeyond/AnyEncodedKeySpec.h" + +using namespace beecrypt::beeyond; + +AnyEncodedKeySpec::AnyEncodedKeySpec(const String& format, const byte* data, size_t size) : EncodedKeySpec(data, size), _format(format) +{ +} + +AnyEncodedKeySpec::AnyEncodedKeySpec(const String& format, const bytearray& copy) : EncodedKeySpec(copy), _format(format) +{ +} + +AnyEncodedKeySpec::~AnyEncodedKeySpec() +{ +} + +const String& AnyEncodedKeySpec::getFormat() const throw () +{ + return _format; +} diff --git a/beecrypt/c++/beeyond/AnyEncodedKeySpec.h b/beecrypt/c++/beeyond/AnyEncodedKeySpec.h new file mode 100644 index 0000000..de8a9ed --- /dev/null +++ b/beecrypt/c++/beeyond/AnyEncodedKeySpec.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file AnyEncodedKeySpec.h + * \ingroup CXX_BEEYOND_m + */ + +#ifndef _CLASS_ANYENCODEDKEYSPEC_H +#define _CLASS_ANYENCODEDKEYSPEC_H + +#ifdef __cplusplus + +#include "beecrypt/c++/lang/String.h" +using beecrypt::lang::String; +#include "beecrypt/c++/security/spec/EncodedKeySpec.h" +using beecrypt::security::spec::EncodedKeySpec; + +namespace beecrypt { + namespace beeyond { + class BEECRYPTCXXAPI AnyEncodedKeySpec : public EncodedKeySpec + { + private: + String _format; + + public: + AnyEncodedKeySpec(const String& format, const byte*, size_t); + AnyEncodedKeySpec(const String& format, const bytearray&); + + virtual ~AnyEncodedKeySpec(); + + virtual const String& getFormat() const throw (); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/beeyond/BeeCertificate.cxx b/beecrypt/c++/beeyond/BeeCertificate.cxx new file mode 100644 index 0000000..08fe437 --- /dev/null +++ b/beecrypt/c++/beeyond/BeeCertificate.cxx @@ -0,0 +1,619 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/beeyond/BeeCertificate.h" +#include "beecrypt/c++/beeyond/AnyEncodedKeySpec.h" +#include "beecrypt/c++/io/ByteArrayInputStream.h" +using beecrypt::io::ByteArrayInputStream; +#include "beecrypt/c++/io/ByteArrayOutputStream.h" +using beecrypt::io::ByteArrayOutputStream; +#include "beecrypt/c++/lang/NullPointerException.h" +using beecrypt::lang::NullPointerException; +#include "beecrypt/c++/security/KeyFactory.h" +using beecrypt::security::KeyFactory; +#include "beecrypt/c++/security/Signature.h" +using beecrypt::security::Signature; +#include "beecrypt/c++/security/cert/CertificateFactory.h" +using beecrypt::security::cert::CertificateFactory; + +using namespace beecrypt::beeyond; + +BeeCertificate::Field::~Field() +{ +} + +BeeCertificate::UnknownField::UnknownField() +{ +} + +BeeCertificate::UnknownField::UnknownField(const UnknownField& copy) : encoding(copy.encoding) +{ + type = copy.type; +} + +BeeCertificate::UnknownField::~UnknownField() +{ +} + +BeeCertificate::Field* BeeCertificate::UnknownField::clone() const +{ + return new BeeCertificate::UnknownField(*this); +} + +void BeeCertificate::UnknownField::decode(DataInputStream& in) throw (IOException) +{ + encoding.resize(in.available()); + + in.readFully(encoding); +} + +void BeeCertificate::UnknownField::encode(DataOutputStream& out) const throw (IOException) +{ + out.write(encoding); +} + +const javaint BeeCertificate::PublicKeyField::FIELD_TYPE = 0x5055424b; // 'PUBK' + +BeeCertificate::PublicKeyField::PublicKeyField() +{ + type = BeeCertificate::PublicKeyField::FIELD_TYPE; + pub = 0; +} + +BeeCertificate::PublicKeyField::PublicKeyField(const PublicKey& key) +{ + type = BeeCertificate::PublicKeyField::FIELD_TYPE; + pub = key.clone(); +} + +BeeCertificate::PublicKeyField::~PublicKeyField() +{ + delete pub; +} + +BeeCertificate::Field* BeeCertificate::PublicKeyField::clone() const +{ + return new BeeCertificate::PublicKeyField(*pub); +} + +void BeeCertificate::PublicKeyField::decode(DataInputStream& in) throw (IOException) +{ + String format; + + in.readUTF(format); + + // no need for a try-catch around this; calling function is expecting a thrown NoSuchAlgorithmException + KeyFactory* kf = KeyFactory::getInstance(format); + + try + { + javaint encsize = in.readInt(); + + if (encsize <= 0) + throw IOException("Invalid key encoding size"); + + bytearray enc(encsize); + + in.readFully(enc); + + AnyEncodedKeySpec spec(format, enc); + + pub = kf->generatePublic(spec); + + delete kf; + } + catch (...) + { + delete kf; + throw; + } +} + +void BeeCertificate::PublicKeyField::encode(DataOutputStream& out) const throw (IOException) +{ + out.writeUTF(*pub->getFormat()); + + const bytearray* pubenc = pub->getEncoded(); + + if (!pubenc) + throw NullPointerException("PublicKey has no encoding"); + + out.writeInt(pubenc->size()); + out.write(*pubenc); +} + +const javaint BeeCertificate::ParentCertificateField::FIELD_TYPE = 0x43455254; // 'CERT' + +BeeCertificate::ParentCertificateField::ParentCertificateField() +{ + type = BeeCertificate::ParentCertificateField::FIELD_TYPE; + parent = 0; +} + +BeeCertificate::ParentCertificateField::ParentCertificateField(const Certificate& cert) +{ + type = BeeCertificate::ParentCertificateField::FIELD_TYPE; + parent = cert.clone(); +} + +BeeCertificate::ParentCertificateField::~ParentCertificateField() +{ + delete parent; +} + +BeeCertificate::Field* BeeCertificate::ParentCertificateField::clone() const +{ + return new BeeCertificate::ParentCertificateField(*parent); +} + +void BeeCertificate::ParentCertificateField::decode(DataInputStream& in) throw (IOException) +{ + String type; + + in.readUTF(type); + + CertificateFactory* cf = CertificateFactory::getInstance(type); + + try + { + javaint encsize = in.readInt(); + + if (encsize <= 0) + throw IOException("Invalid certificate encoding size"); + + bytearray enc(encsize); + + in.readFully(enc); + + ByteArrayInputStream bin(enc); + + parent = cf->generateCertificate(bin); + + throw RuntimeException(); + + delete cf; + } + catch (...) + { + delete cf; + throw; + } +} + +void BeeCertificate::ParentCertificateField::encode(DataOutputStream& out) const throw (IOException) +{ + out.writeUTF(parent->getType()); + + const bytearray& parentenc = parent->getEncoded(); + + out.writeInt(parentenc.size()); + out.write(parentenc); +} + +BeeCertificate::Field* BeeCertificate::instantiateField(javaint type) +{ + switch (type) + { + case PublicKeyField::FIELD_TYPE: + return new PublicKeyField(); + + case ParentCertificateField::FIELD_TYPE: + return new ParentCertificateField(); + + default: + return new UnknownField(); + } +} + +const Date BeeCertificate::FOREVER((javalong) -1L); + +BeeCertificate::BeeCertificate() : Certificate("BEE") +{ + enc = 0; +} + +BeeCertificate::BeeCertificate(InputStream& in) throw (IOException) : Certificate("BEE") +{ + enc = 0; + + DataInputStream dis(in); + + dis.readUTF(issuer); + dis.readUTF(subject); + + created.setTime(dis.readLong()); + expires.setTime(dis.readLong()); + + javaint fieldcount = dis.readInt(); + if (fieldcount < 0) + throw IOException("field count < 0"); + + for (javaint i = 0; i < fieldcount; i++) + { + bytearray fenc; + + javaint type = dis.readInt(); + javaint size = dis.readInt(); + + fenc.resize(size); + + dis.readFully(fenc); + + ByteArrayInputStream bis(fenc); + DataInputStream fis(bis); + + Field* f = instantiateField(type); + + try + { + f->decode(fis); + fields.push_back(f); + } + catch (...) + { + delete f; + throw; + } + } + + dis.readUTF(signature_algorithm); + + javaint siglength = dis.readInt(); + + if (siglength < 0) + throw IOException("signature length < 0"); + + if (siglength > 0) + { + signature.resize(siglength); + dis.readFully(signature); + } +} + +BeeCertificate::BeeCertificate(const BeeCertificate& copy) : Certificate("BEE") +{ + issuer = copy.issuer; + subject = copy.subject; + created = copy.created; + expires = copy.expires; + for (fields_const_iterator it = copy.fields.begin(); it != copy.fields.end(); it++) + fields.push_back((*it)->clone()); + signature_algorithm = copy.signature_algorithm; + signature = copy.signature; + enc = 0; +} + +BeeCertificate::~BeeCertificate() +{ + if (enc) + delete enc; +} + +BeeCertificate* BeeCertificate::clone() const +{ + return new BeeCertificate(*this); +} + +const bytearray& BeeCertificate::getEncoded() const +{ + if (!enc) + { + // The following sequence shouldn't throw an exception + ByteArrayOutputStream bos; + DataOutputStream dos(bos); + + dos.writeUTF(issuer); + dos.writeUTF(subject); + dos.writeLong(created.getTime()); + dos.writeLong(expires.getTime()); + dos.writeInt(fields.size()); + + for (fields_vector::const_iterator it = fields.begin(); it != fields.end(); it++) + { + ByteArrayOutputStream bout; + DataOutputStream dout(bout); + + Field* f = (*it); + + f->encode(dout); + dout.close(); + + bytearray* fenc = bout.toByteArray(); + + dos.writeInt(f->type); + dos.writeInt(fenc->size()); + dos.write(*fenc); + + delete fenc; + } + + dos.writeUTF(signature_algorithm); + dos.writeInt(signature.size()); + dos.write(signature); + dos.close(); + bos.close(); + + enc = bos.toByteArray(); + } + + return *enc; +} + +const PublicKey& BeeCertificate::getPublicKey() const +{ + for (fields_const_iterator it = fields.begin(); it != fields.end(); it++) + { + if ((*it)->type == PublicKeyField::FIELD_TYPE) + { + const PublicKeyField* f = dynamic_cast(*it); + + if (f) + return *f->pub; + else + throw GeneralSecurityException("Somebody's trying to cheat with a new Field subclass"); + } + } + + throw CertificateException("BeeCertificate doesn't contain a PublicKey"); +} + +const Certificate& BeeCertificate::getParentCertificate() const +{ + for (fields_const_iterator it = fields.begin(); it != fields.end(); it++) + { + if ((*it)->type == ParentCertificateField::FIELD_TYPE) + { + const ParentCertificateField* f = dynamic_cast(*it); + + if (f) + return *f->parent; + else + throw GeneralSecurityException("Somebody's trying to cheat with a new Field subclass"); + } + } + + throw CertificateException("BeeCertificate doesn't contain a parent Certificate"); +} + +void BeeCertificate::verify(const PublicKey& pub) throw (CertificateException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException) +{ + Signature* sig = Signature::getInstance(signature_algorithm); + + try + { + sig->initVerify(pub); + + bytearray* tmp = encodeTBS(); + + try + { + sig->update(*tmp); + delete tmp; + } + catch (...) + { + delete tmp; + throw; + } + + if (!sig->verify(signature)) + throw CertificateException("signature doesn't match"); + + delete sig; + } + catch (...) + { + delete sig; + throw; + } +} + +void BeeCertificate::verify(const PublicKey& pub, const String& sigProvider) throw (CertificateException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException) +{ + Signature* sig = Signature::getInstance(signature_algorithm, sigProvider); + + try + { + sig->initVerify(pub); + + bytearray* tmp = encodeTBS(); + + try + { + sig->update(*tmp); + delete tmp; + } + catch (...) + { + delete tmp; + throw; + } + + if (!sig->verify(signature)) + throw CertificateException("signature doesn't match"); + + delete sig; + } + catch (...) + { + delete sig; + throw; + } +} + +const String& BeeCertificate::toString() const throw () +{ + if (!str) + str = new String(); + + return *str; +} + +void BeeCertificate::checkValidity() const throw (CertificateExpiredException, CertificateNotYetValidException) +{ + Date now; + + checkValidity(now); +} + +void BeeCertificate::checkValidity(const Date& at) const throw (CertificateExpiredException, CertificateNotYetValidException) +{ + if (at.before(created)) + throw CertificateNotYetValidException(); + + if (expires != FOREVER) + if (at.after(expires)) + throw CertificateExpiredException(); +} + +const Date& BeeCertificate::getNotAfter() const throw () +{ + return expires; +} + +const Date& BeeCertificate::getNotBefore() const throw () +{ + return created; +} + +const bytearray& BeeCertificate::getSignature() const throw () +{ + return signature; +} + +const String& BeeCertificate::getSigAlgName() const throw () +{ + return signature_algorithm; +} + +bool BeeCertificate::hasPublicKey() const +{ + for (fields_vector::const_iterator it = fields.begin(); it != fields.end(); it++) + { + switch ((*it)->type) + { + case PublicKeyField::FIELD_TYPE: + // do an extra check with dynamic_cast + if (dynamic_cast(*it)) + return true; + else + throw GeneralSecurityException("Somebody's trying to cheat with a new Field subclass"); + } + } + return false; +} + +bool BeeCertificate::hasParentCertificate() const +{ + for (fields_vector::const_iterator it = fields.begin(); it != fields.end(); it++) + { + switch ((*it)->type) + { + case ParentCertificateField::FIELD_TYPE: + // do an extra check with dynamic_cast + if (dynamic_cast(*it)) + return true; + else + throw GeneralSecurityException("Somebody's trying to cheat with a new Field subclass"); + } + } + return false; +} + +bytearray* BeeCertificate::encodeTBS() const +{ + ByteArrayOutputStream bos; + DataOutputStream dos(bos); + + dos.writeUTF(issuer); + dos.writeUTF(subject); + dos.writeLong(created.getTime()); + dos.writeLong(expires.getTime()); + dos.writeInt(fields.size()); + for (fields_vector::const_iterator it = fields.begin(); it != fields.end(); it++) + { + Field* f = (*it); + + dos.writeInt(f->type); + f->encode(dos); + } + + dos.close(); + bos.close(); + return bos.toByteArray(); +} + +BeeCertificate* BeeCertificate::self(const PublicKey& pub, const PrivateKey& pri, const String& signatureAlgorithm) throw (InvalidKeyException, NoSuchAlgorithmException) +{ + // if the public key doesn't have an encoding, it's not worth going through the effort + if (!pub.getEncoded()) + throw InvalidKeyException("PublicKey doesn't have an encoding"); + + Signature* sig = Signature::getInstance(signatureAlgorithm); + + try + { + sig->initSign(pri); + + BeeCertificate* cert = new BeeCertificate(); + + try + { + // issuer is kept blank + cert->subject = "PublicKey Certificate"; + cert->expires = FOREVER; + cert->signature_algorithm = signatureAlgorithm; + cert->fields.push_back(new PublicKeyField(pub)); + + bytearray* tmp = cert->encodeTBS(); + + try + { + sig->update(*tmp); + delete tmp; + } + catch (...) + { + delete tmp; + throw; + } + + sig->sign(cert->signature); + } + catch (...) + { + delete cert; + throw; + } + + delete sig; + + return cert; + } + catch (...) + { + delete sig; + throw; + } +} diff --git a/beecrypt/c++/beeyond/BeeCertificate.h b/beecrypt/c++/beeyond/BeeCertificate.h new file mode 100644 index 0000000..f89f13e --- /dev/null +++ b/beecrypt/c++/beeyond/BeeCertificate.h @@ -0,0 +1,186 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file BeeCertificate.h + * \ingroup CXX_BEEYOND_m + */ + +#ifndef _CLASS_BEECERTIFICATE_H +#define _CLASS_BEECERTIFICATE_H + +#ifdef __cplusplus + +#include "beecrypt/c++/array.h" +using beecrypt::array; +#include "beecrypt/c++/io/DataInputStream.h" +using beecrypt::io::DataInputStream; +#include "beecrypt/c++/io/DataOutputStream.h" +using beecrypt::io::DataOutputStream; +#include "beecrypt/c++/provider/BeeCertificateFactory.h" +using beecrypt::provider::BeeCertificateFactory; +#include "beecrypt/c++/security/PublicKey.h" +using beecrypt::security::PublicKey; +#include "beecrypt/c++/security/PrivateKey.h" +using beecrypt::security::PrivateKey; +#include "beecrypt/c++/security/cert/Certificate.h" +using beecrypt::security::cert::Certificate; +#include "beecrypt/c++/security/cert/CertificateExpiredException.h" +using beecrypt::security::cert::CertificateExpiredException; +#include "beecrypt/c++/security/cert/CertificateNotYetValidException.h" +using beecrypt::security::cert::CertificateNotYetValidException; +#include "beecrypt/c++/util/Date.h" +using beecrypt::util::Date; + +#include +using std::vector; + +namespace beecrypt { + namespace beeyond { + /* We use short certificate chains, embedded in the certificate as parent certificates + * Issuer is informational + * Subject is used to identify the type of certificate + */ + class BEECRYPTCXXAPI BeeCertificate : public Certificate + { + friend class BeeCertificateFactory; + + public: + static const Date FOREVER; + + protected: + struct Field + { + javaint type; + + virtual ~Field(); + + virtual Field* clone() const = 0; + + virtual void decode(DataInputStream&) throw (IOException) = 0; + virtual void encode(DataOutputStream&) const throw (IOException) = 0; + }; + + struct UnknownField : public Field + { + bytearray encoding; + + UnknownField(); + UnknownField(const UnknownField&); + virtual ~UnknownField(); + + virtual Field* clone() const; + + virtual void decode(DataInputStream&) throw (IOException); + virtual void encode(DataOutputStream&) const throw (IOException); + }; + + struct PublicKeyField : public Field + { + static const javaint FIELD_TYPE; + + PublicKey* pub; + + PublicKeyField(); + PublicKeyField(const PublicKey& key); + virtual ~PublicKeyField(); + + virtual Field* clone() const; + + virtual void decode(DataInputStream&) throw (IOException); + virtual void encode(DataOutputStream&) const throw (IOException); + }; + + struct ParentCertificateField : public Field + { + static const javaint FIELD_TYPE; + + Certificate* parent; + + ParentCertificateField(); + ParentCertificateField(const Certificate&); + virtual ~ParentCertificateField(); + + virtual Field* clone() const; + + virtual void decode(DataInputStream&) throw (IOException); + virtual void encode(DataOutputStream&) const throw (IOException); + }; + + virtual Field* instantiateField(javaint type); + + public: + typedef vector fields_vector; + typedef vector::iterator fields_iterator; + typedef vector::const_iterator fields_const_iterator; + + protected: + String issuer; + String subject; + Date created; + Date expires; + fields_vector fields; + String signature_algorithm; + bytearray signature; + + mutable bytearray* enc; + mutable String* str; + + BeeCertificate(); + BeeCertificate(InputStream& in) throw (IOException); + + bytearray* encodeTBS() const; + + public: + BeeCertificate(const BeeCertificate&); + virtual ~BeeCertificate(); + + virtual BeeCertificate* clone() const; + + virtual const bytearray& getEncoded() const; + virtual const PublicKey& getPublicKey() const; + + virtual void verify(const PublicKey&) throw (CertificateException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException); + virtual void verify(const PublicKey&, const String&) throw (CertificateException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException); + virtual const String& toString() const throw (); + + void checkValidity() const throw (CertificateExpiredException, CertificateNotYetValidException); + void checkValidity(const Date&) const throw (CertificateExpiredException, CertificateNotYetValidException); + + const String& getIssuer() const throw (); + const String& getSubject() const throw (); + + const Date& getNotAfter() const throw (); + const Date& getNotBefore() const throw (); + + const bytearray& getSignature() const throw (); + const String& getSigAlgName() const throw (); + + bool hasPublicKey() const; + bool hasParentCertificate() const; + + const Certificate& getParentCertificate() const; + + public: + static BeeCertificate* self(const PublicKey&, const PrivateKey&, const String& sigAlgName) throw (InvalidKeyException, NoSuchAlgorithmException); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/beeyond/BeeEncodedKeySpec.cxx b/beecrypt/c++/beeyond/BeeEncodedKeySpec.cxx new file mode 100644 index 0000000..54a1de4 --- /dev/null +++ b/beecrypt/c++/beeyond/BeeEncodedKeySpec.cxx @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#include "beecrypt/c++/beeyond/BeeEncodedKeySpec.h" + +using namespace beecrypt::beeyond; + +BeeEncodedKeySpec::BeeEncodedKeySpec(const byte* data, size_t size) : EncodedKeySpec(data, size) +{ +} + +BeeEncodedKeySpec::BeeEncodedKeySpec(const bytearray& copy) : EncodedKeySpec(copy) +{ +} + +BeeEncodedKeySpec::~BeeEncodedKeySpec() +{ +} + +const String& BeeEncodedKeySpec::getFormat() const throw () +{ + static const String* format = 0; + + if (!format) + format = new String("BEE"); + + return *format; +} diff --git a/beecrypt/c++/beeyond/BeeEncodedKeySpec.h b/beecrypt/c++/beeyond/BeeEncodedKeySpec.h new file mode 100644 index 0000000..09bf087 --- /dev/null +++ b/beecrypt/c++/beeyond/BeeEncodedKeySpec.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file BeeEncodedKeySpec.h + * \ingroup CXX_BEEYOND_m + */ + +#ifndef _CLASS_BEEENCODEDKEYSPEC_H +#define _CLASS_BEEENCODEDKEYSPEC_H + +#ifdef __cplusplus + +#include "beecrypt/c++/security/spec/EncodedKeySpec.h" +using beecrypt::security::spec::EncodedKeySpec; + +namespace beecrypt { + namespace beeyond { + class BEECRYPTCXXAPI BeeEncodedKeySpec : public EncodedKeySpec + { + public: + BeeEncodedKeySpec(const byte*, size_t); + BeeEncodedKeySpec(const bytearray&); + + virtual ~BeeEncodedKeySpec(); + + virtual const String& getFormat() const throw (); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/beeyond/BeeInputStream.cxx b/beecrypt/c++/beeyond/BeeInputStream.cxx new file mode 100644 index 0000000..7b7f9d4 --- /dev/null +++ b/beecrypt/c++/beeyond/BeeInputStream.cxx @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/beeyond/BeeInputStream.h" + +using namespace beecrypt::beeyond; + +BeeInputStream::BeeInputStream(InputStream& in) : DataInputStream(in) +{ +} + +BeeInputStream::~BeeInputStream() +{ +} + +void BeeInputStream::read(mpnumber& n) throw (IOException) +{ + int size = readInt(); + byte* data = new byte[size]; + + try + { + readFully(data, 0, size); + mpnsetbin(&n, data, size); + delete[] data; + } + catch (IOException) + { + // free buffer + delete[] data; + // re-throw exception + throw; + } +} + +void BeeInputStream::read(mpbarrett& b) throw (IOException) +{ + int size = readInt(); + byte* data = new byte[size]; + + try + { + readFully(data, 0, size); + mpbsetbin(&b, data, size); + delete[] data; + } + catch (IOException) + { + // free buffer + delete[] data; + // re-throw exception + throw; + } +} diff --git a/beecrypt/c++/beeyond/BeeInputStream.h b/beecrypt/c++/beeyond/BeeInputStream.h new file mode 100644 index 0000000..1825dc5 --- /dev/null +++ b/beecrypt/c++/beeyond/BeeInputStream.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file BeeInputStream.h + * \ingroup CXX_BEEYOND_m + */ + +#ifndef _CLASS_BEEINPUTSTREAM_H +#define _CLASS_BEEINPUTSTREAM_H + +#include "beecrypt/mpbarrett.h" + +#ifdef __cplusplus + +#include "beecrypt/c++/io/DataInputStream.h" +using beecrypt::io::DataInputStream; + +namespace beecrypt { + namespace beeyond { + class BEECRYPTCXXAPI BeeInputStream : public DataInputStream + { + public: + BeeInputStream(InputStream& in); + virtual ~BeeInputStream(); + + void read(mpnumber&) throw (IOException); + void read(mpbarrett&) throw (IOException); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/beeyond/BeeOutputStream.cxx b/beecrypt/c++/beeyond/BeeOutputStream.cxx new file mode 100644 index 0000000..cb0c4eb --- /dev/null +++ b/beecrypt/c++/beeyond/BeeOutputStream.cxx @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/beeyond/BeeOutputStream.h" + +using namespace beecrypt::beeyond; + +BeeOutputStream::BeeOutputStream(OutputStream& out) : DataOutputStream(out) +{ +} + +BeeOutputStream::~BeeOutputStream() +{ +} + +void BeeOutputStream::write(const mpnumber& n) throw (IOException) +{ + size_t bits = n.bitlength(); + size_t length = ((bits + 7) >> 3) + (((bits & 7) == 0) ? 1 : 0); + + byte* buffer = new byte[length]; + + try + { + i2osp(buffer, length, n.data, n.size); + + DataOutputStream::writeInt(length); + DataOutputStream::write(buffer, 0, length); + + delete[] buffer; + } + catch (IOException) + { + delete[] buffer; + throw; + } +} + +void BeeOutputStream::write(const mpbarrett& b) throw (IOException) +{ + size_t bits = b.bitlength(); + size_t length = ((bits + 7) >> 3) + (((bits & 7) == 0) ? 1 : 0); + + byte* buffer = new byte[length]; + + try + { + i2osp(buffer, length, b.modl, b.size); + + DataOutputStream::writeInt(length); + DataOutputStream::write(buffer, 0, length); + + delete[] buffer; + } + catch (IOException) + { + delete[] buffer; + throw; + } +} diff --git a/beecrypt/c++/beeyond/BeeOutputStream.h b/beecrypt/c++/beeyond/BeeOutputStream.h new file mode 100644 index 0000000..c6ce4e2 --- /dev/null +++ b/beecrypt/c++/beeyond/BeeOutputStream.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file BeeOutputStream.h + * \ingroup CXX_BEEYOND_m + */ + +#ifndef _CLASS_BEEOUTPUTSTREAM_H +#define _CLASS_BEEOUTPUTSTREAM_H + +#include "beecrypt/mpbarrett.h" + +#ifdef __cplusplus + +#include "beecrypt/c++/io/DataOutputStream.h" +using beecrypt::io::DataOutputStream; + +namespace beecrypt { + namespace beeyond { + class BEECRYPTCXXAPI BeeOutputStream : public DataOutputStream + { + public: + BeeOutputStream(OutputStream& out); + virtual ~BeeOutputStream(); + + void write(const mpnumber&) throw (IOException); + void write(const mpbarrett&) throw (IOException); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/beeyond/Makefile.am b/beecrypt/c++/beeyond/Makefile.am new file mode 100644 index 0000000..098d13f --- /dev/null +++ b/beecrypt/c++/beeyond/Makefile.am @@ -0,0 +1,30 @@ +INCLUDES = -I$(top_srcdir)/.. + +LIBS = -licuuc -licuio + +AUTOMAKE_OPTIONS = gnu no-dependencies + +noinst_LTLIBRARIES = libcxxbeeyond.la + +libcxxbeeyond_la_SOURCES = \ +AnyEncodedKeySpec.cxx \ +BeeCertificate.cxx \ +BeeEncodedKeySpec.cxx \ +BeeInputStream.cxx \ +BeeOutputStream.cxx \ +PKCS12PBEKey.cxx + +noinst_HEADERS = \ +AnyEncodedKeySpec.h \ +BeeCertificate.h \ +BeeEncodedKeySpec.h \ +BeeInputStream.h \ +BeeOutputStream.h \ +PKCS12PBEKey.h + +TESTS = testcert + +check_PROGRAMS = testcert + +testcert_SOURCES = testcert.cxx +testcert_LDADD = ../libbeecrypt_cxx.la diff --git a/beecrypt/c++/beeyond/Makefile.in b/beecrypt/c++/beeyond/Makefile.in new file mode 100644 index 0000000..6047903 --- /dev/null +++ b/beecrypt/c++/beeyond/Makefile.in @@ -0,0 +1,569 @@ +# Makefile.in generated by automake 1.8.3 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + + +SOURCES = $(libcxxbeeyond_la_SOURCES) $(testcert_SOURCES) + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +top_builddir = ../.. +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +INSTALL = @INSTALL@ +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +host_triplet = @host@ +check_PROGRAMS = testcert$(EXEEXT) +subdir = c++/beeyond +DIST_COMMON = $(noinst_HEADERS) $(srcdir)/Makefile.am \ + $(srcdir)/Makefile.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \ + $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +LTLIBRARIES = $(noinst_LTLIBRARIES) +libcxxbeeyond_la_LIBADD = +am_libcxxbeeyond_la_OBJECTS = AnyEncodedKeySpec.lo BeeCertificate.lo \ + BeeEncodedKeySpec.lo BeeInputStream.lo BeeOutputStream.lo \ + PKCS12PBEKey.lo +libcxxbeeyond_la_OBJECTS = $(am_libcxxbeeyond_la_OBJECTS) +am_testcert_OBJECTS = testcert.$(OBJEXT) +testcert_OBJECTS = $(am_testcert_OBJECTS) +testcert_DEPENDENCIES = ../libbeecrypt_cxx.la +DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir) +depcomp = +am__depfiles_maybe = +CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) +LTCXXCOMPILE = $(LIBTOOL) --mode=compile $(CXX) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CXXFLAGS) $(CXXFLAGS) +CXXLD = $(CXX) +CXXLINK = $(LIBTOOL) --mode=link $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) \ + $(AM_LDFLAGS) $(LDFLAGS) -o $@ +SOURCES = $(libcxxbeeyond_la_SOURCES) $(testcert_SOURCES) +DIST_SOURCES = $(libcxxbeeyond_la_SOURCES) $(testcert_SOURCES) +HEADERS = $(noinst_HEADERS) +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMDEP_FALSE = @AMDEP_FALSE@ +AMDEP_TRUE = @AMDEP_TRUE@ +AMTAR = @AMTAR@ +AR = @AR@ +AS = @AS@ +ASM_ALIGN = @ASM_ALIGN@ +ASM_ARCH = @ASM_ARCH@ +ASM_BIGENDIAN = @ASM_BIGENDIAN@ +ASM_CPU = @ASM_CPU@ +ASM_GLOBL = @ASM_GLOBL@ +ASM_GSYM_PREFIX = @ASM_GSYM_PREFIX@ +ASM_LSYM_PREFIX = @ASM_LSYM_PREFIX@ +ASM_OS = @ASM_OS@ +ASM_TEXTSEG = @ASM_TEXTSEG@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCAS = @CCAS@ +CCASFLAGS = @CCASFLAGS@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DLLTOOL = @DLLTOOL@ +ECHO = @ECHO@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +F77 = @F77@ +FFLAGS = @FFLAGS@ +INCLUDE_DLFCN_H = @INCLUDE_DLFCN_H@ +INCLUDE_INTTYPES_H = @INCLUDE_INTTYPES_H@ +INCLUDE_MALLOC_H = @INCLUDE_MALLOC_H@ +INCLUDE_PTHREAD_H = @INCLUDE_PTHREAD_H@ +INCLUDE_STDINT_H = @INCLUDE_STDINT_H@ +INCLUDE_STDIO_H = @INCLUDE_STDIO_H@ +INCLUDE_STDLIB_H = @INCLUDE_STDLIB_H@ +INCLUDE_STRING_H = @INCLUDE_STRING_H@ +INCLUDE_SYNCH_H = @INCLUDE_SYNCH_H@ +INCLUDE_THREAD_H = @INCLUDE_THREAD_H@ +INCLUDE_UNISTD_H = @INCLUDE_UNISTD_H@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +JAVAINC = @JAVAINC@ +LDFLAGS = @LDFLAGS@ +LIBALT = @LIBALT@ +LIBOBJS = @LIBOBJS@ +LIBS = -licuuc -licuio +LIBTOOL = @LIBTOOL@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +MAYBE_LTLIB = @MAYBE_LTLIB@ +MAYBE_SUB = @MAYBE_SUB@ +MP_WBITS = @MP_WBITS@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PYTHONINC = @PYTHONINC@ +PYTHONLIB = @PYTHONLIB@ +RANLIB = @RANLIB@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +TYPEDEF_BC_COND_T = @TYPEDEF_BC_COND_T@ +TYPEDEF_BC_MUTEX_T = @TYPEDEF_BC_MUTEX_T@ +TYPEDEF_BC_THREAD_T = @TYPEDEF_BC_THREAD_T@ +TYPEDEF_INT16_T = @TYPEDEF_INT16_T@ +TYPEDEF_INT32_T = @TYPEDEF_INT32_T@ +TYPEDEF_INT64_T = @TYPEDEF_INT64_T@ +TYPEDEF_INT8_T = @TYPEDEF_INT8_T@ +TYPEDEF_SIZE_T = @TYPEDEF_SIZE_T@ +TYPEDEF_UINT16_T = @TYPEDEF_UINT16_T@ +TYPEDEF_UINT32_T = @TYPEDEF_UINT32_T@ +TYPEDEF_UINT64_T = @TYPEDEF_UINT64_T@ +TYPEDEF_UINT8_T = @TYPEDEF_UINT8_T@ +VERSION = @VERSION@ +ac_ct_AR = @ac_ct_AR@ +ac_ct_AS = @ac_ct_AS@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DLLTOOL = @ac_ct_DLLTOOL@ +ac_ct_F77 = @ac_ct_F77@ +ac_ct_OBJDUMP = @ac_ct_OBJDUMP@ +ac_ct_RANLIB = @ac_ct_RANLIB@ +ac_ct_STRIP = @ac_ct_STRIP@ +ac_cv_have_gcj = @ac_cv_have_gcj@ +ac_cv_have_java = @ac_cv_have_java@ +ac_cv_have_javac = @ac_cv_have_javac@ +ac_cv_have_python = @ac_cv_have_python@ +am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ +am__fastdepCC_TRUE = @am__fastdepCC_TRUE@ +am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@ +am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +datadir = @datadir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +sysconfdir = @sysconfdir@ +target = @target@ +target_alias = @target_alias@ +target_cpu = @target_cpu@ +target_os = @target_os@ +target_vendor = @target_vendor@ +INCLUDES = -I$(top_srcdir)/.. +AUTOMAKE_OPTIONS = gnu no-dependencies +noinst_LTLIBRARIES = libcxxbeeyond.la +libcxxbeeyond_la_SOURCES = \ +AnyEncodedKeySpec.cxx \ +BeeCertificate.cxx \ +BeeEncodedKeySpec.cxx \ +BeeInputStream.cxx \ +BeeOutputStream.cxx \ +PKCS12PBEKey.cxx + +noinst_HEADERS = \ +AnyEncodedKeySpec.h \ +BeeCertificate.h \ +BeeEncodedKeySpec.h \ +BeeInputStream.h \ +BeeOutputStream.h \ +PKCS12PBEKey.h + +TESTS = testcert +testcert_SOURCES = testcert.cxx +testcert_LDADD = ../libbeecrypt_cxx.la +all: all-am + +.SUFFIXES: +.SUFFIXES: .cxx .lo .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ + && exit 0; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu c++/beeyond/Makefile'; \ + cd $(top_srcdir) && \ + $(AUTOMAKE) --gnu c++/beeyond/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +clean-noinstLTLIBRARIES: + -test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES) + @list='$(noinst_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" = "$$p" && dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +libcxxbeeyond.la: $(libcxxbeeyond_la_OBJECTS) $(libcxxbeeyond_la_DEPENDENCIES) + $(CXXLINK) $(libcxxbeeyond_la_LDFLAGS) $(libcxxbeeyond_la_OBJECTS) $(libcxxbeeyond_la_LIBADD) $(LIBS) + +clean-checkPROGRAMS: + @list='$(check_PROGRAMS)'; for p in $$list; do \ + f=`echo $$p|sed 's/$(EXEEXT)$$//'`; \ + echo " rm -f $$p $$f"; \ + rm -f $$p $$f ; \ + done +testcert$(EXEEXT): $(testcert_OBJECTS) $(testcert_DEPENDENCIES) + @rm -f testcert$(EXEEXT) + $(CXXLINK) $(testcert_LDFLAGS) $(testcert_OBJECTS) $(testcert_LDADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +.cxx.o: + $(CXXCOMPILE) -c -o $@ $< + +.cxx.obj: + $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +.cxx.lo: + $(LTCXXCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +distclean-libtool: + -rm -f libtool +uninstall-info-am: + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(ETAGS_ARGS)$$tags$$unique" \ + || $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$tags $$unique +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(CTAGS_ARGS)$$tags$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$tags $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && cd $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) $$here + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +check-TESTS: $(TESTS) + @failed=0; all=0; xfail=0; xpass=0; skip=0; \ + srcdir=$(srcdir); export srcdir; \ + list='$(TESTS)'; \ + if test -n "$$list"; then \ + for tst in $$list; do \ + if test -f ./$$tst; then dir=./; \ + elif test -f $$tst; then dir=; \ + else dir="$(srcdir)/"; fi; \ + if $(TESTS_ENVIRONMENT) $${dir}$$tst; then \ + all=`expr $$all + 1`; \ + case " $(XFAIL_TESTS) " in \ + *" $$tst "*) \ + xpass=`expr $$xpass + 1`; \ + failed=`expr $$failed + 1`; \ + echo "XPASS: $$tst"; \ + ;; \ + *) \ + echo "PASS: $$tst"; \ + ;; \ + esac; \ + elif test $$? -ne 77; then \ + all=`expr $$all + 1`; \ + case " $(XFAIL_TESTS) " in \ + *" $$tst "*) \ + xfail=`expr $$xfail + 1`; \ + echo "XFAIL: $$tst"; \ + ;; \ + *) \ + failed=`expr $$failed + 1`; \ + echo "FAIL: $$tst"; \ + ;; \ + esac; \ + else \ + skip=`expr $$skip + 1`; \ + echo "SKIP: $$tst"; \ + fi; \ + done; \ + if test "$$failed" -eq 0; then \ + if test "$$xfail" -eq 0; then \ + banner="All $$all tests passed"; \ + else \ + banner="All $$all tests behaved as expected ($$xfail expected failures)"; \ + fi; \ + else \ + if test "$$xpass" -eq 0; then \ + banner="$$failed of $$all tests failed"; \ + else \ + banner="$$failed of $$all tests did not behave as expected ($$xpass unexpected passes)"; \ + fi; \ + fi; \ + dashes="$$banner"; \ + skipped=""; \ + if test "$$skip" -ne 0; then \ + skipped="($$skip tests were not run)"; \ + test `echo "$$skipped" | wc -c` -gt `echo "$$banner" | wc -c` && \ + dashes="$$skipped"; \ + fi; \ + report=""; \ + if test "$$failed" -ne 0 && test -n "$(PACKAGE_BUGREPORT)"; then \ + report="Please report to $(PACKAGE_BUGREPORT)"; \ + test `echo "$$report" | wc -c` -gt `echo "$$banner" | wc -c` && \ + dashes="$$report"; \ + fi; \ + dashes=`echo "$$dashes" | sed s/./=/g`; \ + echo "$$dashes"; \ + echo "$$banner"; \ + test -n "$$skipped" && echo "$$skipped"; \ + test -n "$$report" && echo "$$report"; \ + echo "$$dashes"; \ + test "$$failed" -eq 0; \ + else :; fi + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \ + list='$(DISTFILES)'; for file in $$list; do \ + case $$file in \ + $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \ + $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \ + esac; \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test "$$dir" != "$$file" && test "$$dir" != "."; then \ + dir="/$$dir"; \ + $(mkdir_p) "$(distdir)$$dir"; \ + else \ + dir=''; \ + fi; \ + if test -d $$d/$$file; then \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + fi; \ + cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ + else \ + test -f $(distdir)/$$file \ + || cp -p $$d/$$file $(distdir)/$$file \ + || exit 1; \ + fi; \ + done +check-am: all-am + $(MAKE) $(AM_MAKEFLAGS) $(check_PROGRAMS) + $(MAKE) $(AM_MAKEFLAGS) check-TESTS +check: check-am +all-am: Makefile $(LTLIBRARIES) $(HEADERS) +installdirs: +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -rm -f $(CONFIG_CLEAN_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-checkPROGRAMS clean-generic clean-libtool \ + clean-noinstLTLIBRARIES mostlyclean-am + +distclean: distclean-am + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-libtool distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +info: info-am + +info-am: + +install-data-am: + +install-exec-am: + +install-info: install-info-am + +install-man: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-info-am + +.PHONY: CTAGS GTAGS all all-am check check-TESTS check-am clean \ + clean-checkPROGRAMS clean-generic clean-libtool \ + clean-noinstLTLIBRARIES ctags distclean distclean-compile \ + distclean-generic distclean-libtool distclean-tags distdir dvi \ + dvi-am html html-am info info-am install install-am \ + install-data install-data-am install-exec install-exec-am \ + install-info install-info-am install-man install-strip \ + installcheck installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags uninstall uninstall-am uninstall-info-am + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/beecrypt/c++/beeyond/PKCS12PBEKey.cxx b/beecrypt/c++/beeyond/PKCS12PBEKey.cxx new file mode 100644 index 0000000..f7ad0cb --- /dev/null +++ b/beecrypt/c++/beeyond/PKCS12PBEKey.cxx @@ -0,0 +1,86 @@ +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/beeyond/PKCS12PBEKey.h" + +#include +using std::cout; +using std::endl; + +using namespace beecrypt::beeyond; + +PKCS12PBEKey::PKCS12PBEKey(const array& password, const bytearray* salt, size_t iterationCount) : _pswd(password) +{ + if (salt) + _salt = new bytearray(*salt); + else + _salt = 0; + _iter = iterationCount; + _enc = 0; +} + +PKCS12PBEKey::~PKCS12PBEKey() +{ + if (_salt) + delete _salt; +} + +PKCS12PBEKey* PKCS12PBEKey::clone() const +{ + return new PKCS12PBEKey(_pswd, _salt, _iter); +} + +bytearray* PKCS12PBEKey::encode(const array& password, const bytearray* salt, size_t iterationCount) +{ + size_t i; + + bytearray* result = new bytearray((password.size() + 1) * 2); + + for (i = 0; i < password.size(); i++) + { + (*result)[2*i ] = (password[i] >> 8) & 0xff; + (*result)[2*i+1] = (password[i] ) & 0xff; + } + (*result)[2*i ] = 0; + (*result)[2*i+1] = 0; + + return result; +} + +size_t PKCS12PBEKey::getIterationCount() const throw () +{ + return _iter; +} + +const array& PKCS12PBEKey::getPassword() const throw () +{ + return _pswd; +} + +const bytearray* PKCS12PBEKey::getSalt() const throw () +{ + return _salt; +} + +const bytearray* PKCS12PBEKey::getEncoded() const +{ + if (!_enc) + _enc = encode(_pswd, _salt, _iter); + + return _enc; +} + +const String& PKCS12PBEKey::getAlgorithm() const throw () +{ + static const String ALGORITHM = UNICODE_STRING_SIMPLE("PKCS#12/PBE"); + return ALGORITHM; +} + +const String* PKCS12PBEKey::getFormat() const throw () +{ + static const String FORMAT = UNICODE_STRING_SIMPLE("RAW"); + return &FORMAT; +} diff --git a/beecrypt/c++/beeyond/PKCS12PBEKey.h b/beecrypt/c++/beeyond/PKCS12PBEKey.h new file mode 100644 index 0000000..8aacf27 --- /dev/null +++ b/beecrypt/c++/beeyond/PKCS12PBEKey.h @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file PKCS12PBEKey.h + * \ingroup CXX_BEEYOND_m + */ + +#ifndef _CLASS_PKCS12PBEKEY_H +#define _CLASS_PKCS12PBEKEY_H + +#ifdef __cplusplus + +#include "beecrypt/c++/array.h" +using beecrypt::array; +using beecrypt::bytearray; +#include "beecrypt/c++/crypto/interfaces/PBEKey.h" +using beecrypt::crypto::interfaces::PBEKey; + +namespace beecrypt { + namespace beeyond { + class BEECRYPTCXXAPI PKCS12PBEKey : public PBEKey + { + private: + array _pswd; + bytearray* _salt; + size_t _iter; + mutable bytearray* _enc; + + public: + static bytearray* encode(const array&, const bytearray*, size_t); + + public: + PKCS12PBEKey(const array&, const bytearray*, size_t); + virtual ~PKCS12PBEKey(); + + virtual PKCS12PBEKey* clone() const; + + virtual size_t getIterationCount() const throw (); + virtual const array& getPassword() const throw (); + virtual const bytearray* getSalt() const throw (); + + virtual const bytearray* getEncoded() const; + + virtual const String& getAlgorithm() const throw(); + virtual const String* getFormat() const throw (); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/beeyond/testcert.cxx b/beecrypt/c++/beeyond/testcert.cxx new file mode 100644 index 0000000..eecc4e5 --- /dev/null +++ b/beecrypt/c++/beeyond/testcert.cxx @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "c++/bstream.h" +#include "c++/beeyond/BeeCertificate.h" +using beecrypt::beeyond::BeeCertificate; +#include "c++/io/ByteArrayInputStream.h" +using beecrypt::io::ByteArrayInputStream; +#include "c++/security/AlgorithmParameterGenerator.h" +using beecrypt::security::AlgorithmParameterGenerator; +#include "c++/security/AlgorithmParameters.h" +using beecrypt::security::AlgorithmParameters; +#include "c++/security/KeyFactory.h" +using beecrypt::security::KeyFactory; +#include "c++/security/KeyPairGenerator.h" +using beecrypt::security::KeyPairGenerator; +#include "c++/security/Signature.h" +using beecrypt::security::Signature; +#include "c++/security/cert/CertificateFactory.h" +using beecrypt::security::cert::CertificateFactory; +#include "c++/security/spec/EncodedKeySpec.h" +using beecrypt::security::spec::EncodedKeySpec; + +#include +using namespace std; +#include + +int main(int argc, char* argv[]) +{ + int failures = 0; + + try + { + KeyPairGenerator* kpg = KeyPairGenerator::getInstance("DSA"); + + kpg->initialize(1024); + + KeyPair* pair = kpg->generateKeyPair(); + + cout << "keypair generated" << endl << flush; + + BeeCertificate* self = BeeCertificate::self(pair->getPublic(), pair->getPrivate(), "SHA1withDSA"); + + cout << "self generated" << endl << flush; + + ByteArrayInputStream bis(self->getEncoded()); + + CertificateFactory* cf = CertificateFactory::getInstance("BEE"); + + cout << "got cf" << endl << flush; + + Certificate* cert = cf->generateCertificate(bis); + + cout << "verifying" << endl << flush; + + cert->verify(pair->getPublic()); + + cout << "verified" << endl << flush; + + if (!(*cert == *self)) + { + cerr << "certificates differ" << endl; + failures++; + } + else + cout << "certificates equal" << endl << flush; + + delete cert; + delete cf; + delete self; + delete pair; + delete kpg; + } + catch (Exception& ex) + { + std::cerr << "exception: " << ex.getMessage(); + std::cerr << " type " << typeid(ex).name() << std::endl; + failures++; + } + catch (...) + { + std::cerr << "exception" << std::endl; + failures++; + } + return failures; +} diff --git a/beecrypt/c++/bstream.cxx b/beecrypt/c++/bstream.cxx new file mode 100644 index 0000000..2c345c7 --- /dev/null +++ b/beecrypt/c++/bstream.cxx @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#include "beecrypt/c++/bstream.h" + +#include "beecrypt/c++/crypto/interfaces/DHPublicKey.h" +using beecrypt::crypto::interfaces::DHPublicKey; +#include "beecrypt/c++/security/interfaces/DSAPublicKey.h" +using beecrypt::security::interfaces::DSAPublicKey; +#include "beecrypt/c++/security/interfaces/RSAPublicKey.h" +using beecrypt::security::interfaces::RSAPublicKey; + +#include + +using namespace beecrypt; + +ostream& operator<<(ostream& stream, const PublicKey& pub) +{ + stream << pub.getAlgorithm() << " public key" << endl; + + const DHPublicKey* dh = dynamic_cast(&pub); + if (dh) + { + return stream << "P = " << dh->getParams().getP() << endl << + "G = " << dh->getParams().getG() << endl << + "Y = " << dh->getY() << endl; + } + + const DSAPublicKey* dsa = dynamic_cast(&pub); + if (dsa) + { + return stream << "P = " << dsa->getParams().getP() << endl << + "Q = " << dsa->getParams().getQ() << endl << + "G = " << dsa->getParams().getG() << endl << + "Y = " << dsa->getY() << endl; + } + + const RSAPublicKey* rsa = dynamic_cast(&pub); + if (rsa) + { + return stream << "N = " << rsa->getModulus() << endl << + "E = " << rsa->getPublicExponent() << endl; + } + + return stream; +} diff --git a/beecrypt/c++/bstream.h b/beecrypt/c++/bstream.h new file mode 100644 index 0000000..a31f84d --- /dev/null +++ b/beecrypt/c++/bstream.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file bstream.h + * \brief C++ Object-to-stream output. + * \author Bob Deblier + */ + +#ifndef _BEECRYPT_STREAM_H +#define _BEECRYPT_STREAM_H + +#include "beecrypt/api.h" + +#ifdef __cplusplus + +#include +using std::cout; +using std::ostream; +using std::endl; + +#include "beecrypt/c++/security/PublicKey.h" +using beecrypt::security::PublicKey; + +namespace beecrypt { + BEECRYPTCXXAPI + ostream& operator<<(ostream& stream, const PublicKey&); +} + +#endif + +#endif diff --git a/beecrypt/c++/crypto/BadPaddingException.cxx b/beecrypt/c++/crypto/BadPaddingException.cxx new file mode 100644 index 0000000..eea765f --- /dev/null +++ b/beecrypt/c++/crypto/BadPaddingException.cxx @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/crypto/BadPaddingException.h" + +using namespace beecrypt::crypto; + +BadPaddingException::BadPaddingException() throw () +{ +} + +BadPaddingException::BadPaddingException(const String& message) throw () : GeneralSecurityException(message) +{ +} diff --git a/beecrypt/c++/crypto/BadPaddingException.h b/beecrypt/c++/crypto/BadPaddingException.h new file mode 100644 index 0000000..c938606 --- /dev/null +++ b/beecrypt/c++/crypto/BadPaddingException.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file BadPaddingException.h + * \ingroup CXX_CRYPTO_m + */ + +#ifndef _CLASS_BADPADDINGEXCEPTION_H +#define _CLASS_BADPADDINGEXCEPTION_H + +#ifdef __cplusplus + +#include "beecrypt/c++/security/GeneralSecurityException.h" +using beecrypt::security::GeneralSecurityException; + +namespace beecrypt { + namespace crypto { + class BEECRYPTCXXAPI BadPaddingException : public GeneralSecurityException + { + public: + BadPaddingException() throw (); + BadPaddingException(const String&) throw (); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/crypto/Mac.cxx b/beecrypt/c++/crypto/Mac.cxx new file mode 100644 index 0000000..ccb83d1 --- /dev/null +++ b/beecrypt/c++/crypto/Mac.cxx @@ -0,0 +1,180 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/crypto/Mac.h" +#include "beecrypt/c++/lang/IllegalArgumentException.h" +using beecrypt::lang::IllegalArgumentException; +#include "beecrypt/c++/security/Security.h" +using beecrypt::security::Security; + +using namespace beecrypt::crypto; + +Mac::Mac(MacSpi* spi, const String& algorithm, const Provider& provider) +{ + _mspi = spi; + _algo = algorithm; + _prov = &provider; + _init = false; +} + +Mac::~Mac() +{ + delete _mspi; +} + +Mac* Mac::getInstance(const String& algorithm) throw (NoSuchAlgorithmException) +{ + Security::spi* tmp = Security::getSpi(algorithm, "Mac"); + + Mac* result = new Mac((MacSpi*) tmp->cspi, tmp->name, tmp->prov); + + delete tmp; + + return result; +} + +Mac* Mac::getInstance(const String& algorithm, const String& provider) throw (NoSuchAlgorithmException, NoSuchProviderException) +{ + Security::spi* tmp = Security::getSpi(algorithm, "Mac", provider); + + Mac* result = new Mac((MacSpi*) tmp->cspi, tmp->name, tmp->prov); + + delete tmp; + + return result; +} + +Mac* Mac::getInstance(const String& algorithm, const Provider& provider) throw (NoSuchAlgorithmException) +{ + Security::spi* tmp = Security::getSpi(algorithm, "Mac", provider); + + Mac* result = new Mac((MacSpi*) tmp->cspi, tmp->name, tmp->prov); + + delete tmp; + + return result; +} + +Mac* Mac::clone() const +{ + MacSpi* _mspc = _mspi->clone(); + + if (_mspc) + { + // don't forget to also clone the _init state! + Mac* result = new Mac(_mspc, _algo, *_prov); + result->_init = _init; + return result; + } + else + return 0; +} + +const bytearray& Mac::doFinal() throw (IllegalStateException) +{ + if (!_init) + throw IllegalStateException(); + + return _mspi->engineDoFinal(); +} + +const bytearray& Mac::doFinal(const bytearray& b) throw (IllegalStateException) +{ + if (!_init) + throw IllegalStateException(); + + _mspi->engineUpdate(b.data(), 0, b.size()); + return _mspi->engineDoFinal(); +} + +size_t Mac::doFinal(byte* data, size_t offset, size_t length) throw (IllegalStateException, ShortBufferException) +{ + if (!_init) + throw IllegalStateException(); + + return _mspi->engineDoFinal(data, offset, length); +} + +size_t Mac::getMacLength() +{ + return _mspi->engineGetMacLength(); +} + +void Mac::init(const Key& key) throw (InvalidKeyException) +{ + try + { + _mspi->engineInit(key, 0); + } + catch (InvalidAlgorithmParameterException) + { + throw IllegalArgumentException("Mac apparently requires an AlgorithmParameterSpec"); + } + _init = true; +} + +void Mac::init(const Key& key, const AlgorithmParameterSpec* spec) throw (InvalidKeyException, InvalidAlgorithmParameterException) +{ + _mspi->engineInit(key, spec); + _init = true; +} + +void Mac::reset() +{ + _mspi->engineReset(); +} + +void Mac::update(byte b) throw (IllegalStateException) +{ + if (!_init) + throw IllegalStateException(); + + _mspi->engineUpdate(b); +} + +void Mac::update(const bytearray& b) throw (IllegalStateException) +{ + if (!_init) + throw IllegalStateException(); + + _mspi->engineUpdate(b.data(), 0, b.size()); +} + +void Mac::update(const byte* data, size_t offset, size_t length) throw (IllegalStateException) +{ + if (!_init) + throw IllegalStateException(); + + _mspi->engineUpdate(data, offset, length); +} + +const String& Mac::getAlgorithm() const throw () +{ + return _algo; +} + +const Provider& Mac::getProvider() const throw () +{ + return *_prov; +} diff --git a/beecrypt/c++/crypto/Mac.h b/beecrypt/c++/crypto/Mac.h new file mode 100644 index 0000000..2d790d2 --- /dev/null +++ b/beecrypt/c++/crypto/Mac.h @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file Mac.h + * \ingroup CXX_CRYPTO_m + */ + +#ifndef _CLASS_MAC_H +#define _CLASS_MAC_H + +// #include "beecrypt/beecrypt.api.h" + +#ifdef __cplusplus + +#include "beecrypt/c++/crypto/MacSpi.h" +using beecrypt::crypto::MacSpi; +#include "beecrypt/c++/security/Provider.h" +using beecrypt::security::Provider; +#include "beecrypt/c++/security/NoSuchAlgorithmException.h" +using beecrypt::security::NoSuchAlgorithmException; +#include "beecrypt/c++/security/NoSuchProviderException.h" +using beecrypt::security::NoSuchProviderException; + +namespace beecrypt { + namespace crypto { + class BEECRYPTCXXAPI Mac + { + public: + static Mac* getInstance(const String&) throw (NoSuchAlgorithmException); + static Mac* getInstance(const String&, const String&) throw (NoSuchAlgorithmException, NoSuchProviderException); + static Mac* getInstance(const String&, const Provider&) throw (NoSuchAlgorithmException); + + private: + MacSpi* _mspi; + String _algo; + const Provider* _prov; + bool _init; + + protected: + Mac(MacSpi*, const String&, const Provider&); + + public: + ~Mac(); + + Mac* clone() const; + + const bytearray& doFinal() throw (IllegalStateException); + const bytearray& doFinal(const bytearray&) throw (IllegalStateException); + size_t doFinal(byte* data, size_t offset, size_t length) throw (ShortBufferException, IllegalStateException); + size_t getMacLength(); + void init(const Key&) throw (InvalidKeyException); + void init(const Key&, const AlgorithmParameterSpec*) throw (InvalidKeyException, InvalidAlgorithmParameterException); + void reset(); + void update(byte) throw (IllegalStateException); + void update(const byte* data, size_t offset, size_t length) throw (IllegalStateException); + void update(const bytearray&) throw (IllegalStateException); + + const String& getAlgorithm() const throw (); + const Provider& getProvider() const throw (); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/crypto/MacInputStream.cxx b/beecrypt/c++/crypto/MacInputStream.cxx new file mode 100644 index 0000000..7d924ec --- /dev/null +++ b/beecrypt/c++/crypto/MacInputStream.cxx @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/crypto/MacInputStream.h" +#include "beecrypt/c++/lang/NullPointerException.h" +using beecrypt::lang::NullPointerException; + +using namespace beecrypt::crypto; + +MacInputStream::MacInputStream(InputStream& in, Mac& m) : FilterInputStream(in), mac(m) +{ + _on = true; +} + +MacInputStream::~MacInputStream() +{ +} + +int MacInputStream::read() throw (IOException) +{ + int rc = in.read(); + if (rc >= 0 && _on) + mac.update((byte) rc); + return rc; +} + +int MacInputStream::read(byte *data, size_t offset, size_t length) throw (IOException) +{ + if (!data) + throw NullPointerException(); + + int rc = in.read(data, offset, length); + if (rc >= 0 && _on) + mac.update(data, offset, rc); + return rc; +} + +void MacInputStream::on(bool on) +{ + _on = on; +} + +Mac& MacInputStream::getMac() +{ + return mac; +} + +void MacInputStream::setMac(Mac& m) +{ + mac = m; +} diff --git a/beecrypt/c++/crypto/MacInputStream.h b/beecrypt/c++/crypto/MacInputStream.h new file mode 100644 index 0000000..0b3700c --- /dev/null +++ b/beecrypt/c++/crypto/MacInputStream.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file MacInputStream.h + * \ingroup CXX_CRYPTO_m + */ + +#ifndef _CLASS_MACINPUTSTREAM_H +#define _CLASS_MACINPUTSTREAM_H + +#ifdef __cplusplus + +#include "beecrypt/c++/crypto/Mac.h" +using beecrypt::crypto::Mac; +#include "beecrypt/c++/io/FilterInputStream.h" +using beecrypt::io::FilterInputStream; + +namespace beecrypt { + namespace crypto { + class BEECRYPTCXXAPI MacInputStream : public FilterInputStream + { + private: + bool _on; + + protected: + Mac& mac; + + public: + MacInputStream(InputStream&, Mac&); + virtual ~MacInputStream(); + + virtual int read() throw (IOException); + virtual int read(byte* data, size_t offset, size_t length) throw (IOException); + + void on(bool); + + Mac& getMac(); + void setMac(Mac&); + + }; + } +} + +#endif + +#endif + diff --git a/beecrypt/c++/crypto/MacOutputStream.cxx b/beecrypt/c++/crypto/MacOutputStream.cxx new file mode 100644 index 0000000..976deb8 --- /dev/null +++ b/beecrypt/c++/crypto/MacOutputStream.cxx @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/crypto/MacOutputStream.h" +#include "beecrypt/c++/lang/NullPointerException.h" +using beecrypt::lang::NullPointerException; + +using namespace beecrypt::crypto; + +MacOutputStream::MacOutputStream(OutputStream& out, Mac& m) : FilterOutputStream(out), mac(m) +{ + _on = true; +} + +MacOutputStream::~MacOutputStream() +{ +} + +void MacOutputStream::write(byte b) throw (IOException) +{ + out.write(b); + if (_on) + mac.update(b); +} + +void MacOutputStream::write(const byte *data, size_t offset, size_t length) throw (IOException) +{ + if (!data) + throw NullPointerException(); + + out.write(data, offset, length); + if (_on) + mac.update(data, offset, length); +} + +void MacOutputStream::on(bool on) +{ + _on = on; +} + +Mac& MacOutputStream::getMac() +{ + return mac; +} + +void MacOutputStream::setMac(Mac& m) +{ + mac = m; +} diff --git a/beecrypt/c++/crypto/MacOutputStream.h b/beecrypt/c++/crypto/MacOutputStream.h new file mode 100644 index 0000000..ff82563 --- /dev/null +++ b/beecrypt/c++/crypto/MacOutputStream.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file MacOutputStream.h + * \ingroup CXX_CRYPTO_m + */ + +#ifndef _CLASS_MACOUTPUTSTREAM_H +#define _CLASS_MACOUTPUTSTREAM_H + +#ifdef __cplusplus + +#include "beecrypt/c++/crypto/Mac.h" +using beecrypt::crypto::Mac; +#include "beecrypt/c++/io/FilterOutputStream.h" +using beecrypt::io::FilterOutputStream; + +namespace beecrypt { + namespace crypto { + class BEECRYPTCXXAPI MacOutputStream : public FilterOutputStream + { + private: + bool _on; + + protected: + Mac& mac; + + public: + MacOutputStream(OutputStream&, Mac&); + virtual ~MacOutputStream(); + + virtual void write(byte) throw (IOException); + virtual void write(const byte* data, size_t offset, size_t length) throw (IOException); + + void on(bool); + + Mac& getMac(); + void setMac(Mac&); + + }; + } +} + +#endif + +#endif + diff --git a/beecrypt/c++/crypto/MacSpi.h b/beecrypt/c++/crypto/MacSpi.h new file mode 100644 index 0000000..b06104d --- /dev/null +++ b/beecrypt/c++/crypto/MacSpi.h @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file MacSpi.h + * \ingroup CXX_CRYPTO_m + */ + +#ifndef _CLASS_MACSPI_H +#define _CLASS_MACSPI_H + +#include "beecrypt/api.h" + +#ifdef __cplusplus + +#include "beecrypt/c++/array.h" +using beecrypt::array; +#include "beecrypt/c++/lang/IllegalStateException.h" +using beecrypt::lang::IllegalStateException; +#include "beecrypt/c++/security/InvalidAlgorithmParameterException.h" +using beecrypt::security::InvalidAlgorithmParameterException; +#include "beecrypt/c++/security/InvalidKeyException.h" +using beecrypt::security::InvalidKeyException; +#include "beecrypt/c++/security/Key.h" +using beecrypt::security::Key; +#include "beecrypt/c++/security/ShortBufferException.h" +using beecrypt::security::ShortBufferException; +#include "beecrypt/c++/security/spec/AlgorithmParameterSpec.h" +using beecrypt::security::spec::AlgorithmParameterSpec; + +namespace beecrypt { + namespace crypto { + class BEECRYPTCXXAPI MacSpi + { + friend class Mac; + + protected: + virtual const bytearray& engineDoFinal() = 0; + virtual size_t engineDoFinal(byte*, size_t, size_t) throw (ShortBufferException) = 0; + virtual size_t engineGetMacLength() = 0; + virtual void engineInit(const Key&, const AlgorithmParameterSpec*) throw (InvalidKeyException, InvalidAlgorithmParameterException) = 0; + virtual void engineReset() = 0; + virtual void engineUpdate(byte) = 0; + virtual void engineUpdate(const byte*, size_t, size_t) = 0; + + public: + virtual ~MacSpi() {}; + + virtual MacSpi* clone() const = 0; + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/crypto/Makefile.am b/beecrypt/c++/crypto/Makefile.am new file mode 100644 index 0000000..9a9a786 --- /dev/null +++ b/beecrypt/c++/crypto/Makefile.am @@ -0,0 +1,27 @@ +INCLUDES = -I$(top_srcdir)/.. + +AUTOMAKE_OPTIONS = gnu no-dependencies + +SUBDIRS = interfaces spec + +noinst_LTLIBRARIES = libcxxcrypto.la + +cxxcryptodir=$(pkgincludedir)/c++/crypto + +libcxxcrypto_la_SOURCES = \ +BadPaddingException.cxx \ +Mac.cxx \ +MacInputStream.cxx \ +MacOutputStream.cxx \ +SecretKeyFactory.cxx +libcxxcrypto_la_LIBADD = spec/libcxxcryptospec.la + +cxxcrypto_HEADERS = \ +BadPaddingException.h \ +Mac.h \ +MacInputStream.h \ +MacOutputStream.h \ +MacSpi.h \ +SecretKey.h \ +SecretKeyFactory.h \ +SecretKeyFactorySpi.h diff --git a/beecrypt/c++/crypto/Makefile.in b/beecrypt/c++/crypto/Makefile.in new file mode 100644 index 0000000..84db11c --- /dev/null +++ b/beecrypt/c++/crypto/Makefile.in @@ -0,0 +1,599 @@ +# Makefile.in generated by automake 1.8.3 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + + +SOURCES = $(libcxxcrypto_la_SOURCES) + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +top_builddir = ../.. +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +INSTALL = @INSTALL@ +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +host_triplet = @host@ +subdir = c++/crypto +DIST_COMMON = $(cxxcrypto_HEADERS) $(srcdir)/Makefile.am \ + $(srcdir)/Makefile.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \ + $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +LTLIBRARIES = $(noinst_LTLIBRARIES) +libcxxcrypto_la_DEPENDENCIES = spec/libcxxcryptospec.la +am_libcxxcrypto_la_OBJECTS = BadPaddingException.lo Mac.lo \ + MacInputStream.lo MacOutputStream.lo SecretKeyFactory.lo +libcxxcrypto_la_OBJECTS = $(am_libcxxcrypto_la_OBJECTS) +DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir) +depcomp = +am__depfiles_maybe = +CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) +LTCXXCOMPILE = $(LIBTOOL) --mode=compile $(CXX) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CXXFLAGS) $(CXXFLAGS) +CXXLD = $(CXX) +CXXLINK = $(LIBTOOL) --mode=link $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) \ + $(AM_LDFLAGS) $(LDFLAGS) -o $@ +SOURCES = $(libcxxcrypto_la_SOURCES) +DIST_SOURCES = $(libcxxcrypto_la_SOURCES) +RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \ + html-recursive info-recursive install-data-recursive \ + install-exec-recursive install-info-recursive \ + install-recursive installcheck-recursive installdirs-recursive \ + pdf-recursive ps-recursive uninstall-info-recursive \ + uninstall-recursive +am__installdirs = "$(DESTDIR)$(cxxcryptodir)" +cxxcryptoHEADERS_INSTALL = $(INSTALL_HEADER) +HEADERS = $(cxxcrypto_HEADERS) +ETAGS = etags +CTAGS = ctags +DIST_SUBDIRS = $(SUBDIRS) +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMDEP_FALSE = @AMDEP_FALSE@ +AMDEP_TRUE = @AMDEP_TRUE@ +AMTAR = @AMTAR@ +AR = @AR@ +AS = @AS@ +ASM_ALIGN = @ASM_ALIGN@ +ASM_ARCH = @ASM_ARCH@ +ASM_BIGENDIAN = @ASM_BIGENDIAN@ +ASM_CPU = @ASM_CPU@ +ASM_GLOBL = @ASM_GLOBL@ +ASM_GSYM_PREFIX = @ASM_GSYM_PREFIX@ +ASM_LSYM_PREFIX = @ASM_LSYM_PREFIX@ +ASM_OS = @ASM_OS@ +ASM_TEXTSEG = @ASM_TEXTSEG@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCAS = @CCAS@ +CCASFLAGS = @CCASFLAGS@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DLLTOOL = @DLLTOOL@ +ECHO = @ECHO@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +F77 = @F77@ +FFLAGS = @FFLAGS@ +INCLUDE_DLFCN_H = @INCLUDE_DLFCN_H@ +INCLUDE_INTTYPES_H = @INCLUDE_INTTYPES_H@ +INCLUDE_MALLOC_H = @INCLUDE_MALLOC_H@ +INCLUDE_PTHREAD_H = @INCLUDE_PTHREAD_H@ +INCLUDE_STDINT_H = @INCLUDE_STDINT_H@ +INCLUDE_STDIO_H = @INCLUDE_STDIO_H@ +INCLUDE_STDLIB_H = @INCLUDE_STDLIB_H@ +INCLUDE_STRING_H = @INCLUDE_STRING_H@ +INCLUDE_SYNCH_H = @INCLUDE_SYNCH_H@ +INCLUDE_THREAD_H = @INCLUDE_THREAD_H@ +INCLUDE_UNISTD_H = @INCLUDE_UNISTD_H@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +JAVAINC = @JAVAINC@ +LDFLAGS = @LDFLAGS@ +LIBALT = @LIBALT@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +MAYBE_LTLIB = @MAYBE_LTLIB@ +MAYBE_SUB = @MAYBE_SUB@ +MP_WBITS = @MP_WBITS@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PYTHONINC = @PYTHONINC@ +PYTHONLIB = @PYTHONLIB@ +RANLIB = @RANLIB@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +TYPEDEF_BC_COND_T = @TYPEDEF_BC_COND_T@ +TYPEDEF_BC_MUTEX_T = @TYPEDEF_BC_MUTEX_T@ +TYPEDEF_BC_THREAD_T = @TYPEDEF_BC_THREAD_T@ +TYPEDEF_INT16_T = @TYPEDEF_INT16_T@ +TYPEDEF_INT32_T = @TYPEDEF_INT32_T@ +TYPEDEF_INT64_T = @TYPEDEF_INT64_T@ +TYPEDEF_INT8_T = @TYPEDEF_INT8_T@ +TYPEDEF_SIZE_T = @TYPEDEF_SIZE_T@ +TYPEDEF_UINT16_T = @TYPEDEF_UINT16_T@ +TYPEDEF_UINT32_T = @TYPEDEF_UINT32_T@ +TYPEDEF_UINT64_T = @TYPEDEF_UINT64_T@ +TYPEDEF_UINT8_T = @TYPEDEF_UINT8_T@ +VERSION = @VERSION@ +ac_ct_AR = @ac_ct_AR@ +ac_ct_AS = @ac_ct_AS@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DLLTOOL = @ac_ct_DLLTOOL@ +ac_ct_F77 = @ac_ct_F77@ +ac_ct_OBJDUMP = @ac_ct_OBJDUMP@ +ac_ct_RANLIB = @ac_ct_RANLIB@ +ac_ct_STRIP = @ac_ct_STRIP@ +ac_cv_have_gcj = @ac_cv_have_gcj@ +ac_cv_have_java = @ac_cv_have_java@ +ac_cv_have_javac = @ac_cv_have_javac@ +ac_cv_have_python = @ac_cv_have_python@ +am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ +am__fastdepCC_TRUE = @am__fastdepCC_TRUE@ +am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@ +am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +datadir = @datadir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +sysconfdir = @sysconfdir@ +target = @target@ +target_alias = @target_alias@ +target_cpu = @target_cpu@ +target_os = @target_os@ +target_vendor = @target_vendor@ +INCLUDES = -I$(top_srcdir)/.. +AUTOMAKE_OPTIONS = gnu no-dependencies +SUBDIRS = interfaces spec +noinst_LTLIBRARIES = libcxxcrypto.la +cxxcryptodir = $(pkgincludedir)/c++/crypto +libcxxcrypto_la_SOURCES = \ +BadPaddingException.cxx \ +Mac.cxx \ +MacInputStream.cxx \ +MacOutputStream.cxx \ +SecretKeyFactory.cxx + +libcxxcrypto_la_LIBADD = spec/libcxxcryptospec.la +cxxcrypto_HEADERS = \ +BadPaddingException.h \ +Mac.h \ +MacInputStream.h \ +MacOutputStream.h \ +MacSpi.h \ +SecretKey.h \ +SecretKeyFactory.h \ +SecretKeyFactorySpi.h + +all: all-recursive + +.SUFFIXES: +.SUFFIXES: .cxx .lo .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ + && exit 0; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu c++/crypto/Makefile'; \ + cd $(top_srcdir) && \ + $(AUTOMAKE) --gnu c++/crypto/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +clean-noinstLTLIBRARIES: + -test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES) + @list='$(noinst_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" = "$$p" && dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +libcxxcrypto.la: $(libcxxcrypto_la_OBJECTS) $(libcxxcrypto_la_DEPENDENCIES) + $(CXXLINK) $(libcxxcrypto_la_LDFLAGS) $(libcxxcrypto_la_OBJECTS) $(libcxxcrypto_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +.cxx.o: + $(CXXCOMPILE) -c -o $@ $< + +.cxx.obj: + $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +.cxx.lo: + $(LTCXXCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +distclean-libtool: + -rm -f libtool +uninstall-info-am: +install-cxxcryptoHEADERS: $(cxxcrypto_HEADERS) + @$(NORMAL_INSTALL) + test -z "$(cxxcryptodir)" || $(mkdir_p) "$(DESTDIR)$(cxxcryptodir)" + @list='$(cxxcrypto_HEADERS)'; for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + f="`echo $$p | sed -e 's|^.*/||'`"; \ + echo " $(cxxcryptoHEADERS_INSTALL) '$$d$$p' '$(DESTDIR)$(cxxcryptodir)/$$f'"; \ + $(cxxcryptoHEADERS_INSTALL) "$$d$$p" "$(DESTDIR)$(cxxcryptodir)/$$f"; \ + done + +uninstall-cxxcryptoHEADERS: + @$(NORMAL_UNINSTALL) + @list='$(cxxcrypto_HEADERS)'; for p in $$list; do \ + f="`echo $$p | sed -e 's|^.*/||'`"; \ + echo " rm -f '$(DESTDIR)$(cxxcryptodir)/$$f'"; \ + rm -f "$(DESTDIR)$(cxxcryptodir)/$$f"; \ + done + +# This directory's subdirectories are mostly independent; you can cd +# into them and run `make' without going through this Makefile. +# To change the values of `make' variables: instead of editing Makefiles, +# (1) if the variable is set in `config.status', edit `config.status' +# (which will cause the Makefiles to be regenerated when you run `make'); +# (2) otherwise, pass the desired values on the `make' command line. +$(RECURSIVE_TARGETS): + @set fnord $$MAKEFLAGS; amf=$$2; \ + dot_seen=no; \ + target=`echo $@ | sed s/-recursive//`; \ + list='$(SUBDIRS)'; for subdir in $$list; do \ + echo "Making $$target in $$subdir"; \ + if test "$$subdir" = "."; then \ + dot_seen=yes; \ + local_target="$$target-am"; \ + else \ + local_target="$$target"; \ + fi; \ + (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ + || case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \ + done; \ + if test "$$dot_seen" = "no"; then \ + $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \ + fi; test -z "$$fail" + +mostlyclean-recursive clean-recursive distclean-recursive \ +maintainer-clean-recursive: + @set fnord $$MAKEFLAGS; amf=$$2; \ + dot_seen=no; \ + case "$@" in \ + distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \ + *) list='$(SUBDIRS)' ;; \ + esac; \ + rev=''; for subdir in $$list; do \ + if test "$$subdir" = "."; then :; else \ + rev="$$subdir $$rev"; \ + fi; \ + done; \ + rev="$$rev ."; \ + target=`echo $@ | sed s/-recursive//`; \ + for subdir in $$rev; do \ + echo "Making $$target in $$subdir"; \ + if test "$$subdir" = "."; then \ + local_target="$$target-am"; \ + else \ + local_target="$$target"; \ + fi; \ + (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ + || case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \ + done && test -z "$$fail" +tags-recursive: + list='$(SUBDIRS)'; for subdir in $$list; do \ + test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \ + done +ctags-recursive: + list='$(SUBDIRS)'; for subdir in $$list; do \ + test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) ctags); \ + done + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: tags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + if (etags --etags-include --version) >/dev/null 2>&1; then \ + include_option=--etags-include; \ + else \ + include_option=--include; \ + fi; \ + list='$(SUBDIRS)'; for subdir in $$list; do \ + if test "$$subdir" = .; then :; else \ + test -f $$subdir/TAGS && \ + tags="$$tags $$include_option=$$here/$$subdir/TAGS"; \ + fi; \ + done; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(ETAGS_ARGS)$$tags$$unique" \ + || $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$tags $$unique +ctags: CTAGS +CTAGS: ctags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(CTAGS_ARGS)$$tags$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$tags $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && cd $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) $$here + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \ + list='$(DISTFILES)'; for file in $$list; do \ + case $$file in \ + $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \ + $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \ + esac; \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test "$$dir" != "$$file" && test "$$dir" != "."; then \ + dir="/$$dir"; \ + $(mkdir_p) "$(distdir)$$dir"; \ + else \ + dir=''; \ + fi; \ + if test -d $$d/$$file; then \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + fi; \ + cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ + else \ + test -f $(distdir)/$$file \ + || cp -p $$d/$$file $(distdir)/$$file \ + || exit 1; \ + fi; \ + done + list='$(SUBDIRS)'; for subdir in $$list; do \ + if test "$$subdir" = .; then :; else \ + test -d "$(distdir)/$$subdir" \ + || mkdir "$(distdir)/$$subdir" \ + || exit 1; \ + (cd $$subdir && \ + $(MAKE) $(AM_MAKEFLAGS) \ + top_distdir="../$(top_distdir)" \ + distdir="../$(distdir)/$$subdir" \ + distdir) \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-recursive +all-am: Makefile $(LTLIBRARIES) $(HEADERS) +installdirs: installdirs-recursive +installdirs-am: + for dir in "$(DESTDIR)$(cxxcryptodir)"; do \ + test -z "$$dir" || $(mkdir_p) "$$dir"; \ + done +install: install-recursive +install-exec: install-exec-recursive +install-data: install-data-recursive +uninstall: uninstall-recursive + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-recursive +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -rm -f $(CONFIG_CLEAN_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-recursive + +clean-am: clean-generic clean-libtool clean-noinstLTLIBRARIES \ + mostlyclean-am + +distclean: distclean-recursive + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-libtool distclean-tags + +dvi: dvi-recursive + +dvi-am: + +html: html-recursive + +info: info-recursive + +info-am: + +install-data-am: install-cxxcryptoHEADERS + +install-exec-am: + +install-info: install-info-recursive + +install-man: + +installcheck-am: + +maintainer-clean: maintainer-clean-recursive + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-recursive + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-recursive + +pdf-am: + +ps: ps-recursive + +ps-am: + +uninstall-am: uninstall-cxxcryptoHEADERS uninstall-info-am + +uninstall-info: uninstall-info-recursive + +.PHONY: $(RECURSIVE_TARGETS) CTAGS GTAGS all all-am check check-am \ + clean clean-generic clean-libtool clean-noinstLTLIBRARIES \ + clean-recursive ctags ctags-recursive distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-recursive distclean-tags distdir dvi dvi-am html \ + html-am info info-am install install-am \ + install-cxxcryptoHEADERS install-data install-data-am \ + install-exec install-exec-am install-info install-info-am \ + install-man install-strip installcheck installcheck-am \ + installdirs installdirs-am maintainer-clean \ + maintainer-clean-generic maintainer-clean-recursive \ + mostlyclean mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool mostlyclean-recursive pdf pdf-am ps ps-am \ + tags tags-recursive uninstall uninstall-am \ + uninstall-cxxcryptoHEADERS uninstall-info-am + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/beecrypt/c++/crypto/SecretKey.h b/beecrypt/c++/crypto/SecretKey.h new file mode 100644 index 0000000..07b2f75 --- /dev/null +++ b/beecrypt/c++/crypto/SecretKey.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file SecretKey.h + * \ingroup CXX_CRYPTO_m + */ + +#ifndef _INTERFACE_SECRETKEY_H +#define _INTERFACE_SECRETKEY_H + +#ifdef __cplusplus + +#include "beecrypt/c++/security/Key.h" +using beecrypt::security::Key; + +namespace beecrypt { + namespace crypto { + /*!\brief SecretKey interface + * \ingroup CXX_CRYPTO_m + */ + class BEECRYPTCXXAPI SecretKey : public Key + { + public: + virtual SecretKey* clone() const = 0; + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/crypto/SecretKeyFactory.cxx b/beecrypt/c++/crypto/SecretKeyFactory.cxx new file mode 100644 index 0000000..ff25e85 --- /dev/null +++ b/beecrypt/c++/crypto/SecretKeyFactory.cxx @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/crypto/SecretKeyFactory.h" +#include "beecrypt/c++/security/Security.h" +using beecrypt::security::Security; + +using namespace beecrypt::crypto; + +SecretKeyFactory::SecretKeyFactory(SecretKeyFactorySpi* spi, const String& algorithm, const Provider& provider) +{ + _kspi = spi; + _algo = algorithm; + _prov = &provider; +} + +SecretKeyFactory::~SecretKeyFactory() +{ + delete _kspi; +} + +SecretKeyFactory* SecretKeyFactory::getInstance(const String& algorithm) throw (NoSuchAlgorithmException) +{ + Security::spi* tmp = Security::getSpi(algorithm, "SecretKeyFactory"); + + SecretKeyFactory* result = new SecretKeyFactory((SecretKeyFactorySpi*) tmp->cspi, tmp->name, tmp->prov); + + delete tmp; + + return result; +} + +SecretKeyFactory* SecretKeyFactory::getInstance(const String& algorithm, const String& provider) throw (NoSuchAlgorithmException, NoSuchProviderException) +{ + Security::spi* tmp = Security::getSpi(algorithm, "SecretKeyFactory", provider); + + SecretKeyFactory* result = new SecretKeyFactory((SecretKeyFactorySpi*) tmp->cspi, tmp->name, tmp->prov); + + delete tmp; + + return result; +} + +SecretKeyFactory* SecretKeyFactory::getInstance(const String& algorithm, const Provider& provider) throw (NoSuchAlgorithmException) +{ + Security::spi* tmp = Security::getSpi(algorithm, "SecretKeyFactory", provider); + + SecretKeyFactory* result = new SecretKeyFactory((SecretKeyFactorySpi*) tmp->cspi, tmp->name, tmp->prov); + + delete tmp; + + return result; +} + +SecretKey* SecretKeyFactory::generateSecret(const KeySpec& spec) throw (InvalidKeySpecException) +{ + return _kspi->engineGenerateSecret(spec); +} + +KeySpec* SecretKeyFactory::getKeySpec(const SecretKey& key, const type_info& info) throw (InvalidKeySpecException) +{ + return _kspi->engineGetKeySpec(key, info); +} + +SecretKey* SecretKeyFactory::translateKey(const SecretKey& key) throw (InvalidKeyException) +{ + return _kspi->engineTranslateKey(key); +} + +const String& SecretKeyFactory::getAlgorithm() const throw () +{ + return _algo; +} + +const Provider& SecretKeyFactory::getProvider() const throw () +{ + return *_prov; +} diff --git a/beecrypt/c++/crypto/SecretKeyFactory.h b/beecrypt/c++/crypto/SecretKeyFactory.h new file mode 100644 index 0000000..f2c1a55 --- /dev/null +++ b/beecrypt/c++/crypto/SecretKeyFactory.h @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file SecretKeyFactory.h + * \ingroup CXX_CRYPTO_m + */ + +#ifndef _CLASS_SECRETKEYFACTORY_H +#define _CLASS_SECRETKEYFACTORY_H + +// #include "beecrypt/beecrypt.api.h" + +#ifdef __cplusplus + +#include "beecrypt/c++/crypto/SecretKeyFactorySpi.h" +using beecrypt::crypto::SecretKeyFactorySpi; +#include "beecrypt/c++/security/Provider.h" +using beecrypt::security::Provider; +#include "beecrypt/c++/security/NoSuchAlgorithmException.h" +using beecrypt::security::NoSuchAlgorithmException; +#include "beecrypt/c++/security/NoSuchProviderException.h" +using beecrypt::security::NoSuchProviderException; + +#include +using std::type_info; + +namespace beecrypt { + namespace crypto { + class BEECRYPTCXXAPI SecretKeyFactory + { + public: + static SecretKeyFactory* getInstance(const String&) throw (NoSuchAlgorithmException); + static SecretKeyFactory* getInstance(const String&, const String&) throw (NoSuchAlgorithmException, NoSuchProviderException); + static SecretKeyFactory* getInstance(const String&, const Provider&) throw (NoSuchAlgorithmException); + + private: + SecretKeyFactorySpi* _kspi; + String _algo; + const Provider* _prov; + + protected: + SecretKeyFactory(SecretKeyFactorySpi*, const String&, const Provider&); + + public: + ~SecretKeyFactory(); + + SecretKey* generateSecret(const KeySpec&) throw (InvalidKeySpecException); + + KeySpec* getKeySpec(const SecretKey& key, const type_info&) throw (InvalidKeySpecException); + + SecretKey* translateKey(const SecretKey&) throw (InvalidKeyException); + + const String& getAlgorithm() const throw (); + const Provider& getProvider() const throw (); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/crypto/SecretKeyFactorySpi.h b/beecrypt/c++/crypto/SecretKeyFactorySpi.h new file mode 100644 index 0000000..023cc08 --- /dev/null +++ b/beecrypt/c++/crypto/SecretKeyFactorySpi.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file SecretKeyFactorySpi.h + * \ingroup CXX_CRYPTO_m + */ + +#ifndef _CLASS_SECRETKEYFACTORYSPI_H +#define _CLASS_SECRETKEYFACTORYSPI_H + +#include "beecrypt/api.h" + +#ifdef __cplusplus + +#include "beecrypt/c++/crypto/SecretKey.h" +using beecrypt::crypto::SecretKey; +#include "beecrypt/c++/security/InvalidKeyException.h" +using beecrypt::security::InvalidKeyException; +#include "beecrypt/c++/security/spec/KeySpec.h" +using beecrypt::security::spec::KeySpec; +#include "beecrypt/c++/security/spec/InvalidKeySpecException.h" +using beecrypt::security::spec::InvalidKeySpecException; + +#include +using std::type_info; + +namespace beecrypt { + namespace crypto { + class BEECRYPTCXXAPI SecretKeyFactorySpi + { + friend class SecretKeyFactory; + + protected: + virtual SecretKey* engineGenerateSecret(const KeySpec&) throw (InvalidKeySpecException) = 0; + virtual KeySpec* engineGetKeySpec(const SecretKey&, const type_info&) throw (InvalidKeySpecException) = 0; + virtual SecretKey* engineTranslateKey(const SecretKey&) throw (InvalidKeyException) = 0; + + public: + virtual ~SecretKeyFactorySpi() {}; + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/crypto/interfaces/DHKey.h b/beecrypt/c++/crypto/interfaces/DHKey.h new file mode 100644 index 0000000..9523249 --- /dev/null +++ b/beecrypt/c++/crypto/interfaces/DHKey.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file DHKey.h + * \ingroup CXX_CRYPTO_INTERFACES_m + */ + +#ifndef _INTERFACE_DHKEY_H +#define _INTERFACE_DHKEY_H + +#ifdef __cplusplus + +#include "beecrypt/c++/crypto/interfaces/DHParams.h" +using beecrypt::crypto::interfaces::DHParams; + +namespace beecrypt { + namespace crypto { + namespace interfaces { + /*!\brief Diffie-Hellman key interface. + * \ingroup CXX_IF_m + */ + class DHKey + { + public: + virtual const DHParams& getParams() const throw () = 0; + }; + } + } +} + +#endif + +#endif diff --git a/beecrypt/c++/crypto/interfaces/DHParams.h b/beecrypt/c++/crypto/interfaces/DHParams.h new file mode 100644 index 0000000..c6f9e64 --- /dev/null +++ b/beecrypt/c++/crypto/interfaces/DHParams.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file DHParams.h + * \ingroup CXX_CRYPTO_INTERFACES_m + */ + +#ifndef _INTERFACE_DHPARAMS_H +#define _INTERFACE_DHPARAMS_H + +#include "beecrypt/api.h" +#include "beecrypt/mpbarrett.h" + +#ifdef __cplusplus + +namespace beecrypt { + namespace crypto { + namespace interfaces { + class DHParams + { + public: + virtual const mpbarrett& getP() const throw () = 0; + virtual const mpnumber& getG() const throw () = 0; + virtual size_t getL() const throw () = 0; + }; + } + } +} + +#endif + +#endif diff --git a/beecrypt/c++/crypto/interfaces/DHPrivateKey.h b/beecrypt/c++/crypto/interfaces/DHPrivateKey.h new file mode 100644 index 0000000..91e7ab4 --- /dev/null +++ b/beecrypt/c++/crypto/interfaces/DHPrivateKey.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file DHPrivateKey.h + * \ingroup CXX_CRYPTO_INTERFACES_m + */ + +#ifndef _INTERFACE_DHPRIVATEKEY_H +#define _INTERFACE_DHPRIVATEKEY_H + +#include "beecrypt/api.h" +#include "beecrypt/dldp.h" + +#ifdef __cplusplus + +#include "beecrypt/c++/security/PrivateKey.h" +using beecrypt::security::PrivateKey; +#include "beecrypt/c++/crypto/interfaces/DHKey.h" +using beecrypt::crypto::interfaces::DHKey; + +namespace beecrypt { + namespace crypto { + namespace interfaces { + /*!\brief Diffie-Hellman PrivateKey interface + * \ingroup CXX_IF_m + */ + class DHPrivateKey : public PrivateKey, public DHKey + { + public: + virtual const mpnumber& getX() const throw () = 0; + }; + } + } +} + +#endif + +#endif diff --git a/beecrypt/c++/crypto/interfaces/DHPublicKey.h b/beecrypt/c++/crypto/interfaces/DHPublicKey.h new file mode 100644 index 0000000..c33ee29 --- /dev/null +++ b/beecrypt/c++/crypto/interfaces/DHPublicKey.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file DHPublicKey.h + * \ingroup CXX_CRYPTO_INTERFACES_m + */ + +#ifndef _INTERFACE_DHPUBLICKEY_H +#define _INTERFACE_DHPUBLICKEY_H + +#include "beecrypt/api.h" +#include "beecrypt/mpnumber.h" + +#ifdef __cplusplus + +#include "beecrypt/c++/security/PublicKey.h" +using beecrypt::security::PublicKey; +#include "beecrypt/c++/crypto/interfaces/DHKey.h" +using beecrypt::crypto::interfaces::DHKey; + +namespace beecrypt { + namespace crypto { + namespace interfaces { + /*!\brief Diffie-Hellman PublicKey interface + * \ingroup CXX_IF_m + */ + class DHPublicKey : public PublicKey, public DHKey + { + public: + virtual const mpnumber& getY() const throw () = 0; + }; + } + } +} + +#endif + +#endif diff --git a/beecrypt/c++/crypto/interfaces/Makefile.am b/beecrypt/c++/crypto/interfaces/Makefile.am new file mode 100644 index 0000000..41cd575 --- /dev/null +++ b/beecrypt/c++/crypto/interfaces/Makefile.am @@ -0,0 +1,12 @@ +INCLUDES = -I$(top_srcdir)/.. + +AUTOMAKE_OPTIONS = gnu no-dependencies + +cxxcryptointerfacesdir=$(pkgincludedir)/c++/crypto/interfaces + +cxxcryptointerfaces_HEADERS =\ +DHKey.h \ +DHParams.h \ +DHPrivateKey.h \ +DHPublicKey.h \ +PBEKey.h diff --git a/beecrypt/c++/crypto/interfaces/Makefile.in b/beecrypt/c++/crypto/interfaces/Makefile.in new file mode 100644 index 0000000..4040c07 --- /dev/null +++ b/beecrypt/c++/crypto/interfaces/Makefile.in @@ -0,0 +1,444 @@ +# Makefile.in generated by automake 1.8.3 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +top_builddir = ../../.. +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +INSTALL = @INSTALL@ +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +host_triplet = @host@ +subdir = c++/crypto/interfaces +DIST_COMMON = $(cxxcryptointerfaces_HEADERS) $(srcdir)/Makefile.am \ + $(srcdir)/Makefile.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \ + $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +depcomp = +am__depfiles_maybe = +SOURCES = +DIST_SOURCES = +am__installdirs = "$(DESTDIR)$(cxxcryptointerfacesdir)" +cxxcryptointerfacesHEADERS_INSTALL = $(INSTALL_HEADER) +HEADERS = $(cxxcryptointerfaces_HEADERS) +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMDEP_FALSE = @AMDEP_FALSE@ +AMDEP_TRUE = @AMDEP_TRUE@ +AMTAR = @AMTAR@ +AR = @AR@ +AS = @AS@ +ASM_ALIGN = @ASM_ALIGN@ +ASM_ARCH = @ASM_ARCH@ +ASM_BIGENDIAN = @ASM_BIGENDIAN@ +ASM_CPU = @ASM_CPU@ +ASM_GLOBL = @ASM_GLOBL@ +ASM_GSYM_PREFIX = @ASM_GSYM_PREFIX@ +ASM_LSYM_PREFIX = @ASM_LSYM_PREFIX@ +ASM_OS = @ASM_OS@ +ASM_TEXTSEG = @ASM_TEXTSEG@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCAS = @CCAS@ +CCASFLAGS = @CCASFLAGS@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DLLTOOL = @DLLTOOL@ +ECHO = @ECHO@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +F77 = @F77@ +FFLAGS = @FFLAGS@ +INCLUDE_DLFCN_H = @INCLUDE_DLFCN_H@ +INCLUDE_INTTYPES_H = @INCLUDE_INTTYPES_H@ +INCLUDE_MALLOC_H = @INCLUDE_MALLOC_H@ +INCLUDE_PTHREAD_H = @INCLUDE_PTHREAD_H@ +INCLUDE_STDINT_H = @INCLUDE_STDINT_H@ +INCLUDE_STDIO_H = @INCLUDE_STDIO_H@ +INCLUDE_STDLIB_H = @INCLUDE_STDLIB_H@ +INCLUDE_STRING_H = @INCLUDE_STRING_H@ +INCLUDE_SYNCH_H = @INCLUDE_SYNCH_H@ +INCLUDE_THREAD_H = @INCLUDE_THREAD_H@ +INCLUDE_UNISTD_H = @INCLUDE_UNISTD_H@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +JAVAINC = @JAVAINC@ +LDFLAGS = @LDFLAGS@ +LIBALT = @LIBALT@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +MAYBE_LTLIB = @MAYBE_LTLIB@ +MAYBE_SUB = @MAYBE_SUB@ +MP_WBITS = @MP_WBITS@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PYTHONINC = @PYTHONINC@ +PYTHONLIB = @PYTHONLIB@ +RANLIB = @RANLIB@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +TYPEDEF_BC_COND_T = @TYPEDEF_BC_COND_T@ +TYPEDEF_BC_MUTEX_T = @TYPEDEF_BC_MUTEX_T@ +TYPEDEF_BC_THREAD_T = @TYPEDEF_BC_THREAD_T@ +TYPEDEF_INT16_T = @TYPEDEF_INT16_T@ +TYPEDEF_INT32_T = @TYPEDEF_INT32_T@ +TYPEDEF_INT64_T = @TYPEDEF_INT64_T@ +TYPEDEF_INT8_T = @TYPEDEF_INT8_T@ +TYPEDEF_SIZE_T = @TYPEDEF_SIZE_T@ +TYPEDEF_UINT16_T = @TYPEDEF_UINT16_T@ +TYPEDEF_UINT32_T = @TYPEDEF_UINT32_T@ +TYPEDEF_UINT64_T = @TYPEDEF_UINT64_T@ +TYPEDEF_UINT8_T = @TYPEDEF_UINT8_T@ +VERSION = @VERSION@ +ac_ct_AR = @ac_ct_AR@ +ac_ct_AS = @ac_ct_AS@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DLLTOOL = @ac_ct_DLLTOOL@ +ac_ct_F77 = @ac_ct_F77@ +ac_ct_OBJDUMP = @ac_ct_OBJDUMP@ +ac_ct_RANLIB = @ac_ct_RANLIB@ +ac_ct_STRIP = @ac_ct_STRIP@ +ac_cv_have_gcj = @ac_cv_have_gcj@ +ac_cv_have_java = @ac_cv_have_java@ +ac_cv_have_javac = @ac_cv_have_javac@ +ac_cv_have_python = @ac_cv_have_python@ +am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ +am__fastdepCC_TRUE = @am__fastdepCC_TRUE@ +am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@ +am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +datadir = @datadir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +sysconfdir = @sysconfdir@ +target = @target@ +target_alias = @target_alias@ +target_cpu = @target_cpu@ +target_os = @target_os@ +target_vendor = @target_vendor@ +INCLUDES = -I$(top_srcdir)/.. +AUTOMAKE_OPTIONS = gnu no-dependencies +cxxcryptointerfacesdir = $(pkgincludedir)/c++/crypto/interfaces +cxxcryptointerfaces_HEADERS = \ +DHKey.h \ +DHParams.h \ +DHPrivateKey.h \ +DHPublicKey.h \ +PBEKey.h + +all: all-am + +.SUFFIXES: +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ + && exit 0; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu c++/crypto/interfaces/Makefile'; \ + cd $(top_srcdir) && \ + $(AUTOMAKE) --gnu c++/crypto/interfaces/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +distclean-libtool: + -rm -f libtool +uninstall-info-am: +install-cxxcryptointerfacesHEADERS: $(cxxcryptointerfaces_HEADERS) + @$(NORMAL_INSTALL) + test -z "$(cxxcryptointerfacesdir)" || $(mkdir_p) "$(DESTDIR)$(cxxcryptointerfacesdir)" + @list='$(cxxcryptointerfaces_HEADERS)'; for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + f="`echo $$p | sed -e 's|^.*/||'`"; \ + echo " $(cxxcryptointerfacesHEADERS_INSTALL) '$$d$$p' '$(DESTDIR)$(cxxcryptointerfacesdir)/$$f'"; \ + $(cxxcryptointerfacesHEADERS_INSTALL) "$$d$$p" "$(DESTDIR)$(cxxcryptointerfacesdir)/$$f"; \ + done + +uninstall-cxxcryptointerfacesHEADERS: + @$(NORMAL_UNINSTALL) + @list='$(cxxcryptointerfaces_HEADERS)'; for p in $$list; do \ + f="`echo $$p | sed -e 's|^.*/||'`"; \ + echo " rm -f '$(DESTDIR)$(cxxcryptointerfacesdir)/$$f'"; \ + rm -f "$(DESTDIR)$(cxxcryptointerfacesdir)/$$f"; \ + done + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(ETAGS_ARGS)$$tags$$unique" \ + || $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$tags $$unique +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(CTAGS_ARGS)$$tags$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$tags $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && cd $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) $$here + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \ + list='$(DISTFILES)'; for file in $$list; do \ + case $$file in \ + $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \ + $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \ + esac; \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test "$$dir" != "$$file" && test "$$dir" != "."; then \ + dir="/$$dir"; \ + $(mkdir_p) "$(distdir)$$dir"; \ + else \ + dir=''; \ + fi; \ + if test -d $$d/$$file; then \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + fi; \ + cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ + else \ + test -f $(distdir)/$$file \ + || cp -p $$d/$$file $(distdir)/$$file \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(HEADERS) +installdirs: + for dir in "$(DESTDIR)$(cxxcryptointerfacesdir)"; do \ + test -z "$$dir" || $(mkdir_p) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -rm -f $(CONFIG_CLEAN_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libtool mostlyclean-am + +distclean: distclean-am + -rm -f Makefile +distclean-am: clean-am distclean-generic distclean-libtool \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +info: info-am + +info-am: + +install-data-am: install-cxxcryptointerfacesHEADERS + +install-exec-am: + +install-info: install-info-am + +install-man: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-generic mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-cxxcryptointerfacesHEADERS uninstall-info-am + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-libtool ctags distclean distclean-generic \ + distclean-libtool distclean-tags distdir dvi dvi-am html \ + html-am info info-am install install-am \ + install-cxxcryptointerfacesHEADERS install-data \ + install-data-am install-exec install-exec-am install-info \ + install-info-am install-man install-strip installcheck \ + installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-generic \ + mostlyclean-libtool pdf pdf-am ps ps-am tags uninstall \ + uninstall-am uninstall-cxxcryptointerfacesHEADERS \ + uninstall-info-am + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/beecrypt/c++/crypto/interfaces/PBEKey.h b/beecrypt/c++/crypto/interfaces/PBEKey.h new file mode 100644 index 0000000..11df99d --- /dev/null +++ b/beecrypt/c++/crypto/interfaces/PBEKey.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file PBEKey.h + * \ingroup CXX_CRYPTO_INTERFACES_m + */ + +#ifndef _INTERFACE_PBEKEY_H +#define _INTERFACE_PBEKEY_H + +#ifdef __cplusplus + +#include "beecrypt/c++/crypto/SecretKey.h" +using beecrypt::crypto::SecretKey; + +namespace beecrypt { + namespace crypto { + namespace interfaces { + /*!\brief PBEKey interface + * \ingroup CXX_CRYPTO_m + */ + class BEECRYPTCXXAPI PBEKey : public SecretKey + { + public: + virtual size_t getIterationCount() const throw () = 0; + virtual const array& getPassword() const throw () = 0; + virtual const bytearray* getSalt() const throw () = 0; + + virtual PBEKey* clone() const = 0; + }; + } + } +} + +#endif + +#endif diff --git a/beecrypt/c++/crypto/spec/DHParameterSpec.cxx b/beecrypt/c++/crypto/spec/DHParameterSpec.cxx new file mode 100644 index 0000000..8f47c1f --- /dev/null +++ b/beecrypt/c++/crypto/spec/DHParameterSpec.cxx @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#include "beecrypt/c++/crypto/spec/DHParameterSpec.h" + +using namespace beecrypt::crypto::spec; + +DHParameterSpec::DHParameterSpec(const DHParams& copy) +{ + _p = copy.getP(); + _g = copy.getG(); + _l = copy.getL(); +} + +DHParameterSpec::DHParameterSpec(const mpbarrett& p, const mpnumber& g) +{ + _p = p; + _g = g; + _l = 0; +} + +DHParameterSpec::DHParameterSpec(const mpbarrett& p, const mpnumber& g, size_t l) +{ + _p = p; + _g = g; + _l = l; +} + +DHParameterSpec::~DHParameterSpec() +{ +} + +const mpbarrett& DHParameterSpec::getP() const throw () +{ + return _p; +} + +const mpnumber& DHParameterSpec::getG() const throw () +{ + return _g; +} + +size_t DHParameterSpec::getL() const throw () +{ + return _l; +} diff --git a/beecrypt/c++/crypto/spec/DHParameterSpec.h b/beecrypt/c++/crypto/spec/DHParameterSpec.h new file mode 100644 index 0000000..5e2bf3f --- /dev/null +++ b/beecrypt/c++/crypto/spec/DHParameterSpec.h @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file DHParameterSpec.h + * \ingroup CXX_CRYPTO_SPEC_m + */ + +#ifndef _CLASS_DHPARAMETERSPEC_H +#define _CLASS_DHPARAMETERSPEC_H + +#include "beecrypt/api.h" +#include "beecrypt/mpbarrett.h" +#include "beecrypt/dlsvdp-dh.h" + +#ifdef __cplusplus + +#include "beecrypt/c++/crypto/interfaces/DHParams.h" +using beecrypt::crypto::interfaces::DHParams; +#include "beecrypt/c++/security/spec/AlgorithmParameterSpec.h" +using beecrypt::security::spec::AlgorithmParameterSpec; + +namespace beecrypt { + namespace crypto { + namespace spec { + class BEECRYPTCXXAPI DHParameterSpec : public AlgorithmParameterSpec, public DHParams + { + private: + mpbarrett _p; + mpnumber _g; + size_t _l; + + public: + DHParameterSpec(const DHParams&); + DHParameterSpec(const mpbarrett& p, const mpnumber& g); + DHParameterSpec(const mpbarrett& p, const mpnumber& g, size_t l); + virtual ~DHParameterSpec(); + + const mpbarrett& getP() const throw (); + const mpnumber& getG() const throw (); + size_t getL() const throw (); + }; + } + } +} + +#endif + +#endif diff --git a/beecrypt/c++/crypto/spec/DHPrivateKeySpec.cxx b/beecrypt/c++/crypto/spec/DHPrivateKeySpec.cxx new file mode 100644 index 0000000..e67530b --- /dev/null +++ b/beecrypt/c++/crypto/spec/DHPrivateKeySpec.cxx @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#include "beecrypt/c++/crypto/spec/DHPrivateKeySpec.h" + +using namespace beecrypt::crypto::spec; + +DHPrivateKeySpec::DHPrivateKeySpec(const mpbarrett& p, const mpnumber& g, const mpnumber& x) +{ + _p = p; + _g = g; + _x = x; +} + +DHPrivateKeySpec::~DHPrivateKeySpec() +{ + _x.wipe(); +} + +const mpbarrett& DHPrivateKeySpec::getP() const throw () +{ + return _p; +} + +const mpnumber& DHPrivateKeySpec::getG() const throw () +{ + return _g; +} + +const mpnumber& DHPrivateKeySpec::getX() const throw () +{ + return _x; +} diff --git a/beecrypt/c++/crypto/spec/DHPrivateKeySpec.h b/beecrypt/c++/crypto/spec/DHPrivateKeySpec.h new file mode 100644 index 0000000..d4dfefb --- /dev/null +++ b/beecrypt/c++/crypto/spec/DHPrivateKeySpec.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file DHPrivateKeySpec.h + * \ingroup CXX_CRYPTO_SPEC_m + */ + +#ifndef _CLASS_DHPRIVATEKEYSPEC_H +#define _CLASS_DHPRIVATEKEYSPEC_H + +#include "beecrypt/api.h" +#include "beecrypt/mpbarrett.h" + +#ifdef __cplusplus + +#include "beecrypt/c++/security/spec/KeySpec.h" +using beecrypt::security::spec::KeySpec; + +namespace beecrypt { + namespace crypto { + namespace spec { + class BEECRYPTCXXAPI DHPrivateKeySpec : public KeySpec + { + private: + mpbarrett _p; + mpnumber _g; + mpnumber _x; + + public: + DHPrivateKeySpec(const mpbarrett& p, const mpnumber& g, const mpnumber& x); + virtual ~DHPrivateKeySpec(); + + const mpbarrett& getP() const throw (); + const mpnumber& getG() const throw (); + const mpnumber& getX() const throw (); + }; + } + } +} + +#endif + +#endif diff --git a/beecrypt/c++/crypto/spec/DHPublicKeySpec.cxx b/beecrypt/c++/crypto/spec/DHPublicKeySpec.cxx new file mode 100644 index 0000000..15431cb --- /dev/null +++ b/beecrypt/c++/crypto/spec/DHPublicKeySpec.cxx @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#include "beecrypt/c++/crypto/spec/DHPublicKeySpec.h" + +using namespace beecrypt::crypto::spec; + +DHPublicKeySpec::DHPublicKeySpec(const mpbarrett& p, const mpnumber& g, const mpnumber& y) +{ + _p = p; + _g = g; + _y = y; +} + +DHPublicKeySpec::~DHPublicKeySpec() +{ +} + +const mpbarrett& DHPublicKeySpec::getP() const throw () +{ + return _p; +} + +const mpnumber& DHPublicKeySpec::getG() const throw () +{ + return _g; +} + +const mpnumber& DHPublicKeySpec::getY() const throw () +{ + return _y; +} diff --git a/beecrypt/c++/crypto/spec/DHPublicKeySpec.h b/beecrypt/c++/crypto/spec/DHPublicKeySpec.h new file mode 100644 index 0000000..a5a7468 --- /dev/null +++ b/beecrypt/c++/crypto/spec/DHPublicKeySpec.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file DHPublicKeySpec.h + * \ingroup CXX_CRYPTO_SPEC_m + */ + +#ifndef _CLASS_DHPUBLICKEYSPEC_H +#define _CLASS_DHPUBLICKEYSPEC_H + +#include "beecrypt/api.h" +#include "beecrypt/mpbarrett.h" + +#ifdef __cplusplus + +#include "beecrypt/c++/security/spec/KeySpec.h" +using beecrypt::security::spec::KeySpec; + +namespace beecrypt { + namespace crypto { + namespace spec { + class BEECRYPTCXXAPI DHPublicKeySpec : public KeySpec + { + private: + mpbarrett _p; + mpnumber _g; + mpnumber _y; + + public: + DHPublicKeySpec(const mpbarrett& p, const mpnumber& g, const mpnumber& y); + virtual ~DHPublicKeySpec(); + + const mpbarrett& getP() const throw (); + const mpnumber& getG() const throw (); + const mpnumber& getY() const throw (); + }; + } + } +} + +#endif + +#endif diff --git a/beecrypt/c++/crypto/spec/Makefile.am b/beecrypt/c++/crypto/spec/Makefile.am new file mode 100644 index 0000000..234feca --- /dev/null +++ b/beecrypt/c++/crypto/spec/Makefile.am @@ -0,0 +1,19 @@ +INCLUDES = -I$(top_srcdir)/.. + +AUTOMAKE_OPTIONS = gnu no-dependencies + +noinst_LTLIBRARIES = libcxxcryptospec.la + +cxxcryptospecdir=$(pkgincludedir)/c++/crypto/spec + +libcxxcryptospec_la_SOURCES =\ +DHParameterSpec.cxx \ +DHPrivateKeySpec.cxx \ +DHPublicKeySpec.cxx \ +PBEKeySpec.cxx + +cxxcryptospec_HEADERS =\ +DHParameterSpec.h \ +DHPrivateKeySpec.h \ +DHPublicKeySpec.h \ +PBEKeySpec.h diff --git a/beecrypt/c++/crypto/spec/Makefile.in b/beecrypt/c++/crypto/spec/Makefile.in new file mode 100644 index 0000000..684b1a0 --- /dev/null +++ b/beecrypt/c++/crypto/spec/Makefile.in @@ -0,0 +1,496 @@ +# Makefile.in generated by automake 1.8.3 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + + +SOURCES = $(libcxxcryptospec_la_SOURCES) + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +top_builddir = ../../.. +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +INSTALL = @INSTALL@ +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +host_triplet = @host@ +subdir = c++/crypto/spec +DIST_COMMON = $(cxxcryptospec_HEADERS) $(srcdir)/Makefile.am \ + $(srcdir)/Makefile.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \ + $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +LTLIBRARIES = $(noinst_LTLIBRARIES) +libcxxcryptospec_la_LIBADD = +am_libcxxcryptospec_la_OBJECTS = DHParameterSpec.lo \ + DHPrivateKeySpec.lo DHPublicKeySpec.lo PBEKeySpec.lo +libcxxcryptospec_la_OBJECTS = $(am_libcxxcryptospec_la_OBJECTS) +DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir) +depcomp = +am__depfiles_maybe = +CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) +LTCXXCOMPILE = $(LIBTOOL) --mode=compile $(CXX) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CXXFLAGS) $(CXXFLAGS) +CXXLD = $(CXX) +CXXLINK = $(LIBTOOL) --mode=link $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) \ + $(AM_LDFLAGS) $(LDFLAGS) -o $@ +SOURCES = $(libcxxcryptospec_la_SOURCES) +DIST_SOURCES = $(libcxxcryptospec_la_SOURCES) +am__installdirs = "$(DESTDIR)$(cxxcryptospecdir)" +cxxcryptospecHEADERS_INSTALL = $(INSTALL_HEADER) +HEADERS = $(cxxcryptospec_HEADERS) +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMDEP_FALSE = @AMDEP_FALSE@ +AMDEP_TRUE = @AMDEP_TRUE@ +AMTAR = @AMTAR@ +AR = @AR@ +AS = @AS@ +ASM_ALIGN = @ASM_ALIGN@ +ASM_ARCH = @ASM_ARCH@ +ASM_BIGENDIAN = @ASM_BIGENDIAN@ +ASM_CPU = @ASM_CPU@ +ASM_GLOBL = @ASM_GLOBL@ +ASM_GSYM_PREFIX = @ASM_GSYM_PREFIX@ +ASM_LSYM_PREFIX = @ASM_LSYM_PREFIX@ +ASM_OS = @ASM_OS@ +ASM_TEXTSEG = @ASM_TEXTSEG@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCAS = @CCAS@ +CCASFLAGS = @CCASFLAGS@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DLLTOOL = @DLLTOOL@ +ECHO = @ECHO@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +F77 = @F77@ +FFLAGS = @FFLAGS@ +INCLUDE_DLFCN_H = @INCLUDE_DLFCN_H@ +INCLUDE_INTTYPES_H = @INCLUDE_INTTYPES_H@ +INCLUDE_MALLOC_H = @INCLUDE_MALLOC_H@ +INCLUDE_PTHREAD_H = @INCLUDE_PTHREAD_H@ +INCLUDE_STDINT_H = @INCLUDE_STDINT_H@ +INCLUDE_STDIO_H = @INCLUDE_STDIO_H@ +INCLUDE_STDLIB_H = @INCLUDE_STDLIB_H@ +INCLUDE_STRING_H = @INCLUDE_STRING_H@ +INCLUDE_SYNCH_H = @INCLUDE_SYNCH_H@ +INCLUDE_THREAD_H = @INCLUDE_THREAD_H@ +INCLUDE_UNISTD_H = @INCLUDE_UNISTD_H@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +JAVAINC = @JAVAINC@ +LDFLAGS = @LDFLAGS@ +LIBALT = @LIBALT@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +MAYBE_LTLIB = @MAYBE_LTLIB@ +MAYBE_SUB = @MAYBE_SUB@ +MP_WBITS = @MP_WBITS@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PYTHONINC = @PYTHONINC@ +PYTHONLIB = @PYTHONLIB@ +RANLIB = @RANLIB@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +TYPEDEF_BC_COND_T = @TYPEDEF_BC_COND_T@ +TYPEDEF_BC_MUTEX_T = @TYPEDEF_BC_MUTEX_T@ +TYPEDEF_BC_THREAD_T = @TYPEDEF_BC_THREAD_T@ +TYPEDEF_INT16_T = @TYPEDEF_INT16_T@ +TYPEDEF_INT32_T = @TYPEDEF_INT32_T@ +TYPEDEF_INT64_T = @TYPEDEF_INT64_T@ +TYPEDEF_INT8_T = @TYPEDEF_INT8_T@ +TYPEDEF_SIZE_T = @TYPEDEF_SIZE_T@ +TYPEDEF_UINT16_T = @TYPEDEF_UINT16_T@ +TYPEDEF_UINT32_T = @TYPEDEF_UINT32_T@ +TYPEDEF_UINT64_T = @TYPEDEF_UINT64_T@ +TYPEDEF_UINT8_T = @TYPEDEF_UINT8_T@ +VERSION = @VERSION@ +ac_ct_AR = @ac_ct_AR@ +ac_ct_AS = @ac_ct_AS@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DLLTOOL = @ac_ct_DLLTOOL@ +ac_ct_F77 = @ac_ct_F77@ +ac_ct_OBJDUMP = @ac_ct_OBJDUMP@ +ac_ct_RANLIB = @ac_ct_RANLIB@ +ac_ct_STRIP = @ac_ct_STRIP@ +ac_cv_have_gcj = @ac_cv_have_gcj@ +ac_cv_have_java = @ac_cv_have_java@ +ac_cv_have_javac = @ac_cv_have_javac@ +ac_cv_have_python = @ac_cv_have_python@ +am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ +am__fastdepCC_TRUE = @am__fastdepCC_TRUE@ +am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@ +am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +datadir = @datadir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +sysconfdir = @sysconfdir@ +target = @target@ +target_alias = @target_alias@ +target_cpu = @target_cpu@ +target_os = @target_os@ +target_vendor = @target_vendor@ +INCLUDES = -I$(top_srcdir)/.. +AUTOMAKE_OPTIONS = gnu no-dependencies +noinst_LTLIBRARIES = libcxxcryptospec.la +cxxcryptospecdir = $(pkgincludedir)/c++/crypto/spec +libcxxcryptospec_la_SOURCES = \ +DHParameterSpec.cxx \ +DHPrivateKeySpec.cxx \ +DHPublicKeySpec.cxx \ +PBEKeySpec.cxx + +cxxcryptospec_HEADERS = \ +DHParameterSpec.h \ +DHPrivateKeySpec.h \ +DHPublicKeySpec.h \ +PBEKeySpec.h + +all: all-am + +.SUFFIXES: +.SUFFIXES: .cxx .lo .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ + && exit 0; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu c++/crypto/spec/Makefile'; \ + cd $(top_srcdir) && \ + $(AUTOMAKE) --gnu c++/crypto/spec/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +clean-noinstLTLIBRARIES: + -test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES) + @list='$(noinst_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" = "$$p" && dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +libcxxcryptospec.la: $(libcxxcryptospec_la_OBJECTS) $(libcxxcryptospec_la_DEPENDENCIES) + $(CXXLINK) $(libcxxcryptospec_la_LDFLAGS) $(libcxxcryptospec_la_OBJECTS) $(libcxxcryptospec_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +.cxx.o: + $(CXXCOMPILE) -c -o $@ $< + +.cxx.obj: + $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +.cxx.lo: + $(LTCXXCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +distclean-libtool: + -rm -f libtool +uninstall-info-am: +install-cxxcryptospecHEADERS: $(cxxcryptospec_HEADERS) + @$(NORMAL_INSTALL) + test -z "$(cxxcryptospecdir)" || $(mkdir_p) "$(DESTDIR)$(cxxcryptospecdir)" + @list='$(cxxcryptospec_HEADERS)'; for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + f="`echo $$p | sed -e 's|^.*/||'`"; \ + echo " $(cxxcryptospecHEADERS_INSTALL) '$$d$$p' '$(DESTDIR)$(cxxcryptospecdir)/$$f'"; \ + $(cxxcryptospecHEADERS_INSTALL) "$$d$$p" "$(DESTDIR)$(cxxcryptospecdir)/$$f"; \ + done + +uninstall-cxxcryptospecHEADERS: + @$(NORMAL_UNINSTALL) + @list='$(cxxcryptospec_HEADERS)'; for p in $$list; do \ + f="`echo $$p | sed -e 's|^.*/||'`"; \ + echo " rm -f '$(DESTDIR)$(cxxcryptospecdir)/$$f'"; \ + rm -f "$(DESTDIR)$(cxxcryptospecdir)/$$f"; \ + done + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(ETAGS_ARGS)$$tags$$unique" \ + || $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$tags $$unique +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(CTAGS_ARGS)$$tags$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$tags $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && cd $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) $$here + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \ + list='$(DISTFILES)'; for file in $$list; do \ + case $$file in \ + $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \ + $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \ + esac; \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test "$$dir" != "$$file" && test "$$dir" != "."; then \ + dir="/$$dir"; \ + $(mkdir_p) "$(distdir)$$dir"; \ + else \ + dir=''; \ + fi; \ + if test -d $$d/$$file; then \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + fi; \ + cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ + else \ + test -f $(distdir)/$$file \ + || cp -p $$d/$$file $(distdir)/$$file \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(LTLIBRARIES) $(HEADERS) +installdirs: + for dir in "$(DESTDIR)$(cxxcryptospecdir)"; do \ + test -z "$$dir" || $(mkdir_p) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -rm -f $(CONFIG_CLEAN_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libtool clean-noinstLTLIBRARIES \ + mostlyclean-am + +distclean: distclean-am + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-libtool distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +info: info-am + +info-am: + +install-data-am: install-cxxcryptospecHEADERS + +install-exec-am: + +install-info: install-info-am + +install-man: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-cxxcryptospecHEADERS uninstall-info-am + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-libtool clean-noinstLTLIBRARIES ctags distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-tags distdir dvi dvi-am html html-am info info-am \ + install install-am install-cxxcryptospecHEADERS install-data \ + install-data-am install-exec install-exec-am install-info \ + install-info-am install-man install-strip installcheck \ + installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags uninstall uninstall-am uninstall-cxxcryptospecHEADERS \ + uninstall-info-am + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/beecrypt/c++/crypto/spec/PBEKeySpec.cxx b/beecrypt/c++/crypto/spec/PBEKeySpec.cxx new file mode 100644 index 0000000..38ad49b --- /dev/null +++ b/beecrypt/c++/crypto/spec/PBEKeySpec.cxx @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/crypto/spec/PBEKeySpec.h" + +using namespace beecrypt::crypto::spec; + +PBEKeySpec::PBEKeySpec(const array* password) : _password(password ? *password : 0) +{ + _salt = 0; + _iteration_count = 0; + _key_length = 0; +} + +PBEKeySpec::PBEKeySpec(const array* password, const bytearray* salt, size_t iterationCount, size_t keyLength) : _password(password ? *password : 0) +{ + if (salt) + _salt = new bytearray(*salt); + _iteration_count = iterationCount; + _key_length = keyLength; +} + +PBEKeySpec::~PBEKeySpec() +{ +} + +const array& PBEKeySpec::getPassword() const throw () +{ + return _password; +} + +const bytearray* PBEKeySpec::getSalt() const throw () +{ + return _salt; +} + +size_t PBEKeySpec::getIterationCount() const throw () +{ + return _iteration_count; +} + +size_t PBEKeySpec::getKeyLength() const throw () +{ + return _key_length; +} diff --git a/beecrypt/c++/crypto/spec/PBEKeySpec.h b/beecrypt/c++/crypto/spec/PBEKeySpec.h new file mode 100644 index 0000000..d4cf14b --- /dev/null +++ b/beecrypt/c++/crypto/spec/PBEKeySpec.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file PBEKeySpec.h + * \ingroup CXX_CRYPTO_SPEC_m + */ + +#ifndef _CLASS_PBEKEYSPEC_H +#define _CLASS_PBEKEYSPEC_H + +#ifdef __cplusplus + +#include "beecrypt/c++/array.h" +using beecrypt::array; +using beecrypt::bytearray; +#include "beecrypt/c++/security/spec/KeySpec.h" +using beecrypt::security::spec::KeySpec; + +namespace beecrypt { + namespace crypto { + namespace spec { + class BEECRYPTCXXAPI PBEKeySpec : public KeySpec + { + private: + array _password; + bytearray* _salt; + size_t _iteration_count; + size_t _key_length; + + public: + PBEKeySpec(const array* password); + PBEKeySpec(const array* password, const bytearray* salt, size_t iterationCount, size_t keyLength); + virtual ~PBEKeySpec(); + + const array& getPassword() const throw (); + const bytearray* getSalt() const throw (); + size_t getIterationCount() const throw (); + size_t getKeyLength() const throw (); + }; + } + } +} + +#endif + +#endif diff --git a/beecrypt/c++/io/ByteArrayInputStream.cxx b/beecrypt/c++/io/ByteArrayInputStream.cxx new file mode 100644 index 0000000..415d77e --- /dev/null +++ b/beecrypt/c++/io/ByteArrayInputStream.cxx @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/io/ByteArrayInputStream.h" +#include "beecrypt/c++/lang/NullPointerException.h" +using beecrypt::lang::NullPointerException; + +using namespace beecrypt::io; + +ByteArrayInputStream::ByteArrayInputStream(const bytearray& b) : _buf(b) +{ + _lock.init(); + _count = _buf.size(); + _mark = 0; + _pos = 0; +} + +ByteArrayInputStream::ByteArrayInputStream(const byte* data, size_t offset, size_t length) : _buf(data+offset, length) +{ + _lock.init(); + _count = _buf.size(); + _mark = 0; + _pos = 0; +} + +ByteArrayInputStream::~ByteArrayInputStream() +{ + _lock.destroy(); +} + +off_t ByteArrayInputStream::available() throw (IOException) +{ + return (off_t)(_count - _pos); +} + +void ByteArrayInputStream::close() throw (IOException) +{ +} + +void ByteArrayInputStream::mark(off_t readlimit) throw () +{ + _mark = _pos; +} + +bool ByteArrayInputStream::markSupported() throw () +{ + return true; +} + +int ByteArrayInputStream::read() throw (IOException) +{ + register int rc; + _lock.lock(); + rc = (_pos < _count) ? _buf[_pos++] : -1; + _lock.unlock(); + return rc; +} + +int ByteArrayInputStream::read(byte* data, size_t offset, size_t length) throw (IOException) +{ + if (!data) + throw NullPointerException(); + + _lock.lock(); + if (_pos >= _count) + { + _lock.unlock(); + return -1; + } + + if (_pos + length > _count) + length = _count - _pos; + + if (length == 0) + { + _lock.unlock(); + return 0; + } + + memcpy(data+offset, _buf.data()+_pos, length); + _pos += length; + + _lock.unlock(); + + return length; +} + +int ByteArrayInputStream::read(bytearray& b) throw (IOException) +{ + return read(b.data(), 0, b.size()); +} + +void ByteArrayInputStream::reset() throw (IOException) +{ + _lock.lock(); + _pos = _mark; + _lock.unlock(); +} + +off_t ByteArrayInputStream::skip(off_t n) throw (IOException) +{ + _lock.lock(); + if (_pos + n > _count) + n = _count - _pos; + _pos += n; + _lock.unlock(); + return n; +} diff --git a/beecrypt/c++/io/ByteArrayInputStream.h b/beecrypt/c++/io/ByteArrayInputStream.h new file mode 100644 index 0000000..60c9d5e --- /dev/null +++ b/beecrypt/c++/io/ByteArrayInputStream.h @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file ByteArrayInputStream.h + * \ingroup CXX_IO_m + */ + +#ifndef _CLASS_BYTEARRAYINPUTSTREAM_H +#define _CLASS_BYTEARRAYINPUTSTREAM_H + +#ifdef __cplusplus + +#include "beecrypt/c++/array.h" +using beecrypt::bytearray; +#include "beecrypt/c++/mutex.h" +using beecrypt::mutex; +#include "beecrypt/c++/io/InputStream.h" +using beecrypt::io::InputStream; + +namespace beecrypt { + namespace io { + class BEECRYPTCXXAPI ByteArrayInputStream : public InputStream + { + private: + mutex _lock; + + protected: + bytearray _buf; + size_t _count; + size_t _mark; + size_t _pos; + + public: + ByteArrayInputStream(const byte* data, size_t offset, size_t length); + ByteArrayInputStream(const bytearray& b); + virtual ~ByteArrayInputStream(); + + virtual off_t available() throw (IOException); + virtual void close() throw (IOException); + virtual void mark(off_t readlimit) throw (); + virtual bool markSupported() throw (); + virtual int read() throw (IOException); + virtual int read(byte* data, size_t offset, size_t length) throw (IOException); + virtual int read(bytearray&) throw (IOException); + virtual void reset() throw (IOException); + virtual off_t skip(off_t n) throw (IOException); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/io/ByteArrayOutputStream.cxx b/beecrypt/c++/io/ByteArrayOutputStream.cxx new file mode 100644 index 0000000..a45a031 --- /dev/null +++ b/beecrypt/c++/io/ByteArrayOutputStream.cxx @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/io/ByteArrayOutputStream.h" +#include "beecrypt/c++/lang/NullPointerException.h" +using beecrypt::lang::NullPointerException; + +using namespace beecrypt::io; + +ByteArrayOutputStream::ByteArrayOutputStream() : _buf(32) +{ + _lock.init(); + _count = 0; +} + +ByteArrayOutputStream::ByteArrayOutputStream(size_t size) : _buf(size) +{ + _lock.init(); + _count = 0; +} + +ByteArrayOutputStream::~ByteArrayOutputStream() +{ + _lock.destroy(); +} + +void ByteArrayOutputStream::reset() throw () +{ + _count = 0; +} + +size_t ByteArrayOutputStream::size() throw () +{ + return _count; +} + +bytearray* ByteArrayOutputStream::toByteArray() +{ + bytearray* result = new bytearray(); + + toByteArray(*result); + + return result; +} + +void ByteArrayOutputStream::toByteArray(bytearray& b) +{ + _lock.lock(); + + b.resize(_count); + memcpy(b.data(), _buf.data(), _count); + + _lock.unlock(); +} + +void ByteArrayOutputStream::close() throw (IOException) +{ +} + +void ByteArrayOutputStream::flush() throw (IOException) +{ +} + +void ByteArrayOutputStream::write(byte b) throw (IOException) +{ + _lock.lock(); + + size_t newcount = _count+1; + size_t actualsz = _buf.size(); + + if (actualsz < newcount) + { + if (actualsz == 0) + _buf.resize(32); + else + _buf.resize(actualsz << 1); + } + + _buf[_count++] = b; + + _lock.unlock(); +} + +void ByteArrayOutputStream::write(const byte* data, size_t offset, size_t length) throw (IOException) +{ + if (!data) + throw NullPointerException(); + + _lock.lock(); + + size_t newcount = _count + length; + size_t actualsz = _buf.size(); + + if (newcount > actualsz) + { + _buf.resize(newcount > (actualsz << 1) ? newcount : (actualsz << 1)); + } + memcpy(_buf.data()+_count, data, length); + _count += length; + _lock.unlock(); +} + +void ByteArrayOutputStream::write(const bytearray& b) throw (IOException) +{ + write(b.data(), 0, b.size()); +} diff --git a/beecrypt/c++/io/ByteArrayOutputStream.h b/beecrypt/c++/io/ByteArrayOutputStream.h new file mode 100644 index 0000000..febae87 --- /dev/null +++ b/beecrypt/c++/io/ByteArrayOutputStream.h @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file ByteArrayOutputStream.h + * \ingroup CXX_IO_m + */ + +#ifndef _CLASS_BYTEARRAYOUTPUTSTREAM_H +#define _CLASS_BYTEARRAYOUTPUTSTREAM_H + +#ifdef __cplusplus + +#include "beecrypt/c++/mutex.h" +using beecrypt::mutex; +#include "beecrypt/c++/io/OutputStream.h" +using beecrypt::io::OutputStream; + +namespace beecrypt { + namespace io { + class BEECRYPTCXXAPI ByteArrayOutputStream : public OutputStream + { + private: + mutex _lock; + + protected: + bytearray _buf; + size_t _count; + + public: + ByteArrayOutputStream(); + ByteArrayOutputStream(size_t); + virtual ~ByteArrayOutputStream(); + + void reset() throw (); + size_t size() throw (); + bytearray* toByteArray(); + void toByteArray(bytearray&); + void writeTo(OutputStream& out) throw (IOException); + + virtual void close() throw (IOException); + virtual void flush() throw (IOException); + virtual void write(byte b) throw (IOException); + virtual void write(const byte* data, size_t offset, size_t length) throw (IOException); + virtual void write(const bytearray& b) throw (IOException); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/io/DataInput.h b/beecrypt/c++/io/DataInput.h new file mode 100644 index 0000000..ce1d5d1 --- /dev/null +++ b/beecrypt/c++/io/DataInput.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file DataInput.h + * \ingroup CXX_IO_m + */ + +#ifndef _INTERFACE_DATAINPUT_H +#define _INTERFACE_DATAINPUT_H + +#ifdef __cplusplus + +#include "beecrypt/c++/array.h" +using beecrypt::bytearray; +#include "beecrypt/c++/io/IOException.h" +using beecrypt::io::IOException; + +namespace beecrypt { + namespace io { + class DataInput + { + public: + virtual bool readBoolean() throw (IOException) = 0; + virtual javabyte readByte() throw (IOException) = 0; + virtual javachar readChar() throw (IOException) = 0; + virtual void readFully(byte*, size_t, size_t) = 0; + virtual void readFully(bytearray&) = 0; + virtual javaint readInt() throw (IOException) = 0; + virtual String* readLine() throw (IOException) = 0; + virtual void readLine(String&) throw (IOException) = 0; + virtual javalong readLong() throw (IOException) = 0; + virtual javashort readShort() throw (IOException) = 0; + virtual int readUnsignedByte() throw (IOException) = 0; + virtual int readUnsignedShort() throw (IOException) = 0; + virtual String* readUTF() throw (IOException) = 0; + virtual void readUTF(String&) throw (IOException) = 0; + virtual off_t skipBytes(off_t n) throw (IOException) = 0; + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/io/DataInputStream.cxx b/beecrypt/c++/io/DataInputStream.cxx new file mode 100644 index 0000000..54ae57b --- /dev/null +++ b/beecrypt/c++/io/DataInputStream.cxx @@ -0,0 +1,370 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/io/DataInputStream.h" +#include "beecrypt/c++/io/EOFException.h" +#include "beecrypt/c++/io/PushbackInputStream.h" +#include "beecrypt/c++/lang/NullPointerException.h" +using beecrypt::lang::NullPointerException; + +#define MAX_BYTES_PER_CHARACTER 8 + +using namespace beecrypt::io; + +DataInputStream::DataInputStream(InputStream& in) : FilterInputStream(in) +{ + _pin = ∈ + _del = false; + _utf = 0; + _loc = 0; +} + +DataInputStream::~DataInputStream() +{ + if (_utf) + { + ucnv_close(_utf); + _utf = 0; + } + + if (_loc) + { + ucnv_close(_loc); + _loc = 0; + } + + if (_del) + { + delete _pin; + _pin = 0; + } +} + +bool DataInputStream::readBoolean() throw (IOException) +{ + register int b = _pin->read(); + + if (b < 0) + throw EOFException(); + + return (b != 0); +} + +javabyte DataInputStream::readByte() throw (IOException) +{ + register int b = _pin->read(); + + if (b < 0) + throw EOFException(); + + return static_cast(b); +} + +int DataInputStream::readUnsignedByte() throw (IOException) +{ + register int b = _pin->read(); + + if (b < 0) + throw EOFException(); + + return b; +} + +javashort DataInputStream::readShort() throw (IOException) +{ + register javashort tmp = 0; + register int rc; + + for (register unsigned i = 0; i < 2; i++) + { + if ((rc = _pin->read()) < 0) + throw EOFException(); + + tmp = (tmp << 8) + rc; + } + + return tmp; +} + +int DataInputStream::readUnsignedShort() throw (IOException) +{ + register int tmp = 0, rc; + + for (register unsigned i = 0; i < 2; i++) + { + if ((rc = _pin->read()) < 0) + throw EOFException(); + + tmp = (tmp << 8) + rc; + } + + return tmp; +} + +javachar DataInputStream::readChar() throw (IOException) +{ + register javachar tmp = 0; + register int rc; + + for (register unsigned i = 0; i < 2; i++) + { + if ((rc = _pin->read()) < 0) + throw EOFException(); + + tmp = (tmp << 8) + rc; + } + + return tmp; +} + +javaint DataInputStream::readInt() throw (IOException) +{ + register javaint tmp = 0; + register int rc; + + for (register unsigned i = 0; i < 4; i++) + { + if ((rc = _pin->read()) < 0) + throw EOFException(); + + tmp = (tmp << 8) + rc; + } + + return tmp; +} + +javalong DataInputStream::readLong() throw (IOException) +{ + register javalong tmp = 0; + register int rc; + + for (register unsigned i = 0; i < 8; i++) + { + if ((rc = _pin->read()) < 0) + throw EOFException(); + + tmp = (tmp << 8) + rc; + } + + return tmp; +} + +void DataInputStream::readUTF(String& str) throw (IOException) +{ + UErrorCode status = U_ZERO_ERROR; + + if (!_utf) + { + // UTF-8 converter lazy initialization + _utf = ucnv_open("UTF-8", &status); + if (U_FAILURE(status)) + throw IOException("unable to open ICU UTF-8 converter"); + } + + int utflen = readUnsignedShort(); + + if (utflen > 0) + { + byte* data = new byte[utflen]; + + readFully(data, 0, utflen); + + status = U_ZERO_ERROR; + size_t ulen = ucnv_toUChars(_utf, 0, 0, (const char*) data, (size_t) utflen, &status); + if (status != U_BUFFER_OVERFLOW_ERROR) + { + delete[] data; + throw "error in ucnv_toUChars"; + } + + UChar* buffer = str.getBuffer(ulen+1); + + if (buffer) + { + status = U_ZERO_ERROR; + ucnv_toUChars(_utf, buffer, ulen+1, (const char*) data, (size_t) utflen, &status); + + delete[] data; + + if (status != U_ZERO_ERROR) + throw "error in ucnv_toUChars"; + + str.releaseBuffer(ulen); + } + else + { + delete[] data; + throw "error in String::getBuffer(size_t)"; + } + } +} + +String* DataInputStream::readUTF() throw (IOException) +{ + String* str = new String(); + + try + { + readUTF(*str); + } + catch (IOException ex) + { + /* cleanup str */ + delete str; + /* re-throw exception */ + throw ex; + } + return str; +} + +String* DataInputStream::readLine() throw (IOException) +{ + String* result = new String(); + + readLine(*result); + + return result; +} + +void DataInputStream::readLine(String& line) throw (IOException) +{ + UErrorCode status = U_ZERO_ERROR; + + if (!_loc) + { + // default locale converter lazy initialization + _loc = ucnv_open(0, &status); + if (U_FAILURE(status)) + throw IOException("unable to open ICU default locale converter"); + } + + UChar target_buffer[1]; + UChar* target = target_buffer; + const UChar* target_limit = target_buffer+1; + char source_buffer[MAX_BYTES_PER_CHARACTER]; + const char* source = source_buffer; + char* source_limit = source_buffer; + + bool cr = false; + + int ch; + + // clear the line + line.remove(); + + do + { + ch = _pin->read(); + + if (ch >= 0) + { + if ((source_limit-source_buffer) == MAX_BYTES_PER_CHARACTER) + throw IOException("fubar in readLine"); + + *(source_limit++) = (byte) ch; + } + + status = U_ZERO_ERROR; + // use the default locale converter; flush if ch == -1 + ucnv_toUnicode(_loc, &target, target_limit, &source, source_limit, NULL, (UBool) (ch == -1), &status); + + if (U_FAILURE(status)) + throw IOException("error in ucnv_toUnicode"); + + if (target == target_limit) + { + // we got a whole character from the converter + if (cr) + { + // last character read was ASCII ; is this one a ? + if (target_buffer[0] != 0x0A) + { + // unread the right number of bytes + PushbackInputStream* p = dynamic_cast(_pin); + if (p) + p->unread((const byte*) source_buffer, 0, source-source_buffer); + else + throw IOException("fubar in dynamic_cast"); + } + // we're now officially at the end of the line + break; + } + + // did we get an ASCII ? + if (target_buffer[0] == 0x0A) + break; + + // did we get an ASCII ? + if (target_buffer[0] == 0x0D) + { + cr = true; + + // the next character may be a but if not we'll have to 'unread' it + if (!_del) + { + // lazy push + _pin = new PushbackInputStream(in, MAX_BYTES_PER_CHARACTER); + _del = true; + } + } + else + { + // append character to string and reset pointers + source = source_limit = source_buffer; + line.append(*(target = target_buffer)); + } + } + } while (ch >= 0); +} + +void DataInputStream::readFully(byte* data, size_t offset, size_t length) throw (IOException) +{ + if (!data) + throw NullPointerException(); + + size_t total = 0; + + while (total < length) + { + int rc = _pin->read(data, offset+total, length-total); + if (rc < 0) + throw EOFException(); + total += rc; + } +} + +void DataInputStream::readFully(bytearray& b) throw (IOException) +{ + readFully(b.data(), 0, b.size()); +} + +off_t DataInputStream::skipBytes(off_t n) throw (IOException) +{ + off_t total = 0, rc; + + while ((total < n) && ((rc = _pin->skip(n - total)) > 0)) + total += rc; + + return total; +} diff --git a/beecrypt/c++/io/DataInputStream.h b/beecrypt/c++/io/DataInputStream.h new file mode 100644 index 0000000..2dd4c01 --- /dev/null +++ b/beecrypt/c++/io/DataInputStream.h @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file DataInputStream.h + * \ingroup CXX_IO_m + */ + +#ifndef _CLASS_DATAINPUTSTREAM_H +#define _CLASS_DATAINPUTSTREAM_H + +#ifdef __cplusplus + +#include "beecrypt/c++/io/DataInput.h" +using beecrypt::io::DataInput; +#include "beecrypt/c++/io/FilterInputStream.h" +using beecrypt::io::FilterInputStream; + +#include + +namespace beecrypt { + namespace io { + class BEECRYPTCXXAPI DataInputStream : public FilterInputStream, public DataInput + { + private: + bool _del; + InputStream* _pin; + UConverter* _utf; + UConverter* _loc; + + public: + DataInputStream(InputStream& in); + virtual ~DataInputStream(); + + virtual bool readBoolean() throw (IOException); + virtual javabyte readByte() throw (IOException); + virtual javachar readChar() throw (IOException); + virtual void readFully(byte* data, size_t offset, size_t length) throw (IOException); + virtual void readFully(bytearray& b) throw (IOException); + virtual javaint readInt() throw (IOException); + virtual String* readLine() throw (IOException); + virtual void readLine(String&) throw (IOException); + virtual javalong readLong() throw (IOException); + virtual javashort readShort() throw (IOException); + virtual int readUnsignedByte() throw (IOException); + virtual int readUnsignedShort() throw (IOException); + virtual String* readUTF() throw (IOException); + virtual void readUTF(String&) throw (IOException); + virtual off_t skipBytes(off_t n) throw (IOException); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/io/DataOutput.h b/beecrypt/c++/io/DataOutput.h new file mode 100644 index 0000000..2962a61 --- /dev/null +++ b/beecrypt/c++/io/DataOutput.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file DataOutput.h + * \ingroup CXX_IO_m + */ + +#ifndef _INTERFACE_DATAOUTPUT_H +#define _INTERFACE_DATAOUTPUT_H + +#ifdef __cplusplus + +#include "beecrypt/c++/array.h" +using beecrypt::bytearray; +#include "beecrypt/c++/io/IOException.h" +using beecrypt::io::IOException; + +namespace beecrypt { + namespace io { + class DataOutput + { + public: + virtual void write(const bytearray&) throw (IOException) = 0; + virtual void write(const byte*, size_t, size_t) throw (IOException) = 0; + virtual void write(byte) throw (IOException) = 0; + virtual void writeBoolean(bool) throw (IOException) = 0; + virtual void writeByte(byte) throw (IOException) = 0; + virtual void writeChars(const String&) throw (IOException) = 0; + virtual void writeInt(javaint) throw (IOException) = 0; + virtual void writeLong(javalong) throw (IOException) = 0; + virtual void writeShort(javashort) throw (IOException) = 0; + virtual void writeUTF(const String&) throw (IOException) = 0; + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/io/DataOutputStream.cxx b/beecrypt/c++/io/DataOutputStream.cxx new file mode 100644 index 0000000..c8f5445 --- /dev/null +++ b/beecrypt/c++/io/DataOutputStream.cxx @@ -0,0 +1,186 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/io/DataOutputStream.h" + +using namespace beecrypt::io; + +DataOutputStream::DataOutputStream(OutputStream& out) : FilterOutputStream(out) +{ + _lock.init(); + _utf = 0; + written = 0; +} + +DataOutputStream::~DataOutputStream() +{ + _lock.destroy(); + if (_utf) + ucnv_close(_utf); +} + +size_t DataOutputStream::size() const throw () +{ + return written; +} + +void DataOutputStream::write(byte b) throw (IOException) +{ + _lock.lock(); + out.write(b); + written++; + _lock.unlock(); +} + +void DataOutputStream::write(const byte* data, size_t offset, size_t len) throw (IOException) +{ + _lock.lock(); + out.write(data, offset, len); + written += len; + _lock.unlock(); +} + +void DataOutputStream::write(const bytearray& b) throw (IOException) +{ + write(b.data(), 0, b.size()); +} + +void DataOutputStream::writeBoolean(bool b) throw (IOException) +{ + _lock.lock(); + out.write(b ? 1 : 0); + written++; + _lock.unlock(); +} + +void DataOutputStream::writeByte(byte b) throw (IOException) +{ + _lock.lock(); + out.write(b); + written++; + _lock.unlock(); +} + +void DataOutputStream::writeShort(javashort s) throw (IOException) +{ + _lock.lock(); + out.write((s >> 8) ); + out.write((s ) & 0xff); + written += 2; + _lock.unlock(); +} + +void DataOutputStream::writeInt(javaint i) throw (IOException) +{ + _lock.lock(); + out.write((i >> 24) ); + out.write((i >> 16) & 0xff); + out.write((i >> 8) & 0xff); + out.write((i ) & 0xff); + written += 4; + _lock.unlock(); +} + +void DataOutputStream::writeLong(javalong l) throw (IOException) +{ + _lock.lock(); + out.write((l >> 56) ); + out.write((l >> 48) & 0xff); + out.write((l >> 40) & 0xff); + out.write((l >> 32) & 0xff); + out.write((l >> 24) & 0xff); + out.write((l >> 16) & 0xff); + out.write((l >> 8) & 0xff); + out.write((l ) & 0xff); + written += 8; + _lock.unlock(); +} + +void DataOutputStream::writeChars(const String& str) throw (IOException) +{ + const UChar* buffer = str.getBuffer(); + size_t len = str.length(); + + _lock.lock(); + for (size_t i = 0; i < len; i++) + { + out.write((buffer[i] >> 8) & 0xff); + out.write((buffer[i] ) & 0xff); + } + written += (len << 1); + _lock.unlock(); +} + +void DataOutputStream::writeUTF(const String& str) throw (IOException) +{ + UErrorCode status = U_ZERO_ERROR; + + if (!_utf) + { + // UTF-8 converter lazy initialization + _utf = ucnv_open("UTF-8", &status); + if (U_FAILURE(status)) + throw IOException("unable to open ICU UTF-8 converter"); + } + + // the expected status code here is U_BUFFER_OVERFLOW_ERROR + size_t need = ucnv_fromUChars(_utf, 0, 0, str.getBuffer(), str.length(), &status); + if (U_FAILURE(status)) + if (status != U_BUFFER_OVERFLOW_ERROR) + throw IOException("unexpected error in ucnv_fromUChars"); + + if (need > 0xffff) + throw IOException("String length >= 64K"); + + byte* buffer = new byte[need]; + + status = U_ZERO_ERROR; + + // the expected status code here is U_STRING_NOT_TERMINATED_WARNING + ucnv_fromUChars(_utf, (char*) buffer, need, str.getBuffer(), str.length(), &status); + if (status != U_STRING_NOT_TERMINATED_WARNING) + { + delete[] buffer; + throw IOException("error in ucnv_fromUChars"); + } + + // everything ready for the critical section + _lock.lock(); + try + { + out.write((need >> 8) & 0xff); + out.write((need ) & 0xff); + out.write(buffer, 0, need); + written += 2 + need; + _lock.unlock(); + + delete[] buffer; + } + catch (IOException) + { + _lock.unlock(); + delete[] buffer; + throw; + } +} diff --git a/beecrypt/c++/io/DataOutputStream.h b/beecrypt/c++/io/DataOutputStream.h new file mode 100644 index 0000000..ae09080 --- /dev/null +++ b/beecrypt/c++/io/DataOutputStream.h @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file DataOutputStream.h + * \ingroup CXX_IO_m + */ + +#ifndef _CLASS_DATAOUTPUTSTREAM_H +#define _CLASS_DATAOUTPUTSTREAM_H + +#ifdef __cplusplus + +#include "beecrypt/c++/mutex.h" +using beecrypt::mutex; +#include "beecrypt/c++/io/DataOutput.h" +using beecrypt::io::DataOutput; +#include "beecrypt/c++/io/FilterOutputStream.h" +using beecrypt::io::FilterOutputStream; + +#include + +namespace beecrypt { + namespace io { + class BEECRYPTCXXAPI DataOutputStream : public FilterOutputStream, public DataOutput + { + private: + mutex _lock; + UConverter* _utf; + + protected: + size_t written; + + public: + DataOutputStream(OutputStream& out); + virtual ~DataOutputStream(); + + size_t size() const throw (); + + virtual void write(byte) throw (IOException); + virtual void write(const byte* data, size_t offset, size_t length) throw (IOException); + virtual void write(const bytearray&) throw (IOException); + virtual void writeBoolean(bool) throw (IOException); + virtual void writeByte(byte) throw (IOException); + virtual void writeChars(const String&) throw (IOException); + virtual void writeInt(javaint) throw (IOException); + virtual void writeLong(javalong) throw (IOException); + virtual void writeShort(javashort) throw (IOException); + virtual void writeUTF(const String&) throw (IOException); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/io/EOFException.cxx b/beecrypt/c++/io/EOFException.cxx new file mode 100644 index 0000000..0498810 --- /dev/null +++ b/beecrypt/c++/io/EOFException.cxx @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/io/EOFException.h" + +using namespace beecrypt::io; + +EOFException::EOFException() throw () +{ +} + +EOFException::EOFException(const String& message) throw () : IOException(message) +{ +} diff --git a/beecrypt/c++/io/EOFException.h b/beecrypt/c++/io/EOFException.h new file mode 100644 index 0000000..ceb5508 --- /dev/null +++ b/beecrypt/c++/io/EOFException.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file EOFException.h + * \ingroup CXX_IO_m + */ + +#ifndef _CLASS_EOFEXCEPTION_H +#define _CLASS_EOFEXCEPTION_H + +#ifdef __cplusplus + +#include "beecrypt/c++/io/IOException.h" +using beecrypt::io::IOException; + +namespace beecrypt { + namespace io { + class BEECRYPTCXXAPI EOFException : public IOException + { + public: + EOFException() throw (); + EOFException(const String&) throw (); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/io/FileInputStream.cxx b/beecrypt/c++/io/FileInputStream.cxx new file mode 100644 index 0000000..49c096b --- /dev/null +++ b/beecrypt/c++/io/FileInputStream.cxx @@ -0,0 +1,172 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#if HAVE_ERRNO_H +# include +#endif + +#include "beecrypt/c++/io/FileInputStream.h" +#include "beecrypt/c++/lang/NullPointerException.h" +using beecrypt::lang::NullPointerException; + +using namespace beecrypt::io; + +FileInputStream::FileInputStream(FILE* f) +{ + _f = f; + _mark = -1; +} + +FileInputStream::~FileInputStream() +{ +} + +off_t FileInputStream::available() throw (IOException) +{ + if (!_f) + throw IOException("not a valid file handle"); + + long _curr, _size; + + if ((_curr = ftell(_f)) == -1) + #if HAVE_ERRNO_H + throw IOException(strerror(errno)); + #else + throw IOException("ftell failed"); + #endif + + if (fseek(_f, 0, SEEK_END)) + #if HAVE_ERRNO_H + throw IOException(strerror(errno)); + #else + throw IOException("fseek failed"); + #endif + + if ((_size = ftell(_f)) == -1) + #if HAVE_ERRNO_H + throw IOException(strerror(errno)); + #else + throw IOException("ftell failed"); + #endif + + if (fseek(_f, _curr, SEEK_SET)) + #if HAVE_ERRNO_H + throw IOException(strerror(errno)); + #else + throw IOException("fseek failed"); + #endif + + return (off_t) (_size - _curr); +} + +void FileInputStream::close() throw (IOException) +{ + if (_f) + { + if (fclose(_f)) + #if HAVE_ERRNO_H + throw IOException(strerror(errno)); + #else + throw IOException("fclose failed"); + #endif + + _f = 0; + } +} + +void FileInputStream::mark(off_t readlimit) throw () +{ + if (_f) + _mark = ftell(_f); +} + +bool FileInputStream::markSupported() throw () +{ + return true; +} + +int FileInputStream::read() throw (IOException) +{ + if (!_f) + throw IOException("not a valid file handle"); + + return fgetc(_f); +} + +int FileInputStream::read(byte* data, size_t offset, size_t length) throw (IOException) +{ + if (!_f) + throw IOException("not a valid file handle"); + + if (!data) + throw NullPointerException(); + + size_t rc = fread(data+offset, 1, length, _f); + + if (rc == 0) + return -1; + + return rc; +} + +int FileInputStream::read(bytearray& b) throw (IOException) +{ + return read(b.data(), 0, b.size()); +} + +void FileInputStream::reset() throw (IOException) +{ + if (!_f) + throw IOException("not a valid file handle"); + + if (_mark < 0) + throw IOException("not a valid mark"); + + if (fseek(_f, _mark, SEEK_SET)) + #if HAVE_ERRNO_H + throw IOException(strerror(errno)); + #else + throw IOException("fseek failed"); + #endif +} + +off_t FileInputStream::skip(off_t n) throw (IOException) +{ + if (!_f) + throw IOException("not a valid file handle"); + + off_t _avail = available(); + + if (n > _avail) + n = _avail; + + if (fseek(_f, (long) n, SEEK_CUR)) + #if HAVE_ERRNO_H + throw IOException(strerror(errno)); + #else + throw IOException("fseek failed"); + #endif + + return n; +} diff --git a/beecrypt/c++/io/FileInputStream.h b/beecrypt/c++/io/FileInputStream.h new file mode 100644 index 0000000..1f14a8f --- /dev/null +++ b/beecrypt/c++/io/FileInputStream.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file FileInputStream.h + * \ingroup CXX_IO_m + */ + +#ifndef _CLASS_FILEINPUTSTREAM_H +#define _CLASS_FILEINPUTSTREAM_H + +#include + +#ifdef __cplusplus + +#include "beecrypt/c++/io/InputStream.h" +using beecrypt::io::InputStream; + +namespace beecrypt { + namespace io { + class BEECRYPTCXXAPI FileInputStream : public InputStream + { + private: + FILE* _f; + long _mark; + + public: + FileInputStream(FILE* f); + virtual ~FileInputStream(); + + virtual off_t available() throw (IOException); + virtual void close() throw (IOException); + virtual void mark(off_t readlimit) throw (); + virtual bool markSupported() throw (); + virtual int read() throw (IOException); + virtual int read(byte* data, size_t offset, size_t length) throw (IOException); + virtual int read(bytearray&) throw (IOException); + virtual void reset() throw (IOException); + virtual off_t skip(off_t n) throw (IOException); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/io/FileOutputStream.cxx b/beecrypt/c++/io/FileOutputStream.cxx new file mode 100644 index 0000000..8f6d19d --- /dev/null +++ b/beecrypt/c++/io/FileOutputStream.cxx @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#if HAVE_ERRNO_H +# include +#endif + +#include "beecrypt/c++/io/FileOutputStream.h" +#include "beecrypt/c++/lang/NullPointerException.h" +using beecrypt::lang::NullPointerException; + +using namespace beecrypt::io; + +FileOutputStream::FileOutputStream(FILE *f) +{ + _f = f; +} + +FileOutputStream::~FileOutputStream() +{ +} + +void FileOutputStream::close() throw (IOException) +{ + if (_f) + { + if (fclose(_f)) + #if HAVE_ERRNO_H + throw IOException(strerror(errno)); + #else + throw IOException("fclose failed"); + #endif + + _f = 0; + } +} + +void FileOutputStream::flush() throw (IOException) +{ + if (!_f) + throw IOException("no valid file handle to flush"); + + if (fflush(_f)) + #if HAVE_ERRNO_H + throw IOException(strerror(errno)); + #else + throw IOException("fflush failed"); + #endif +} + +void FileOutputStream::write(byte b) throw (IOException) +{ + if (!_f) + throw IOException("no valid file handle to write"); + + size_t rc = fwrite(&b, 1, 1, _f); + + if (rc < 1) + #if HAVE_ERRNO_H + throw IOException(strerror(errno)); + #else + throw IOException("incomplete fwrite"); + #endif +} + +void FileOutputStream::write(const byte* data, size_t offset, size_t length) throw (IOException) +{ + if (!data) + throw NullPointerException(); + + if (!_f) + throw IOException("no valid file handle to write"); + + size_t rc = fwrite(data+offset, 1, length, _f); + + if (rc < length) + #if HAVE_ERRNO_H + throw IOException(strerror(errno)); + #else + throw IOException("incomplete fwrite"); + #endif +} + +void FileOutputStream::write(const bytearray& b) throw (IOException) +{ + write(b.data(), 0, b.size()); +} diff --git a/beecrypt/c++/io/FileOutputStream.h b/beecrypt/c++/io/FileOutputStream.h new file mode 100644 index 0000000..6afa4f3 --- /dev/null +++ b/beecrypt/c++/io/FileOutputStream.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file FileOutputStream.h + * \ingroup CXX_IO_m + */ + +#ifndef _CLASS_FILEOUTPUTSTREAM_H +#define _CLASS_FILEOUTPUTSTREAM_H + +#ifdef __cplusplus + +#include "beecrypt/c++/io/OutputStream.h" +using beecrypt::io::OutputStream; + +namespace beecrypt { + namespace io { + class BEECRYPTCXXAPI FileOutputStream : public OutputStream + { + private: + FILE* _f; + + public: + FileOutputStream(FILE* f); + virtual ~FileOutputStream(); + + virtual void close() throw (IOException); + virtual void flush() throw (IOException); + virtual void write(byte b) throw (IOException); + virtual void write(const byte* data, size_t offset, size_t length) throw (IOException); + virtual void write(const bytearray&) throw (IOException); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/io/FilterInputStream.cxx b/beecrypt/c++/io/FilterInputStream.cxx new file mode 100644 index 0000000..a049526 --- /dev/null +++ b/beecrypt/c++/io/FilterInputStream.cxx @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/io/FilterInputStream.h" + +using namespace beecrypt::io; + +FilterInputStream::FilterInputStream(InputStream& in) : in(in) +{ + _lock.init(); +} + +FilterInputStream::~FilterInputStream() +{ + _lock.destroy(); +} + +off_t FilterInputStream::available() throw (IOException) +{ + return in.available(); +} + +void FilterInputStream::close() throw (IOException) +{ + in.close(); +} + +void FilterInputStream::mark(off_t readlimit) throw () +{ + _lock.lock(); + in.mark(readlimit); + _lock.unlock(); +} + +bool FilterInputStream::markSupported() throw () +{ + return in.markSupported(); +} + +int FilterInputStream::read() throw (IOException) +{ + return in.read(); +} + +int FilterInputStream::read(byte* data, size_t offset, size_t len) throw (IOException) +{ + return in.read(data, offset, len); +} + +int FilterInputStream::read(bytearray& b) throw (IOException) +{ + return in.read(b); +} + +void FilterInputStream::reset() throw (IOException) +{ + _lock.lock(); + in.reset(); + _lock.unlock(); +} + +off_t FilterInputStream::skip(off_t n) throw (IOException) +{ + return in.skip(n); +} diff --git a/beecrypt/c++/io/FilterInputStream.h b/beecrypt/c++/io/FilterInputStream.h new file mode 100644 index 0000000..3132377 --- /dev/null +++ b/beecrypt/c++/io/FilterInputStream.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file FilterInputStream.h + * \ingroup CXX_IO_m + */ + +#ifndef _CLASS_FILTERINPUTSTREAM_H +#define _CLASS_FILTERINPUTSTREAM_H + +#ifdef __cplusplus + +#include "beecrypt/c++/mutex.h" +using beecrypt::mutex; +#include "beecrypt/c++/io/InputStream.h" +using beecrypt::io::InputStream; + +namespace beecrypt { + namespace io { + class BEECRYPTCXXAPI FilterInputStream : public InputStream + { + private: + mutex _lock; + + protected: + InputStream& in; + + public: + FilterInputStream(InputStream& in); + virtual ~FilterInputStream(); + + virtual off_t available() throw (IOException); + virtual void close() throw (IOException); + virtual void mark(off_t) throw (); + virtual bool markSupported() throw (); + virtual int read() throw (IOException); + virtual int read(byte* data, size_t offset, size_t length) throw (IOException); + virtual int read(bytearray& b) throw (IOException); + virtual void reset() throw (IOException); + virtual off_t skip(off_t) throw (IOException); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/io/FilterOutputStream.cxx b/beecrypt/c++/io/FilterOutputStream.cxx new file mode 100644 index 0000000..6131fe0 --- /dev/null +++ b/beecrypt/c++/io/FilterOutputStream.cxx @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/io/FilterOutputStream.h" + +using namespace beecrypt::io; + +FilterOutputStream::FilterOutputStream(OutputStream& out) : out(out) +{ +} + +FilterOutputStream::~FilterOutputStream() +{ +} + +void FilterOutputStream::close() throw (IOException) +{ + try + { + flush(); + } + catch (IOException) + { + // ignore + } + out.close(); +} + +void FilterOutputStream::flush() throw (IOException) +{ + out.flush(); +} + +void FilterOutputStream::write(byte b) throw (IOException) +{ + out.write(b); +} + +void FilterOutputStream::write(const byte* data, size_t offset, size_t len) throw (IOException) +{ + out.write(data, offset, len); +} + +void FilterOutputStream::write(const bytearray& b) throw (IOException) +{ + out.write(b.data(), 0, b.size()); +} diff --git a/beecrypt/c++/io/FilterOutputStream.h b/beecrypt/c++/io/FilterOutputStream.h new file mode 100644 index 0000000..bb76ce5 --- /dev/null +++ b/beecrypt/c++/io/FilterOutputStream.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file FilterOutputStream.h + * \ingroup CXX_IO_m + */ + +#ifndef _CLASS_FILTEROUTPUTSTREAM_H +#define _CLASS_FILTEROUTPUTSTREAM_H + +#ifdef __cplusplus + +#include "beecrypt/c++/io/OutputStream.h" +using beecrypt::io::OutputStream; + +namespace beecrypt { + namespace io { + class BEECRYPTCXXAPI FilterOutputStream : public OutputStream + { + protected: + OutputStream& out; + + public: + FilterOutputStream(OutputStream& out); + virtual ~FilterOutputStream(); + + virtual void close() throw (IOException); + virtual void flush() throw (IOException); + virtual void write(byte b) throw (IOException); + virtual void write(const byte* data, size_t offset, size_t length) throw (IOException); + virtual void write(const bytearray&) throw (IOException); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/io/IOException.cxx b/beecrypt/c++/io/IOException.cxx new file mode 100644 index 0000000..3cf3994 --- /dev/null +++ b/beecrypt/c++/io/IOException.cxx @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/io/IOException.h" + +using namespace beecrypt::io; + +IOException::IOException() +{ +} + +IOException::IOException(const String& message) : Exception(message) +{ +} diff --git a/beecrypt/c++/io/IOException.h b/beecrypt/c++/io/IOException.h new file mode 100644 index 0000000..69f9012 --- /dev/null +++ b/beecrypt/c++/io/IOException.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file IOException.h + * \ingroup CXX_IO_m + */ + +#ifndef _CLASS_IOEXCEPTION_H +#define _CLASS_IOEXCEPTION_H + +#ifdef __cplusplus + +#include "beecrypt/c++/lang/Exception.h" +using beecrypt::lang::Exception; + +namespace beecrypt { + namespace io { + class BEECRYPTCXXAPI IOException : public Exception + { + public: + IOException(); + IOException(const String&); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/io/InputStream.cxx b/beecrypt/c++/io/InputStream.cxx new file mode 100644 index 0000000..f586ce0 --- /dev/null +++ b/beecrypt/c++/io/InputStream.cxx @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/io/InputStream.h" +#include "beecrypt/c++/lang/NullPointerException.h" +using beecrypt::lang::NullPointerException; + +using namespace beecrypt::io; + +off_t InputStream::available() throw (IOException) +{ + return 0; +} + +void InputStream::close() throw (IOException) +{ +} + +void InputStream::mark(off_t readlimit) throw () +{ +} + +bool InputStream::markSupported() throw () +{ + return false; +} + +int InputStream::read(bytearray& b) throw (IOException) +{ + return read(b.data(), 0, b.size()); +} + +int InputStream::read(byte* data, size_t offset, size_t length) throw (IOException) +{ + if (!data) + throw NullPointerException(); + + int b = read(); + if (b < 0) + return -1; + + data[offset] = (byte) b; + + size_t i = 1; + try + { + while (i < length) + { + b = read(); + if (b < 0) + break; + data[offset+i++] = (byte) b; + } + } + catch (IOException) + { + // ignore + } + return i; +} + +off_t InputStream::skip(off_t n) throw (IOException) +{ + off_t remaining = n; + + byte skip[2048]; + + while (remaining > 0) + { + int rc = read(skip, 0, remaining > 2048 ? 2048 : remaining); + if (rc < 0) + break; + remaining -= rc; + } + + return n - remaining; +} + +void InputStream::reset() throw (IOException) +{ + throw IOException("reset not supported"); +} diff --git a/beecrypt/c++/io/InputStream.h b/beecrypt/c++/io/InputStream.h new file mode 100644 index 0000000..aea61c5 --- /dev/null +++ b/beecrypt/c++/io/InputStream.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file InputStream.h + * \ingroup CXX_IO_m + */ + +#ifndef _CLASS_INPUTSTREAM_H +#define _CLASS_INPUTSTREAM_H + +#ifdef __cplusplus + +#include "beecrypt/c++/array.h" +using beecrypt::bytearray; +#include "beecrypt/c++/io/IOException.h" +using beecrypt::io::IOException; + +namespace beecrypt { + namespace io { + class BEECRYPTCXXAPI InputStream + { + public: + virtual ~InputStream() {}; + + virtual off_t available() throw (IOException); + virtual void close() throw (IOException); + virtual void mark(off_t readlimit) throw (); + virtual bool markSupported() throw (); + virtual int read() throw (IOException) = 0; + virtual int read(byte* data, size_t offset, size_t length) throw (IOException); + virtual int read(bytearray& b) throw (IOException); + virtual void reset() throw (IOException); + virtual off_t skip(off_t n) throw (IOException); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/io/Makefile.am b/beecrypt/c++/io/Makefile.am new file mode 100644 index 0000000..a86a0c2 --- /dev/null +++ b/beecrypt/c++/io/Makefile.am @@ -0,0 +1,48 @@ +INCLUDES = -I$(top_srcdir)/.. + +AUTOMAKE_OPTIONS = gnu no-dependencies + +noinst_LTLIBRARIES = libcxxio.la +cxxiodir= $(pkgincludedir)/c++/io + +libcxxio_la_SOURCES =\ +ByteArrayInputStream.cxx \ +ByteArrayOutputStream.cxx \ +DataInputStream.cxx \ +DataOutputStream.cxx \ +EOFException.cxx \ +FileInputStream.cxx \ +FileOutputStream.cxx \ +FilterInputStream.cxx \ +FilterOutputStream.cxx \ +InputStream.cxx \ +IOException.cxx \ +OutputStream.cxx \ +PrintStream.cxx \ +PushbackInputStream.cxx +libcxxio_la_LIBADD = -licuuc + +cxxio_HEADERS =\ +ByteArrayInputStream.h \ +ByteArrayOutputStream.h \ +DataInput.h \ +DataOutput.h \ +DataInputStream.h \ +DataOutputStream.h \ +EOFException.h \ +FileInputStream.h \ +FileOutputStream.h \ +FilterInputStream.h \ +FilterOutputStream.h \ +InputStream.h \ +IOException.h \ +OutputStream.h \ +PrintStream.h \ +PushbackInputStream.h + +TESTS = test + +check_PROGRAMS = test + +test_SOURCES = test.cxx +test_LDADD = libcxxio.la ../lang/libcxxlang.la $(top_builddir)/libbeecrypt.la -licuuc -licuio diff --git a/beecrypt/c++/io/Makefile.in b/beecrypt/c++/io/Makefile.in new file mode 100644 index 0000000..7f8c2f0 --- /dev/null +++ b/beecrypt/c++/io/Makefile.in @@ -0,0 +1,616 @@ +# Makefile.in generated by automake 1.8.3 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + + +SOURCES = $(libcxxio_la_SOURCES) $(test_SOURCES) + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +top_builddir = ../.. +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +INSTALL = @INSTALL@ +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +host_triplet = @host@ +check_PROGRAMS = test$(EXEEXT) +subdir = c++/io +DIST_COMMON = $(cxxio_HEADERS) $(srcdir)/Makefile.am \ + $(srcdir)/Makefile.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \ + $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +LTLIBRARIES = $(noinst_LTLIBRARIES) +libcxxio_la_DEPENDENCIES = +am_libcxxio_la_OBJECTS = ByteArrayInputStream.lo \ + ByteArrayOutputStream.lo DataInputStream.lo \ + DataOutputStream.lo EOFException.lo FileInputStream.lo \ + FileOutputStream.lo FilterInputStream.lo FilterOutputStream.lo \ + InputStream.lo IOException.lo OutputStream.lo PrintStream.lo \ + PushbackInputStream.lo +libcxxio_la_OBJECTS = $(am_libcxxio_la_OBJECTS) +am_test_OBJECTS = test.$(OBJEXT) +test_OBJECTS = $(am_test_OBJECTS) +test_DEPENDENCIES = libcxxio.la ../lang/libcxxlang.la \ + $(top_builddir)/libbeecrypt.la +DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir) +depcomp = +am__depfiles_maybe = +CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) +LTCXXCOMPILE = $(LIBTOOL) --mode=compile $(CXX) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CXXFLAGS) $(CXXFLAGS) +CXXLD = $(CXX) +CXXLINK = $(LIBTOOL) --mode=link $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) \ + $(AM_LDFLAGS) $(LDFLAGS) -o $@ +SOURCES = $(libcxxio_la_SOURCES) $(test_SOURCES) +DIST_SOURCES = $(libcxxio_la_SOURCES) $(test_SOURCES) +am__installdirs = "$(DESTDIR)$(cxxiodir)" +cxxioHEADERS_INSTALL = $(INSTALL_HEADER) +HEADERS = $(cxxio_HEADERS) +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMDEP_FALSE = @AMDEP_FALSE@ +AMDEP_TRUE = @AMDEP_TRUE@ +AMTAR = @AMTAR@ +AR = @AR@ +AS = @AS@ +ASM_ALIGN = @ASM_ALIGN@ +ASM_ARCH = @ASM_ARCH@ +ASM_BIGENDIAN = @ASM_BIGENDIAN@ +ASM_CPU = @ASM_CPU@ +ASM_GLOBL = @ASM_GLOBL@ +ASM_GSYM_PREFIX = @ASM_GSYM_PREFIX@ +ASM_LSYM_PREFIX = @ASM_LSYM_PREFIX@ +ASM_OS = @ASM_OS@ +ASM_TEXTSEG = @ASM_TEXTSEG@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCAS = @CCAS@ +CCASFLAGS = @CCASFLAGS@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DLLTOOL = @DLLTOOL@ +ECHO = @ECHO@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +F77 = @F77@ +FFLAGS = @FFLAGS@ +INCLUDE_DLFCN_H = @INCLUDE_DLFCN_H@ +INCLUDE_INTTYPES_H = @INCLUDE_INTTYPES_H@ +INCLUDE_MALLOC_H = @INCLUDE_MALLOC_H@ +INCLUDE_PTHREAD_H = @INCLUDE_PTHREAD_H@ +INCLUDE_STDINT_H = @INCLUDE_STDINT_H@ +INCLUDE_STDIO_H = @INCLUDE_STDIO_H@ +INCLUDE_STDLIB_H = @INCLUDE_STDLIB_H@ +INCLUDE_STRING_H = @INCLUDE_STRING_H@ +INCLUDE_SYNCH_H = @INCLUDE_SYNCH_H@ +INCLUDE_THREAD_H = @INCLUDE_THREAD_H@ +INCLUDE_UNISTD_H = @INCLUDE_UNISTD_H@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +JAVAINC = @JAVAINC@ +LDFLAGS = @LDFLAGS@ +LIBALT = @LIBALT@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +MAYBE_LTLIB = @MAYBE_LTLIB@ +MAYBE_SUB = @MAYBE_SUB@ +MP_WBITS = @MP_WBITS@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PYTHONINC = @PYTHONINC@ +PYTHONLIB = @PYTHONLIB@ +RANLIB = @RANLIB@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +TYPEDEF_BC_COND_T = @TYPEDEF_BC_COND_T@ +TYPEDEF_BC_MUTEX_T = @TYPEDEF_BC_MUTEX_T@ +TYPEDEF_BC_THREAD_T = @TYPEDEF_BC_THREAD_T@ +TYPEDEF_INT16_T = @TYPEDEF_INT16_T@ +TYPEDEF_INT32_T = @TYPEDEF_INT32_T@ +TYPEDEF_INT64_T = @TYPEDEF_INT64_T@ +TYPEDEF_INT8_T = @TYPEDEF_INT8_T@ +TYPEDEF_SIZE_T = @TYPEDEF_SIZE_T@ +TYPEDEF_UINT16_T = @TYPEDEF_UINT16_T@ +TYPEDEF_UINT32_T = @TYPEDEF_UINT32_T@ +TYPEDEF_UINT64_T = @TYPEDEF_UINT64_T@ +TYPEDEF_UINT8_T = @TYPEDEF_UINT8_T@ +VERSION = @VERSION@ +ac_ct_AR = @ac_ct_AR@ +ac_ct_AS = @ac_ct_AS@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DLLTOOL = @ac_ct_DLLTOOL@ +ac_ct_F77 = @ac_ct_F77@ +ac_ct_OBJDUMP = @ac_ct_OBJDUMP@ +ac_ct_RANLIB = @ac_ct_RANLIB@ +ac_ct_STRIP = @ac_ct_STRIP@ +ac_cv_have_gcj = @ac_cv_have_gcj@ +ac_cv_have_java = @ac_cv_have_java@ +ac_cv_have_javac = @ac_cv_have_javac@ +ac_cv_have_python = @ac_cv_have_python@ +am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ +am__fastdepCC_TRUE = @am__fastdepCC_TRUE@ +am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@ +am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +datadir = @datadir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +sysconfdir = @sysconfdir@ +target = @target@ +target_alias = @target_alias@ +target_cpu = @target_cpu@ +target_os = @target_os@ +target_vendor = @target_vendor@ +INCLUDES = -I$(top_srcdir)/.. +AUTOMAKE_OPTIONS = gnu no-dependencies +noinst_LTLIBRARIES = libcxxio.la +cxxiodir = $(pkgincludedir)/c++/io +libcxxio_la_SOURCES = \ +ByteArrayInputStream.cxx \ +ByteArrayOutputStream.cxx \ +DataInputStream.cxx \ +DataOutputStream.cxx \ +EOFException.cxx \ +FileInputStream.cxx \ +FileOutputStream.cxx \ +FilterInputStream.cxx \ +FilterOutputStream.cxx \ +InputStream.cxx \ +IOException.cxx \ +OutputStream.cxx \ +PrintStream.cxx \ +PushbackInputStream.cxx + +libcxxio_la_LIBADD = -licuuc +cxxio_HEADERS = \ +ByteArrayInputStream.h \ +ByteArrayOutputStream.h \ +DataInput.h \ +DataOutput.h \ +DataInputStream.h \ +DataOutputStream.h \ +EOFException.h \ +FileInputStream.h \ +FileOutputStream.h \ +FilterInputStream.h \ +FilterOutputStream.h \ +InputStream.h \ +IOException.h \ +OutputStream.h \ +PrintStream.h \ +PushbackInputStream.h + +TESTS = test +test_SOURCES = test.cxx +test_LDADD = libcxxio.la ../lang/libcxxlang.la $(top_builddir)/libbeecrypt.la -licuuc -licuio +all: all-am + +.SUFFIXES: +.SUFFIXES: .cxx .lo .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ + && exit 0; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu c++/io/Makefile'; \ + cd $(top_srcdir) && \ + $(AUTOMAKE) --gnu c++/io/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +clean-noinstLTLIBRARIES: + -test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES) + @list='$(noinst_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" = "$$p" && dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +libcxxio.la: $(libcxxio_la_OBJECTS) $(libcxxio_la_DEPENDENCIES) + $(CXXLINK) $(libcxxio_la_LDFLAGS) $(libcxxio_la_OBJECTS) $(libcxxio_la_LIBADD) $(LIBS) + +clean-checkPROGRAMS: + @list='$(check_PROGRAMS)'; for p in $$list; do \ + f=`echo $$p|sed 's/$(EXEEXT)$$//'`; \ + echo " rm -f $$p $$f"; \ + rm -f $$p $$f ; \ + done +test$(EXEEXT): $(test_OBJECTS) $(test_DEPENDENCIES) + @rm -f test$(EXEEXT) + $(CXXLINK) $(test_LDFLAGS) $(test_OBJECTS) $(test_LDADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +.cxx.o: + $(CXXCOMPILE) -c -o $@ $< + +.cxx.obj: + $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +.cxx.lo: + $(LTCXXCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +distclean-libtool: + -rm -f libtool +uninstall-info-am: +install-cxxioHEADERS: $(cxxio_HEADERS) + @$(NORMAL_INSTALL) + test -z "$(cxxiodir)" || $(mkdir_p) "$(DESTDIR)$(cxxiodir)" + @list='$(cxxio_HEADERS)'; for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + f="`echo $$p | sed -e 's|^.*/||'`"; \ + echo " $(cxxioHEADERS_INSTALL) '$$d$$p' '$(DESTDIR)$(cxxiodir)/$$f'"; \ + $(cxxioHEADERS_INSTALL) "$$d$$p" "$(DESTDIR)$(cxxiodir)/$$f"; \ + done + +uninstall-cxxioHEADERS: + @$(NORMAL_UNINSTALL) + @list='$(cxxio_HEADERS)'; for p in $$list; do \ + f="`echo $$p | sed -e 's|^.*/||'`"; \ + echo " rm -f '$(DESTDIR)$(cxxiodir)/$$f'"; \ + rm -f "$(DESTDIR)$(cxxiodir)/$$f"; \ + done + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(ETAGS_ARGS)$$tags$$unique" \ + || $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$tags $$unique +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(CTAGS_ARGS)$$tags$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$tags $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && cd $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) $$here + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +check-TESTS: $(TESTS) + @failed=0; all=0; xfail=0; xpass=0; skip=0; \ + srcdir=$(srcdir); export srcdir; \ + list='$(TESTS)'; \ + if test -n "$$list"; then \ + for tst in $$list; do \ + if test -f ./$$tst; then dir=./; \ + elif test -f $$tst; then dir=; \ + else dir="$(srcdir)/"; fi; \ + if $(TESTS_ENVIRONMENT) $${dir}$$tst; then \ + all=`expr $$all + 1`; \ + case " $(XFAIL_TESTS) " in \ + *" $$tst "*) \ + xpass=`expr $$xpass + 1`; \ + failed=`expr $$failed + 1`; \ + echo "XPASS: $$tst"; \ + ;; \ + *) \ + echo "PASS: $$tst"; \ + ;; \ + esac; \ + elif test $$? -ne 77; then \ + all=`expr $$all + 1`; \ + case " $(XFAIL_TESTS) " in \ + *" $$tst "*) \ + xfail=`expr $$xfail + 1`; \ + echo "XFAIL: $$tst"; \ + ;; \ + *) \ + failed=`expr $$failed + 1`; \ + echo "FAIL: $$tst"; \ + ;; \ + esac; \ + else \ + skip=`expr $$skip + 1`; \ + echo "SKIP: $$tst"; \ + fi; \ + done; \ + if test "$$failed" -eq 0; then \ + if test "$$xfail" -eq 0; then \ + banner="All $$all tests passed"; \ + else \ + banner="All $$all tests behaved as expected ($$xfail expected failures)"; \ + fi; \ + else \ + if test "$$xpass" -eq 0; then \ + banner="$$failed of $$all tests failed"; \ + else \ + banner="$$failed of $$all tests did not behave as expected ($$xpass unexpected passes)"; \ + fi; \ + fi; \ + dashes="$$banner"; \ + skipped=""; \ + if test "$$skip" -ne 0; then \ + skipped="($$skip tests were not run)"; \ + test `echo "$$skipped" | wc -c` -gt `echo "$$banner" | wc -c` && \ + dashes="$$skipped"; \ + fi; \ + report=""; \ + if test "$$failed" -ne 0 && test -n "$(PACKAGE_BUGREPORT)"; then \ + report="Please report to $(PACKAGE_BUGREPORT)"; \ + test `echo "$$report" | wc -c` -gt `echo "$$banner" | wc -c` && \ + dashes="$$report"; \ + fi; \ + dashes=`echo "$$dashes" | sed s/./=/g`; \ + echo "$$dashes"; \ + echo "$$banner"; \ + test -n "$$skipped" && echo "$$skipped"; \ + test -n "$$report" && echo "$$report"; \ + echo "$$dashes"; \ + test "$$failed" -eq 0; \ + else :; fi + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \ + list='$(DISTFILES)'; for file in $$list; do \ + case $$file in \ + $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \ + $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \ + esac; \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test "$$dir" != "$$file" && test "$$dir" != "."; then \ + dir="/$$dir"; \ + $(mkdir_p) "$(distdir)$$dir"; \ + else \ + dir=''; \ + fi; \ + if test -d $$d/$$file; then \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + fi; \ + cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ + else \ + test -f $(distdir)/$$file \ + || cp -p $$d/$$file $(distdir)/$$file \ + || exit 1; \ + fi; \ + done +check-am: all-am + $(MAKE) $(AM_MAKEFLAGS) $(check_PROGRAMS) + $(MAKE) $(AM_MAKEFLAGS) check-TESTS +check: check-am +all-am: Makefile $(LTLIBRARIES) $(HEADERS) +installdirs: + for dir in "$(DESTDIR)$(cxxiodir)"; do \ + test -z "$$dir" || $(mkdir_p) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -rm -f $(CONFIG_CLEAN_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-checkPROGRAMS clean-generic clean-libtool \ + clean-noinstLTLIBRARIES mostlyclean-am + +distclean: distclean-am + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-libtool distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +info: info-am + +info-am: + +install-data-am: install-cxxioHEADERS + +install-exec-am: + +install-info: install-info-am + +install-man: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-cxxioHEADERS uninstall-info-am + +.PHONY: CTAGS GTAGS all all-am check check-TESTS check-am clean \ + clean-checkPROGRAMS clean-generic clean-libtool \ + clean-noinstLTLIBRARIES ctags distclean distclean-compile \ + distclean-generic distclean-libtool distclean-tags distdir dvi \ + dvi-am html html-am info info-am install install-am \ + install-cxxioHEADERS install-data install-data-am install-exec \ + install-exec-am install-info install-info-am install-man \ + install-strip installcheck installcheck-am installdirs \ + maintainer-clean maintainer-clean-generic mostlyclean \ + mostlyclean-compile mostlyclean-generic mostlyclean-libtool \ + pdf pdf-am ps ps-am tags uninstall uninstall-am \ + uninstall-cxxioHEADERS uninstall-info-am + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/beecrypt/c++/io/OutputStream.cxx b/beecrypt/c++/io/OutputStream.cxx new file mode 100644 index 0000000..ca45278 --- /dev/null +++ b/beecrypt/c++/io/OutputStream.cxx @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/io/OutputStream.h" +#include "beecrypt/c++/lang/NullPointerException.h" +using beecrypt::lang::NullPointerException; + +using namespace beecrypt::io; + +void OutputStream::close() throw (IOException) +{ +} + +void OutputStream::flush() throw (IOException) +{ +} + +void OutputStream::write(const byte* data, size_t offset, size_t len) throw (IOException) +{ + if (!data) + throw NullPointerException(); + + for (size_t i = 0; i < len; i++) + write(data[offset+i]); +} + +void OutputStream::write(const bytearray& b) throw (IOException) +{ + write(b.data(), 0, b.size()); +} diff --git a/beecrypt/c++/io/OutputStream.h b/beecrypt/c++/io/OutputStream.h new file mode 100644 index 0000000..d2f4307 --- /dev/null +++ b/beecrypt/c++/io/OutputStream.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file OutputStream.h + * \ingroup CXX_IO_m + */ + +#ifndef _CLASS_OUTPUTSTREAM_H +#define _CLASS_OUTPUTSTREAM_H + +#ifdef __cplusplus + +#include "beecrypt/c++/array.h" +using beecrypt::bytearray; +#include "beecrypt/c++/io/IOException.h" +using beecrypt::io::IOException; + +namespace beecrypt { + namespace io { + class BEECRYPTCXXAPI OutputStream + { + public: + virtual ~OutputStream() {}; + + virtual void close() throw (IOException); + virtual void flush() throw (IOException); + virtual void write(byte b) throw (IOException) = 0; + virtual void write(const byte* data, size_t offset, size_t length) throw (IOException); + virtual void write(const bytearray& b) throw (IOException); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/io/PrintStream.cxx b/beecrypt/c++/io/PrintStream.cxx new file mode 100644 index 0000000..340ad69 --- /dev/null +++ b/beecrypt/c++/io/PrintStream.cxx @@ -0,0 +1,257 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/io/PrintStream.h" +#include "beecrypt/c++/lang/IllegalArgumentException.h" +using beecrypt::lang::IllegalArgumentException; + +#define MAX_BYTES_PER_CHARACTER 8 + +using namespace beecrypt::io; + +PrintStream::PrintStream(OutputStream& out, bool autoflush, const char* encoding) : FilterOutputStream(out) +{ + UErrorCode status = U_ZERO_ERROR; + + _loc = ucnv_open(encoding, &status); + if (U_FAILURE(status)) + throw IllegalArgumentException("invalid encoding"); + + _closed = false; + _error = false; + _flush = autoflush; +} + +PrintStream::~PrintStream() +{ + ucnv_close(_loc); +} + +void PrintStream::close() throw () +{ + try + { + out.close(); + _closed = true; + } + catch (IOException) + { + _error = true; + } +} + +void PrintStream::flush() throw () +{ + if (!_closed) + { + try + { + out.flush(); + } + catch (IOException) + { + _error = true; + } + } +} + +void PrintStream::write(byte b) throw () +{ + if (!_closed) + { + try + { + out.write(b); + } + catch (IOException) + { + _error = true; + } + } +} + +void PrintStream::write(const byte* data, size_t offset, size_t length) throw () +{ + if (!_closed) + { + try + { + out.write(data, offset, length); + } + catch (IOException) + { + _error = true; + } + } +} + +void PrintStream::print(const UChar* str, size_t length) throw () +{ + if (!_closed) + { + try + { + UErrorCode status = U_ZERO_ERROR; + + // pre-flighting + size_t need = ucnv_fromUChars(_loc, 0, 0, str, length, &status); + if (U_FAILURE(status)) + if (status != U_BUFFER_OVERFLOW_ERROR) + throw IOException(); + + byte* buffer = new byte[need]; + + status = U_ZERO_ERROR; + + try + { + ucnv_fromUChars(_loc, (char*) buffer, need, str, length, &status); + if (status != U_STRING_NOT_TERMINATED_WARNING) + throw IOException(); + + out.write(buffer, 0, need); + + if (_flush) + { + for (size_t i = 0; i < length; i++) + if (str[i] == 0xA) + out.flush(); + } + + delete[] buffer; + } + catch (IOException) + { + delete[] buffer; + throw; + } + } + catch (IOException) + { + _error = true; + } + } +} + +void PrintStream::print(bool b) throw () +{ + static const String* STR_TRUE = 0; + static const String* STR_FALSE = 0; + + if (!_closed) + { + if (b) + { + if (!STR_FALSE) + STR_FALSE = new String("true"); + + print(*STR_TRUE); + } + else + { + if (!STR_FALSE) + STR_FALSE = new String("false"); + + print(*STR_FALSE); + } + } +} + +void PrintStream::print(javachar ch) throw () +{ + if (!_closed) + { + char buffer[MAX_BYTES_PER_CHARACTER]; + + try + { + UErrorCode status = U_ZERO_ERROR; + + // do conversion of one character + size_t used = ucnv_fromUChars(_loc, buffer, 8, &ch, 1, &status); + if (U_FAILURE(status)) + throw IOException("failure in ucnv_fromUChars"); + + out.write((const byte*) buffer, 0, used); + + // check if we need to flush + if (_flush && ch == 0xA) + out.flush(); + } + catch (IOException) + { + _error = true; + } + } +} + +void PrintStream::print(const array& chars) throw () +{ + print(chars.data(), chars.size()); +} + +void PrintStream::print(const String& str) throw () +{ + print(str.getBuffer(), str.length()); +} + +void PrintStream::println() throw () +{ + if (!_closed) + { + #if WIN32 + print((javachar) 0xD); + print((javachar) 0xA); + #else + print((javachar) 0xA); + #endif + } +} + +void PrintStream::println(bool b) throw () +{ + if (!_closed) + { + print(b); + println(); + } +} + +void PrintStream::println(const array& chars) throw () +{ + if (!_closed) + { + print(chars); + println(); + } +} + +void PrintStream::println(const String& str) throw () +{ + if (!_closed) + { + print(str); + println(); + } +} diff --git a/beecrypt/c++/io/PrintStream.h b/beecrypt/c++/io/PrintStream.h new file mode 100644 index 0000000..f530449 --- /dev/null +++ b/beecrypt/c++/io/PrintStream.h @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file PrintStream.h + * \ingroup CXX_IO_m + */ + +#ifndef _CLASS_PRINTSTREAM_H +#define _CLASS_PRINTSTREAM_H + +#ifdef __cplusplus + +#include "beecrypt/c++/array.h" +using beecrypt::array; +using beecrypt::bytearray; +#include "beecrypt/c++/io/FilterOutputStream.h" +using beecrypt::io::FilterOutputStream; + +#include + +namespace beecrypt { + namespace io { + class BEECRYPTCXXAPI PrintStream : public FilterOutputStream + { + private: + bool _closed; + bool _error; + bool _flush; + UConverter* _loc; + + void print(const UChar*, size_t) throw (); + + protected: + void setError() throw (); + + public: + PrintStream(OutputStream& out, bool autoflush = false, const char* encoding = 0); + virtual ~PrintStream(); + + virtual void close() throw (); + virtual void flush() throw (); + virtual void write(byte) throw (); + virtual void write(const byte*, size_t, size_t) throw (); + + bool checkError() throw (); + void print(bool) throw (); + void print(javachar) throw (); + void print(javaint) throw (); + void print(javalong) throw (); + void print(javashort) throw (); + // void print(javafloat) throw (); + // void print(javadouble) throw (); + // void print(const char*) throw (); + void print(const array&) throw (); + void print(const String&) throw (); + void println() throw (); + void println(bool) throw (); + void println(javachar) throw (); + void println(javaint) throw (); + void println(javalong) throw (); + void println(javashort) throw (); + // void println(javafloat) throw (); + // void println(javadouble) throw (); + // void println(const char*) throw (); + void println(const array&) throw (); + void println(const String&) throw (); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/io/PushbackInputStream.cxx b/beecrypt/c++/io/PushbackInputStream.cxx new file mode 100644 index 0000000..908991b --- /dev/null +++ b/beecrypt/c++/io/PushbackInputStream.cxx @@ -0,0 +1,168 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/io/PushbackInputStream.h" +#include "beecrypt/c++/lang/NullPointerException.h" +using beecrypt::lang::NullPointerException; + +using namespace beecrypt::io; + +PushbackInputStream::PushbackInputStream(InputStream& in, size_t size) : FilterInputStream(in), buf(size) +{ + _closed = false; + pos = 0; +} + +PushbackInputStream::~PushbackInputStream() +{ +} + +off_t PushbackInputStream::available() throw (IOException) +{ + if (_closed) + throw IOException("Stream closed"); + + return in.available() + (buf.size() - pos); +} + +void PushbackInputStream::close() throw (IOException) +{ + if (!_closed) + { + in.close(); + _closed = true; + } +} + +int PushbackInputStream::read() throw (IOException) +{ + if (_closed) + throw IOException("Stream closed"); + + if (pos < buf.size()) + return buf[pos++]; + + return in.read(); +} + +bool PushbackInputStream::markSupported() throw () +{ + return false; +} + +int PushbackInputStream::read(byte* data, size_t offset, size_t length) throw (IOException) +{ + if (!data) + throw NullPointerException(); + + if (_closed) + throw IOException("Stream closed"); + + if (length == 0) + return 0; + + size_t buffered = buf.size() - pos; + + if (buffered > 0) + { + if (length < buffered) + buffered = length; + + memcpy(data+offset, buf.data()+pos, buffered); + + pos += buffered; + offset += buffered; + length -= buffered; + } + + if (length > 0) + { + int rc = in.read(data, offset, length); + if (rc < 0) + if (buffered == 0) + return -1; // nothing in buffer and nothing read + else + return buffered; // something in buffer and nothing read + + return buffered + rc; // something in buffer and something read + } + + return buffered; // everything was in buffer +} + +off_t PushbackInputStream::skip(off_t n) throw (IOException) +{ + if (_closed) + throw IOException("Stream closed"); + + if (n == 0) + return 0; + + size_t canskip = buf.size() - pos; + + if (canskip > 0) + { + if (n < canskip) + { + // more in buffer than we need to skip + canskip = n; + } + pos += canskip; + n -= canskip; + } + + if (n > 0) + { + // apparently we didn't have enough in the buffer + canskip += in.skip(n); + } + + return canskip; +} + +void PushbackInputStream::unread(byte b) throw (IOException) +{ + if (_closed) + throw IOException("Stream closed"); + + if (pos == 0) + throw IOException("Pushback buffer is full"); + + buf[--pos] = b; +} + +void PushbackInputStream::unread(const bytearray& b) throw (IOException) +{ + unread(b.data(), 0, b.size()); +} + +void PushbackInputStream::unread(const byte* data, size_t offset, size_t length) throw (IOException) +{ + if (!data) + throw NullPointerException(); + + pos -= length; + + memcpy(buf.data()+pos, data+offset, length); +} diff --git a/beecrypt/c++/io/PushbackInputStream.h b/beecrypt/c++/io/PushbackInputStream.h new file mode 100644 index 0000000..ff63dfc --- /dev/null +++ b/beecrypt/c++/io/PushbackInputStream.h @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file PushbackInputStream.h + * \ingroup CXX_IO_m + */ + +#ifndef _CLASS_PUSHBACKINPUTSTREAM_H +#define _CLASS_PUSHBACKINPUTSTREAM_H + +#ifdef __cplusplus + +#include "beecrypt/c++/io/FilterInputStream.h" +using beecrypt::io::FilterInputStream; + +namespace beecrypt { + namespace io { + class BEECRYPTCXXAPI PushbackInputStream : public FilterInputStream + { + private: + bool _closed; + + protected: + bytearray buf; + size_t pos; + + public: + PushbackInputStream(InputStream& in, size_t size = 1); + virtual ~PushbackInputStream(); + + virtual off_t available() throw (IOException); + virtual void close() throw (IOException); + virtual bool markSupported() throw (); + virtual int read() throw (IOException); + virtual int read(byte* data, size_t offset, size_t length) throw (IOException); + virtual off_t skip(off_t n) throw (IOException); + + void unread(byte) throw (IOException); + void unread(const byte* data, size_t offset, size_t length) throw (IOException); + void unread(const bytearray& b) throw (IOException); + + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/io/test.cxx b/beecrypt/c++/io/test.cxx new file mode 100644 index 0000000..2d9095f --- /dev/null +++ b/beecrypt/c++/io/test.cxx @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "c++/io/ByteArrayInputStream.h" +using beecrypt::io::ByteArrayInputStream; +#include "c++/io/ByteArrayOutputStream.h" +using beecrypt::io::ByteArrayOutputStream; +#include "c++/io/DataInputStream.h" +using beecrypt::io::DataInputStream; +#include "c++/io/DataOutputStream.h" +using beecrypt::io::DataOutputStream; + +#include +#include +using namespace std; + +int main(int argc, char* argv[]) +{ + String input = UNICODE_STRING_SIMPLE("The quick brown fox jumps over the lazy dog"); + + int failures = 0; + + try + { + ByteArrayOutputStream bos; + DataOutputStream dos(bos); + + dos.writeUTF(input); + dos.close(); + + bytearray* b = bos.toByteArray(); + + if (b) + { + if (b->size() != 45) + { + cerr << "failed test 1" << endl; + failures++; + } + + ByteArrayInputStream bin(*b); + DataInputStream din(bin); + + String test; + + din.readUTF(test); + + if (input != test) + { + cerr << "failed test 2" << endl; + failures++; + } + + if (din.available() != 0) + { + cerr << "failed test 3" << endl; + cerr << "remaining bytes in stream: " << din.available() << endl; + failures++; + } + + din.close(); + bin.close(); + } + else + { + cerr << "failed structural 1" << endl; + failures++; + } + } + catch (IOException& ex) + { + cerr << "failed structural 2" << endl; + failures++; + } + catch (...) + { + cerr << "failed structural 3" << endl; + failures++; + } + + return failures; +} diff --git a/beecrypt/c++/lang/Error.cxx b/beecrypt/c++/lang/Error.cxx new file mode 100644 index 0000000..2e02381 --- /dev/null +++ b/beecrypt/c++/lang/Error.cxx @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/lang/Error.h" +using namespace beecrypt::lang; + +Error::Error() throw () +{ +} + +Error::Error(const String& message) throw () : Throwable(message) +{ +} diff --git a/beecrypt/c++/lang/Error.h b/beecrypt/c++/lang/Error.h new file mode 100644 index 0000000..d5d01e3 --- /dev/null +++ b/beecrypt/c++/lang/Error.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file Error.h + * \ingroup CXX_LANG_m + */ + +#ifndef _CLASS_ERROR_H +#define _CLASS_ERROR_H + +#ifdef __cplusplus + +#include "beecrypt/c++/lang/Throwable.h" +using beecrypt::lang::Throwable; + +namespace beecrypt { + namespace lang { + class BEECRYPTCXXAPI Error : public Throwable + { + public: + Error() throw (); + Error(const String&) throw (); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/lang/Exception.cxx b/beecrypt/c++/lang/Exception.cxx new file mode 100644 index 0000000..5626e28 --- /dev/null +++ b/beecrypt/c++/lang/Exception.cxx @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/lang/Exception.h" +using namespace beecrypt::lang; + +Exception::Exception() throw () +{ +} + +Exception::Exception(const String& message) throw () : Throwable(message) +{ +} diff --git a/beecrypt/c++/lang/Exception.h b/beecrypt/c++/lang/Exception.h new file mode 100644 index 0000000..7ba56e0 --- /dev/null +++ b/beecrypt/c++/lang/Exception.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file Exception.h + * \ingroup CXX_LANG_m + */ + +#ifndef _CLASS_EXCEPTION_H +#define _CLASS_EXCEPTION_H + +#ifdef __cplusplus + +#include "beecrypt/c++/lang/Throwable.h" +using beecrypt::lang::Throwable; + +namespace beecrypt { + namespace lang { + class BEECRYPTCXXAPI Exception : public Throwable + { + public: + Exception() throw (); + Exception(const String&) throw (); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/lang/IllegalArgumentException.cxx b/beecrypt/c++/lang/IllegalArgumentException.cxx new file mode 100644 index 0000000..e6ff1dd --- /dev/null +++ b/beecrypt/c++/lang/IllegalArgumentException.cxx @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/lang/IllegalArgumentException.h" +using namespace beecrypt::lang; + +IllegalArgumentException::IllegalArgumentException() throw () +{ +} + +IllegalArgumentException::IllegalArgumentException(const String& message) throw () : RuntimeException(message) +{ +} diff --git a/beecrypt/c++/lang/IllegalArgumentException.h b/beecrypt/c++/lang/IllegalArgumentException.h new file mode 100644 index 0000000..a0e73db --- /dev/null +++ b/beecrypt/c++/lang/IllegalArgumentException.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file IllegalArgumentException.h + * \ingroup CXX_LANG_m + */ + +#ifndef _CLASS_ILLEGALARGUMENTEXCEPTION_H +#define _CLASS_ILLEGALARGUMENTEXCEPTION_H + +#ifdef __cplusplus + +#include "beecrypt/c++/lang/RuntimeException.h" +using beecrypt::lang::RuntimeException; + +namespace beecrypt { + namespace lang { + class BEECRYPTCXXAPI IllegalArgumentException : public RuntimeException + { + public: + IllegalArgumentException() throw (); + IllegalArgumentException(const String&) throw (); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/lang/IllegalStateException.cxx b/beecrypt/c++/lang/IllegalStateException.cxx new file mode 100644 index 0000000..e1668ab --- /dev/null +++ b/beecrypt/c++/lang/IllegalStateException.cxx @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/lang/IllegalStateException.h" +using namespace beecrypt::lang; + +IllegalStateException::IllegalStateException() throw () +{ +} + +IllegalStateException::IllegalStateException(const String& message) throw () : RuntimeException(message) +{ +} diff --git a/beecrypt/c++/lang/IllegalStateException.h b/beecrypt/c++/lang/IllegalStateException.h new file mode 100644 index 0000000..bcbc2c5 --- /dev/null +++ b/beecrypt/c++/lang/IllegalStateException.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file IllegalStateException.h + * \ingroup CXX_LANG_m + */ + +#ifndef _CLASS_ILLEGALSTATEEXCEPTION_H +#define _CLASS_ILLEGALSTATEEXCEPTION_H + +#ifdef __cplusplus + +#include "beecrypt/c++/lang/RuntimeException.h" +using beecrypt::lang::RuntimeException; + +namespace beecrypt { + namespace lang { + class BEECRYPTCXXAPI IllegalStateException : public RuntimeException + { + public: + IllegalStateException() throw (); + IllegalStateException(const String&) throw (); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/lang/Makefile.am b/beecrypt/c++/lang/Makefile.am new file mode 100644 index 0000000..4bafe6a --- /dev/null +++ b/beecrypt/c++/lang/Makefile.am @@ -0,0 +1,28 @@ +INCLUDES = -I$(top_srcdir)/.. + +AUTOMAKE_OPTIONS = gnu no-dependencies + +noinst_LTLIBRARIES = libcxxlang.la + +cxxlangdir=$(pkgincludedir)/c++/lang + +libcxxlang_la_SOURCES =\ +Error.cxx \ +Exception.cxx \ +IllegalArgumentException.cxx \ +IllegalStateException.cxx \ +NullPointerException.cxx \ +OutOfMemoryError.cxx \ +RuntimeException.cxx \ +Throwable.cxx + +cxxlang_HEADERS =\ +Error.h \ +Exception.h \ +IllegalArgumentException.h \ +IllegalStateException.h \ +NullPointerException.h \ +OutOfMemoryError.h \ +RuntimeException.h \ +String.h \ +Throwable.h diff --git a/beecrypt/c++/lang/Makefile.in b/beecrypt/c++/lang/Makefile.in new file mode 100644 index 0000000..6085c1c --- /dev/null +++ b/beecrypt/c++/lang/Makefile.in @@ -0,0 +1,507 @@ +# Makefile.in generated by automake 1.8.3 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + + +SOURCES = $(libcxxlang_la_SOURCES) + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +top_builddir = ../.. +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +INSTALL = @INSTALL@ +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +host_triplet = @host@ +subdir = c++/lang +DIST_COMMON = $(cxxlang_HEADERS) $(srcdir)/Makefile.am \ + $(srcdir)/Makefile.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \ + $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +LTLIBRARIES = $(noinst_LTLIBRARIES) +libcxxlang_la_LIBADD = +am_libcxxlang_la_OBJECTS = Error.lo Exception.lo \ + IllegalArgumentException.lo IllegalStateException.lo \ + NullPointerException.lo OutOfMemoryError.lo \ + RuntimeException.lo Throwable.lo +libcxxlang_la_OBJECTS = $(am_libcxxlang_la_OBJECTS) +DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir) +depcomp = +am__depfiles_maybe = +CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) +LTCXXCOMPILE = $(LIBTOOL) --mode=compile $(CXX) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CXXFLAGS) $(CXXFLAGS) +CXXLD = $(CXX) +CXXLINK = $(LIBTOOL) --mode=link $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) \ + $(AM_LDFLAGS) $(LDFLAGS) -o $@ +SOURCES = $(libcxxlang_la_SOURCES) +DIST_SOURCES = $(libcxxlang_la_SOURCES) +am__installdirs = "$(DESTDIR)$(cxxlangdir)" +cxxlangHEADERS_INSTALL = $(INSTALL_HEADER) +HEADERS = $(cxxlang_HEADERS) +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMDEP_FALSE = @AMDEP_FALSE@ +AMDEP_TRUE = @AMDEP_TRUE@ +AMTAR = @AMTAR@ +AR = @AR@ +AS = @AS@ +ASM_ALIGN = @ASM_ALIGN@ +ASM_ARCH = @ASM_ARCH@ +ASM_BIGENDIAN = @ASM_BIGENDIAN@ +ASM_CPU = @ASM_CPU@ +ASM_GLOBL = @ASM_GLOBL@ +ASM_GSYM_PREFIX = @ASM_GSYM_PREFIX@ +ASM_LSYM_PREFIX = @ASM_LSYM_PREFIX@ +ASM_OS = @ASM_OS@ +ASM_TEXTSEG = @ASM_TEXTSEG@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCAS = @CCAS@ +CCASFLAGS = @CCASFLAGS@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DLLTOOL = @DLLTOOL@ +ECHO = @ECHO@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +F77 = @F77@ +FFLAGS = @FFLAGS@ +INCLUDE_DLFCN_H = @INCLUDE_DLFCN_H@ +INCLUDE_INTTYPES_H = @INCLUDE_INTTYPES_H@ +INCLUDE_MALLOC_H = @INCLUDE_MALLOC_H@ +INCLUDE_PTHREAD_H = @INCLUDE_PTHREAD_H@ +INCLUDE_STDINT_H = @INCLUDE_STDINT_H@ +INCLUDE_STDIO_H = @INCLUDE_STDIO_H@ +INCLUDE_STDLIB_H = @INCLUDE_STDLIB_H@ +INCLUDE_STRING_H = @INCLUDE_STRING_H@ +INCLUDE_SYNCH_H = @INCLUDE_SYNCH_H@ +INCLUDE_THREAD_H = @INCLUDE_THREAD_H@ +INCLUDE_UNISTD_H = @INCLUDE_UNISTD_H@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +JAVAINC = @JAVAINC@ +LDFLAGS = @LDFLAGS@ +LIBALT = @LIBALT@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +MAYBE_LTLIB = @MAYBE_LTLIB@ +MAYBE_SUB = @MAYBE_SUB@ +MP_WBITS = @MP_WBITS@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PYTHONINC = @PYTHONINC@ +PYTHONLIB = @PYTHONLIB@ +RANLIB = @RANLIB@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +TYPEDEF_BC_COND_T = @TYPEDEF_BC_COND_T@ +TYPEDEF_BC_MUTEX_T = @TYPEDEF_BC_MUTEX_T@ +TYPEDEF_BC_THREAD_T = @TYPEDEF_BC_THREAD_T@ +TYPEDEF_INT16_T = @TYPEDEF_INT16_T@ +TYPEDEF_INT32_T = @TYPEDEF_INT32_T@ +TYPEDEF_INT64_T = @TYPEDEF_INT64_T@ +TYPEDEF_INT8_T = @TYPEDEF_INT8_T@ +TYPEDEF_SIZE_T = @TYPEDEF_SIZE_T@ +TYPEDEF_UINT16_T = @TYPEDEF_UINT16_T@ +TYPEDEF_UINT32_T = @TYPEDEF_UINT32_T@ +TYPEDEF_UINT64_T = @TYPEDEF_UINT64_T@ +TYPEDEF_UINT8_T = @TYPEDEF_UINT8_T@ +VERSION = @VERSION@ +ac_ct_AR = @ac_ct_AR@ +ac_ct_AS = @ac_ct_AS@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DLLTOOL = @ac_ct_DLLTOOL@ +ac_ct_F77 = @ac_ct_F77@ +ac_ct_OBJDUMP = @ac_ct_OBJDUMP@ +ac_ct_RANLIB = @ac_ct_RANLIB@ +ac_ct_STRIP = @ac_ct_STRIP@ +ac_cv_have_gcj = @ac_cv_have_gcj@ +ac_cv_have_java = @ac_cv_have_java@ +ac_cv_have_javac = @ac_cv_have_javac@ +ac_cv_have_python = @ac_cv_have_python@ +am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ +am__fastdepCC_TRUE = @am__fastdepCC_TRUE@ +am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@ +am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +datadir = @datadir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +sysconfdir = @sysconfdir@ +target = @target@ +target_alias = @target_alias@ +target_cpu = @target_cpu@ +target_os = @target_os@ +target_vendor = @target_vendor@ +INCLUDES = -I$(top_srcdir)/.. +AUTOMAKE_OPTIONS = gnu no-dependencies +noinst_LTLIBRARIES = libcxxlang.la +cxxlangdir = $(pkgincludedir)/c++/lang +libcxxlang_la_SOURCES = \ +Error.cxx \ +Exception.cxx \ +IllegalArgumentException.cxx \ +IllegalStateException.cxx \ +NullPointerException.cxx \ +OutOfMemoryError.cxx \ +RuntimeException.cxx \ +Throwable.cxx + +cxxlang_HEADERS = \ +Error.h \ +Exception.h \ +IllegalArgumentException.h \ +IllegalStateException.h \ +NullPointerException.h \ +OutOfMemoryError.h \ +RuntimeException.h \ +String.h \ +Throwable.h + +all: all-am + +.SUFFIXES: +.SUFFIXES: .cxx .lo .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ + && exit 0; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu c++/lang/Makefile'; \ + cd $(top_srcdir) && \ + $(AUTOMAKE) --gnu c++/lang/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +clean-noinstLTLIBRARIES: + -test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES) + @list='$(noinst_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" = "$$p" && dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +libcxxlang.la: $(libcxxlang_la_OBJECTS) $(libcxxlang_la_DEPENDENCIES) + $(CXXLINK) $(libcxxlang_la_LDFLAGS) $(libcxxlang_la_OBJECTS) $(libcxxlang_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +.cxx.o: + $(CXXCOMPILE) -c -o $@ $< + +.cxx.obj: + $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +.cxx.lo: + $(LTCXXCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +distclean-libtool: + -rm -f libtool +uninstall-info-am: +install-cxxlangHEADERS: $(cxxlang_HEADERS) + @$(NORMAL_INSTALL) + test -z "$(cxxlangdir)" || $(mkdir_p) "$(DESTDIR)$(cxxlangdir)" + @list='$(cxxlang_HEADERS)'; for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + f="`echo $$p | sed -e 's|^.*/||'`"; \ + echo " $(cxxlangHEADERS_INSTALL) '$$d$$p' '$(DESTDIR)$(cxxlangdir)/$$f'"; \ + $(cxxlangHEADERS_INSTALL) "$$d$$p" "$(DESTDIR)$(cxxlangdir)/$$f"; \ + done + +uninstall-cxxlangHEADERS: + @$(NORMAL_UNINSTALL) + @list='$(cxxlang_HEADERS)'; for p in $$list; do \ + f="`echo $$p | sed -e 's|^.*/||'`"; \ + echo " rm -f '$(DESTDIR)$(cxxlangdir)/$$f'"; \ + rm -f "$(DESTDIR)$(cxxlangdir)/$$f"; \ + done + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(ETAGS_ARGS)$$tags$$unique" \ + || $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$tags $$unique +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(CTAGS_ARGS)$$tags$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$tags $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && cd $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) $$here + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \ + list='$(DISTFILES)'; for file in $$list; do \ + case $$file in \ + $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \ + $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \ + esac; \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test "$$dir" != "$$file" && test "$$dir" != "."; then \ + dir="/$$dir"; \ + $(mkdir_p) "$(distdir)$$dir"; \ + else \ + dir=''; \ + fi; \ + if test -d $$d/$$file; then \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + fi; \ + cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ + else \ + test -f $(distdir)/$$file \ + || cp -p $$d/$$file $(distdir)/$$file \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(LTLIBRARIES) $(HEADERS) +installdirs: + for dir in "$(DESTDIR)$(cxxlangdir)"; do \ + test -z "$$dir" || $(mkdir_p) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -rm -f $(CONFIG_CLEAN_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libtool clean-noinstLTLIBRARIES \ + mostlyclean-am + +distclean: distclean-am + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-libtool distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +info: info-am + +info-am: + +install-data-am: install-cxxlangHEADERS + +install-exec-am: + +install-info: install-info-am + +install-man: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-cxxlangHEADERS uninstall-info-am + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-libtool clean-noinstLTLIBRARIES ctags distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-tags distdir dvi dvi-am html html-am info info-am \ + install install-am install-cxxlangHEADERS install-data \ + install-data-am install-exec install-exec-am install-info \ + install-info-am install-man install-strip installcheck \ + installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags uninstall uninstall-am uninstall-cxxlangHEADERS \ + uninstall-info-am + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/beecrypt/c++/lang/NullPointerException.cxx b/beecrypt/c++/lang/NullPointerException.cxx new file mode 100644 index 0000000..d06d085 --- /dev/null +++ b/beecrypt/c++/lang/NullPointerException.cxx @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/lang/NullPointerException.h" +using namespace beecrypt::lang; + +NullPointerException::NullPointerException() throw () +{ +} + +NullPointerException::NullPointerException(const String& message) throw () : RuntimeException(message) +{ +} diff --git a/beecrypt/c++/lang/NullPointerException.h b/beecrypt/c++/lang/NullPointerException.h new file mode 100644 index 0000000..7e9b5a0 --- /dev/null +++ b/beecrypt/c++/lang/NullPointerException.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file NullPointerException.h + * \ingroup CXX_LANG_m + */ + +#ifndef _CLASS_NULLPOINTEREXCEPTION_H +#define _CLASS_NULLPOINTEREXCEPTION_H + +#ifdef __cplusplus + +#include "beecrypt/c++/lang/RuntimeException.h" +using beecrypt::lang::RuntimeException; + +namespace beecrypt { + namespace lang { + class BEECRYPTCXXAPI NullPointerException : public RuntimeException + { + public: + NullPointerException() throw (); + NullPointerException(const String&) throw (); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/lang/OutOfMemoryError.cxx b/beecrypt/c++/lang/OutOfMemoryError.cxx new file mode 100644 index 0000000..2ed18a7 --- /dev/null +++ b/beecrypt/c++/lang/OutOfMemoryError.cxx @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/lang/OutOfMemoryError.h" +using namespace beecrypt::lang; + +OutOfMemoryError::OutOfMemoryError() throw () +{ +} + +OutOfMemoryError::OutOfMemoryError(const String& message) throw () : Error(message) +{ +} diff --git a/beecrypt/c++/lang/OutOfMemoryError.h b/beecrypt/c++/lang/OutOfMemoryError.h new file mode 100644 index 0000000..bdd996f --- /dev/null +++ b/beecrypt/c++/lang/OutOfMemoryError.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file OutOfMemoryError.h + * \ingroup CXX_LANG_m + */ + +#ifndef _CLASS_OUTOFMEMORYERROR_H +#define _CLASS_OUTOFMEMORYERROR_H + +#ifdef __cplusplus + +#include "beecrypt/c++/lang/Error.h" +using beecrypt::lang::Error; + +namespace beecrypt { + namespace lang { + class BEECRYPTCXXAPI OutOfMemoryError : public Error + { + public: + OutOfMemoryError() throw (); + OutOfMemoryError(const String&) throw (); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/lang/RuntimeException.cxx b/beecrypt/c++/lang/RuntimeException.cxx new file mode 100644 index 0000000..e9dd31d --- /dev/null +++ b/beecrypt/c++/lang/RuntimeException.cxx @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/lang/RuntimeException.h" +using namespace beecrypt::lang; + +RuntimeException::RuntimeException() throw () +{ +} + +RuntimeException::RuntimeException(const String& message) throw () : Exception(message) +{ +} diff --git a/beecrypt/c++/lang/RuntimeException.h b/beecrypt/c++/lang/RuntimeException.h new file mode 100644 index 0000000..4770767 --- /dev/null +++ b/beecrypt/c++/lang/RuntimeException.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file RuntimeException.h + * \ingroup CXX_LANG_m + */ + +#ifndef _CLASS_RUNTIMEEXCEPTION_H +#define _CLASS_RUNTIMEEXCEPTION_H + +#ifdef __cplusplus + +#include "beecrypt/c++/lang/Exception.h" +using beecrypt::lang::Exception; + +namespace beecrypt { + namespace lang { + class BEECRYPTCXXAPI RuntimeException : public Exception + { + public: + RuntimeException() throw (); + RuntimeException(const String&) throw (); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/lang/String.h b/beecrypt/c++/lang/String.h new file mode 100644 index 0000000..25a3edd --- /dev/null +++ b/beecrypt/c++/lang/String.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file String.h + * \ingroup CXX_LANG_m + */ + +#ifndef _BEECRYPT_CLASS_STRING_H +#define _BEECRYPT_CLASS_STRING_H + +#ifdef __cplusplus + +#include + +namespace beecrypt { + namespace lang { + typedef UnicodeString String; + } +} + +#endif + +#endif + diff --git a/beecrypt/c++/lang/Throwable.cxx b/beecrypt/c++/lang/Throwable.cxx new file mode 100644 index 0000000..f687a5d --- /dev/null +++ b/beecrypt/c++/lang/Throwable.cxx @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/lang/Throwable.h" +using namespace beecrypt::lang; + +Throwable::Throwable() throw () +{ +} + +Throwable::Throwable(const String& message) throw () +{ + _msg = message; +} + +Throwable::Throwable(const Throwable& copy) throw () +{ + _msg = copy._msg; +} + +const String& Throwable::getMessage() const throw () +{ + return _msg; +} diff --git a/beecrypt/c++/lang/Throwable.h b/beecrypt/c++/lang/Throwable.h new file mode 100644 index 0000000..5df4480 --- /dev/null +++ b/beecrypt/c++/lang/Throwable.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file Throwable.h + * \ingroup CXX_LANG_m + */ + +#ifndef _CLASS_THROWABLE_H +#define _CLASS_THROWABLE_H + +#include "beecrypt/api.h" + +#ifdef __cplusplus + +#include "beecrypt/c++/lang/String.h" +using beecrypt::lang::String; + +namespace beecrypt { + namespace lang { + class BEECRYPTCXXAPI Throwable + { + private: + String _msg; + + public: + Throwable() throw (); + Throwable(const String&) throw (); + Throwable(const Throwable&) throw (); + + virtual ~Throwable() throw () {}; + + const String& getMessage() const throw (); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/mutex.h b/beecrypt/c++/mutex.h new file mode 100644 index 0000000..e5575e9 --- /dev/null +++ b/beecrypt/c++/mutex.h @@ -0,0 +1,157 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file mutex.h + * \brief MUTually EXclusive lock class. + * \author Bob Deblier + * \ingroup CXX_m + */ + +#ifndef _CLASS_BEECRYPT_MUTEX_H +#define _CLASS_BEECRYPT_MUTEX_H + +#include "beecrypt/api.h" + +#ifdef __cplusplus + +#if HAVE_ERRNO_H +# include +#endif + +namespace beecrypt { + class BEECRYPTCXXAPI mutex + { + private: + bc_mutex_t _lock; + + public: + inline void init() throw (char*) + { + #if WIN32 + _lock = CreateMutex((LPSECURITY_ATTRIBUTES) 0, FALSE, (LPCSTR) 0); + if (!_lock) + throw "CreateMutex failed"; + #else + register int rc; + # if HAVE_SYNCH_H + if ((rc = mutex_init(&_lock, USYNC_THREAD, 0))) + throw strerror(rc); + # elif HAVE_PTHREAD_H + if ((rc = pthread_mutex_init(&_lock, 0))) + throw strerror(rc); + # else + # error + # endif + #endif + } + + inline void lock() throw (char*) + { + #if WIN32 + if (WaitForSingleObject(_lock, INFINITE) == WAIT_OBJECT_0) + return; + throw "WaitForSingleObject failed"; + #else + register int rc; + # if HAVE_SYNCH_H + if ((rc = mutex_lock(&_lock))) + throw strerror(rc); + # elif HAVE_PTHREAD_H + if ((rc = pthread_mutex_lock(&_lock))) + throw strerror(rc); + # else + # error + # endif + #endif + } + + inline bool trylock() throw (char*) + { + #if WIN32 + switch (WaitForSingleObject(_lock, 0)) + { + case WAIT_TIMEOUT: + return false; + case WAIT_OBJECT_0: + return true; + default: + throw "WaitForSingleObbject failed"; + } + #else + register int rc; + # if HAVE_SYNCH_H + if ((rc = mutex_trylock(&_lock)) == 0) + return true; + if (rc == EBUSY) + return false; + throw strerror(rc); + # elif HAVE_PTHREAD_H + if ((rc = pthread_mutex_trylock(&_lock)) == 0) + return true; + if (rc == EBUSY) + return false; + throw strerror(rc); + # else + # error + # endif + #endif + } + + inline void unlock() throw (char*) + { + #if WIN32 + if (!ReleaseMutex(_lock)) + throw "ReleaseMutex failed"; + #else + register int rc; + # if HAVE_SYNCH_H + if ((rc = mutex_unlock(&_lock))) + throw strerror(rc); + # elif HAVE_PTHREAD_H + if ((rc = pthread_mutex_unlock(&_lock))) + throw strerror(rc); + # else + # error + # endif + #endif + } + + inline void destroy() throw (char*) + { + #if WIN32 + if (!CloseHandle(_lock)) + throw "CloseHandle failed"; + #else + register int rc; + # if HAVE_SYNCH_H + if ((rc = mutex_destroy(&_lock))) + throw strerror(rc); + # elif HAVE_PTHREAD_H + if ((rc = pthread_mutex_destroy(&_lock))) + throw strerror(rc); + # else + # error + # endif + #endif + } + }; +} + +#endif + +#endif diff --git a/beecrypt/c++/provider/BeeCertificateFactory.cxx b/beecrypt/c++/provider/BeeCertificateFactory.cxx new file mode 100644 index 0000000..bc288d0 --- /dev/null +++ b/beecrypt/c++/provider/BeeCertificateFactory.cxx @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/beeyond/BeeCertificate.h" +using beecrypt::beeyond::BeeCertificate; +#include "beecrypt/c++/provider/BeeCertificateFactory.h" + +using namespace beecrypt::provider; + +BeeCertificateFactory::BeeCertificateFactory() +{ +} + +BeeCertificateFactory::~BeeCertificateFactory() +{ +} + +Certificate* BeeCertificateFactory::engineGenerateCertificate(InputStream& in) throw (CertificateException) +{ + try + { + return new BeeCertificate(in); + } + catch (Exception& ex) + { + throw CertificateException(ex.getMessage()); + } +} + +vector* BeeCertificateFactory::engineGenerateCertificates(InputStream& in) throw (CertificateException) +{ + vector* result = new vector; + + try + { + while (in.available()) + { + result->push_back(new BeeCertificate(in)); + } + } + catch (...) + { + delete result; + throw; + } + + return result; +} diff --git a/beecrypt/c++/provider/BeeCertificateFactory.h b/beecrypt/c++/provider/BeeCertificateFactory.h new file mode 100644 index 0000000..2dfb4e8 --- /dev/null +++ b/beecrypt/c++/provider/BeeCertificateFactory.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file BeeCertificateFactory.h + * \ingroup CXX_PROV_m + */ + +#ifndef _CLASS_BEECERTIFICATEFACTORY_H +#define _CLASS_BEECERTIFICATEFACTORY_H + +#ifdef __cplusplus + +#include "beecrypt/c++/security/cert/CertificateFactorySpi.h" +using beecrypt::security::cert::CertificateFactorySpi; + +namespace beecrypt { + namespace provider { + class BeeCertificateFactory : public CertificateFactorySpi + { + protected: + virtual Certificate* engineGenerateCertificate(InputStream& in) throw (CertificateException); + virtual vector* engineGenerateCertificates(InputStream& in) throw (CertificateException); + + public: + BeeCertificateFactory(); + virtual ~BeeCertificateFactory(); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/provider/BeeCryptProvider.cxx b/beecrypt/c++/provider/BeeCryptProvider.cxx new file mode 100644 index 0000000..6f42c30 --- /dev/null +++ b/beecrypt/c++/provider/BeeCryptProvider.cxx @@ -0,0 +1,289 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/provider/BeeCertificateFactory.h" +#include "beecrypt/c++/provider/BeeCryptProvider.h" +#include "beecrypt/c++/provider/BeeKeyFactory.h" +#include "beecrypt/c++/provider/BeeKeyStore.h" +#include "beecrypt/c++/provider/BeeSecureRandom.h" +#include "beecrypt/c++/provider/DHKeyFactory.h" +#include "beecrypt/c++/provider/DHKeyPairGenerator.h" +#include "beecrypt/c++/provider/DHParameterGenerator.h" +#include "beecrypt/c++/provider/DHParameters.h" +#include "beecrypt/c++/provider/DSAKeyFactory.h" +#include "beecrypt/c++/provider/DSAKeyPairGenerator.h" +#include "beecrypt/c++/provider/DSAParameterGenerator.h" +#include "beecrypt/c++/provider/DSAParameters.h" +#include "beecrypt/c++/provider/HMACMD5.h" +#include "beecrypt/c++/provider/HMACSHA256.h" +#include "beecrypt/c++/provider/MD5Digest.h" +#include "beecrypt/c++/provider/MD5withRSASignature.h" +#include "beecrypt/c++/provider/PKCS12KeyFactory.h" +#include "beecrypt/c++/provider/RSAKeyFactory.h" +#include "beecrypt/c++/provider/RSAKeyPairGenerator.h" +#include "beecrypt/c++/provider/SHA1Digest.h" +#include "beecrypt/c++/provider/SHA1withDSASignature.h" +#include "beecrypt/c++/provider/SHA1withRSASignature.h" +#include "beecrypt/c++/provider/SHA256withRSASignature.h" + +namespace { + const String PROVIDER_NAME = UNICODE_STRING_SIMPLE("BeeCrypt++"); + const String PROVIDER_INFO = UNICODE_STRING_SIMPLE("Copyright (c) 2004 Beeyond Software Holding"); + const double PROVIDER_VERSION = 0.1; +} + +extern "C" { + +#if WIN32 +# define PROVAPI __declspec(dllexport) +#else +# define PROVAPI +#endif + +PROVAPI +void* beecrypt_BeeCertificateFactory_create() +{ + return new beecrypt::provider::BeeCertificateFactory(); +} + +PROVAPI +void* beecrypt_BeeKeyFactory_create() +{ + return new beecrypt::provider::BeeKeyFactory(); +} + +PROVAPI +void* beecrypt_BeeKeyStore_create() +{ + return new beecrypt::provider::BeeKeyStore(); +} + +PROVAPI +void* beecrypt_BeeSecureRandom_create() +{ + return new beecrypt::provider::BeeSecureRandom(); +} + +PROVAPI +void* beecrypt_DHKeyFactory_create() +{ + return new beecrypt::provider::DHKeyFactory(); +} + +PROVAPI +void* beecrypt_DHKeyPairGenerator_create() +{ + return new beecrypt::provider::DHKeyPairGenerator(); +} + +PROVAPI +void* beecrypt_HParameterGenerator_create() +{ + return new beecrypt::provider::DHParameterGenerator(); +} + +PROVAPI +void* beecrypt_DHParameters_create() +{ + return new beecrypt::provider::DHParameters(); +} + +PROVAPI +void* beecrypt_DSAKeyFactory_create() +{ + return new beecrypt::provider::DSAKeyFactory(); +} + +PROVAPI +void* beecrypt_DSAKeyPairGenerator_create() +{ + return new beecrypt::provider::DSAKeyPairGenerator(); +} + +PROVAPI +void* beecrypt_DSAParameterGenerator_create() +{ + return new beecrypt::provider::DSAParameterGenerator(); +} + +PROVAPI +void* beecrypt_DSAParameters_create() +{ + return new beecrypt::provider::DSAParameters(); +} + +PROVAPI +void* beecrypt_HMACMD5_create() +{ + return new beecrypt::provider::HMACMD5(); +} + +PROVAPI +void* beecrypt_HMACSHA256_create() +{ + return new beecrypt::provider::HMACSHA256(); +} + +PROVAPI +void* beecrypt_MD5Digest_create() +{ + return new beecrypt::provider::MD5Digest(); +} + +PROVAPI +void* beecrypt_MD5withRSASignature_create() +{ + return new beecrypt::provider::MD5withRSASignature(); +} + +PROVAPI +void* beecrypt_PKCS12KeyFactory_create() +{ + return new beecrypt::provider::PKCS12KeyFactory(); +} + +PROVAPI +void* beecrypt_RSAKeyFactory_create() +{ + return new beecrypt::provider::RSAKeyFactory(); +} + +PROVAPI +void* beecrypt_RSAKeyPairGenerator_create() +{ + return new beecrypt::provider::RSAKeyPairGenerator(); +} + +PROVAPI +void* beecrypt_SHA1Digest_create() +{ + return new beecrypt::provider::SHA1Digest(); +} + +PROVAPI +void* beecrypt_SHA1withDSASignature_create() +{ + return new beecrypt::provider::SHA1withDSASignature(); +} + +PROVAPI +void* beecrypt_SHA1withRSASignature_create() +{ + return new beecrypt::provider::SHA1withRSASignature(); +} + +PROVAPI +void* beecrypt_SHA256withRSASignature_create() +{ + return new beecrypt::provider::SHA256withRSASignature(); +} + +} + +using namespace beecrypt::provider; + +BeeCryptProvider::BeeCryptProvider() : Provider(PROVIDER_NAME, PROVIDER_VERSION, PROVIDER_INFO) +{ + _dlhandle = 0; + + putall(); +} + +BeeCryptProvider::BeeCryptProvider(void* dlhandle) : Provider(PROVIDER_NAME, PROVIDER_VERSION, PROVIDER_INFO) +{ + _dlhandle = dlhandle; + + putall(); +} + +BeeCryptProvider::~BeeCryptProvider() +{ +} + +void BeeCryptProvider::putall() +{ + put("AlgorithmParameterGenerator.DH" , "beecrypt_DHParameterGenerator_create"); + put("AlgorithmParameterGenerator.DSA" , "beecrypt_DSAParameterGenerator_create"); + put("AlgorithmParameters.DH" , "beecrypt_DHParameters_create"); + put("AlgorithmParameters.DSA" , "beecrypt_DSAParameters_create"); + put("CertificateFactory.BEE" , "beecrypt_BeeCertificateFactory_create"); + put("KeyFactory.BEE" , "beecrypt_BeeKeyFactory_create"); + put("KeyFactory.DH" , "beecrypt_DHKeyFactory_create"); + put("KeyFactory.DSA" , "beecrypt_DSAKeyFactory_create"); + put("KeyFactory.RSA" , "beecrypt_RSAKeyFactory_create"); + put("KeyStore.BEE" , "beecrypt_BeeKeyStore_create"); + put("KeyPairGenerator.DH" , "beecrypt_DHKeyPairGenerator_create"); + put("KeyPairGenerator.DSA" , "beecrypt_DSAKeyPairGenerator_create"); + put("KeyPairGenerator.RSA" , "beecrypt_RSAKeyPairGenerator_create"); + put("Mac.HMAC-MD5" , "beecrypt_HMACMD5_create"); + put("Mac.HMAC-SHA-1" , "beecrypt_HMACSHA1_create"); + put("Mac.HMAC-SHA-256" , "beecrypt_HMACSHA256_create"); + put("MessageDigest.MD5" , "beecrypt_MD5Digest_create"); + put("MessageDigest.SHA-1" , "beecrypt_SHA1Digest_create"); + put("SecretKeyFactory.PKCS#12/PBE" , "beecrypt_PKCS12KeyFactory_create"); + put("SecureRandom.BEE" , "beecrypt_BeeSecureRandom_create"); + put("Signature.MD5withRSA" , "beecrypt_MD5withRSASignature_create"); + put("Signature.SHA1withDSA" , "beecrypt_SHA1withDSASignature_create"); + put("Signature.SHA1withRSA" , "beecrypt_SHA1withRSASignature_create"); + put("Signature.SHA256withRSA" , "beecrypt_SHA256withRSASignature_create"); + put("Alg.Alias.KeyFactory.DiffieHellman" , "KeyFactory.DH"); + put("Alg.Alias.KeyPairGenerator.DiffieHellman" , "KeyFactory.DH"); + put("Alg.Alias.Signature.DSS" , "Signature.SHA1withDSA"); + put("Alg.Alias.Signature.SHAwithDSA" , "Signature.SHA1withDSA"); + put("Alg.Alias.Signature.SHA/DSA" , "Signature.SHA1withDSA"); + put("Alg.Alias.Signature.SHA-1/DSA" , "Signature.SHA1withDSA"); +} + +namespace { + bool init = false; + BeeCryptProvider* singleton; +} + +extern "C" { + +#if WIN32 +__declspec(dllexport) +BOOL WINAPI DllMain(HINSTANCE hInst, DWORD wDataSeg, LPVOID lpReserved) +{ + switch (wDataSeg) + { + case DLL_PROCESS_ATTACH: + break; + case DLL_PROCESS_DETACH: + break; + } + return TRUE; +} + +__declspec(dllexport) +#endif +const Provider& provider_const_ref(void *dlhandle) +{ + if (!init) + { + singleton = new BeeCryptProvider(dlhandle); + init = true; + } + return *singleton; +} + +} diff --git a/beecrypt/c++/provider/BeeCryptProvider.h b/beecrypt/c++/provider/BeeCryptProvider.h new file mode 100644 index 0000000..6f67225 --- /dev/null +++ b/beecrypt/c++/provider/BeeCryptProvider.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file BeeCryptProvider.h + * \ingroup CXX_PROV_m + */ + +#ifndef _CLASS_BEECRYPTPROVIDER_H +#define _CLASS_BEECRYPTPROVIDER_H + +#ifdef __cplusplus + +#include "beecrypt/c++/security/Provider.h" +using beecrypt::security::Provider; + +namespace beecrypt { + namespace provider { + class BeeCryptProvider : public Provider + { + private: + void putall(); + + public: + BeeCryptProvider(); + BeeCryptProvider(void*); + virtual ~BeeCryptProvider(); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/provider/BeeKeyFactory.cxx b/beecrypt/c++/provider/BeeKeyFactory.cxx new file mode 100644 index 0000000..96c4147 --- /dev/null +++ b/beecrypt/c++/provider/BeeKeyFactory.cxx @@ -0,0 +1,391 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/beeyond/BeeEncodedKeySpec.h" +using beecrypt::beeyond::BeeEncodedKeySpec; +#include "beecrypt/c++/beeyond/BeeInputStream.h" +using beecrypt::beeyond::BeeInputStream; +#include "beecrypt/c++/beeyond/BeeOutputStream.h" +using beecrypt::beeyond::BeeOutputStream; +#include "beecrypt/c++/io/ByteArrayInputStream.h" +using beecrypt::io::ByteArrayInputStream; +#include "beecrypt/c++/io/ByteArrayOutputStream.h" +using beecrypt::io::ByteArrayOutputStream; +#include "beecrypt/c++/provider/BeeKeyFactory.h" +#include "beecrypt/c++/provider/DHPrivateKeyImpl.h" +#include "beecrypt/c++/provider/DHPublicKeyImpl.h" +#include "beecrypt/c++/provider/DSAPrivateKeyImpl.h" +#include "beecrypt/c++/provider/DSAPublicKeyImpl.h" +#include "beecrypt/c++/provider/RSAPrivateKeyImpl.h" +#include "beecrypt/c++/provider/RSAPrivateCrtKeyImpl.h" +#include "beecrypt/c++/provider/RSAPublicKeyImpl.h" + +namespace { + const String ALGORITHM_DH = UNICODE_STRING_SIMPLE("DH"); + const String ALGORITHM_DSA = UNICODE_STRING_SIMPLE("DSA"); + const String ALGORITHM_RSA = UNICODE_STRING_SIMPLE("RSA"); +} + +using namespace beecrypt::provider; + +BeeKeyFactory::BeeKeyFactory() +{ +} + +BeeKeyFactory::~BeeKeyFactory() +{ +} + +PrivateKey* BeeKeyFactory::decodePrivate(const byte* data, size_t offset, size_t size) +{ + try + { + String algo; + + ByteArrayInputStream bis(data, offset, size); + BeeInputStream bee(bis); + + bee.readUTF(algo); + + if (algo == ALGORITHM_DH) + { + mpbarrett p; + mpnumber g; + mpnumber x; + + bee.read(p); + bee.read(g); + bee.read(x); + + return new DHPrivateKeyImpl(p, g, x); + } + + if (algo == ALGORITHM_DSA) + { + mpbarrett p; + mpbarrett q; + mpnumber g; + mpnumber x; + + bee.read(p); + bee.read(q); + bee.read(g); + bee.read(x); + + return new DSAPrivateKeyImpl(p, q, g, x); + } + + if (algo == ALGORITHM_RSA) + { + mpbarrett n; + mpnumber d; + + bee.read(n); + bee.read(d); + + if (bee.available() > 0) + { + mpnumber e; + mpbarrett p; + mpbarrett q; + mpnumber dp; + mpnumber dq; + mpnumber qi; + + bee.read(e); + bee.read(p); + bee.read(q); + bee.read(dp); + bee.read(dq); + bee.read(qi); + + return new RSAPrivateCrtKeyImpl(n, e, d, p, q, dp, dq, qi); + } + return new RSAPrivateKeyImpl(n, d); + } + } + catch (IOException) + { + } + return 0; +} + +PublicKey* BeeKeyFactory::decodePublic(const byte* data, size_t offset, size_t size) +{ + try + { + String algo; + + ByteArrayInputStream bis(data, offset, size); + BeeInputStream bee(bis); + + bee.readUTF(algo); + + if (algo == ALGORITHM_DH) + { + mpbarrett p; + mpnumber g; + mpnumber y; + + bee.read(p); + bee.read(g); + bee.read(y); + + return new DHPublicKeyImpl(p, g, y); + } + + if (algo == ALGORITHM_DSA) + { + mpbarrett p; + mpbarrett q; + mpnumber g; + mpnumber y; + + bee.read(p); + bee.read(q); + bee.read(g); + bee.read(y); + + return new DSAPublicKeyImpl(p, q, g, y); + } + + if (algo == ALGORITHM_RSA) + { + mpbarrett n; + mpnumber e; + + bee.read(n); + bee.read(e); + + return new RSAPublicKeyImpl(n, e); + } + } + catch (IOException) + { + } + return 0; +} + +bytearray* BeeKeyFactory::encode(const PrivateKey& pri) +{ + try + { + ByteArrayOutputStream bos; + BeeOutputStream bee(bos); + + bee.writeUTF(pri.getAlgorithm()); + + const DHPrivateKey* dh = dynamic_cast(&pri); + if (dh) + { + bee.write(dh->getParams().getP()); + bee.write(dh->getParams().getG()); + bee.write(dh->getX()); + bee.close(); + + return bos.toByteArray(); + } + + const DSAPrivateKey* dsa = dynamic_cast(&pri); + if (dsa) + { + bee.write(dsa->getParams().getP()); + bee.write(dsa->getParams().getQ()); + bee.write(dsa->getParams().getG()); + bee.write(dsa->getX()); + bee.close(); + + return bos.toByteArray(); + } + + const RSAPrivateKey* rsa = dynamic_cast(&pri); + if (rsa) + { + bee.write(rsa->getModulus()); + + const RSAPrivateCrtKey* crt = dynamic_cast(rsa); + + if (crt) + { + bee.write(crt->getPublicExponent()); + bee.write(crt->getPrivateExponent()); + bee.write(crt->getPrimeP()); + bee.write(crt->getPrimeQ()); + bee.write(crt->getPrimeExponentP()); + bee.write(crt->getPrimeExponentQ()); + bee.write(crt->getCrtCoefficient()); + } + else + { + bee.write(rsa->getPrivateExponent()); + } + bee.close(); + + return bos.toByteArray(); + } + } + catch (IOException) + { + } + return 0; +} + + +bytearray* BeeKeyFactory::encode(const PublicKey& pub) +{ + try + { + ByteArrayOutputStream bos; + BeeOutputStream bee(bos); + + bee.writeUTF(pub.getAlgorithm()); + + const DHPublicKey* dh = dynamic_cast(&pub); + if (dh) + { + bee.write(dh->getParams().getP()); + bee.write(dh->getParams().getG()); + bee.write(dh->getY()); + bee.close(); + + return bos.toByteArray(); + } + + const DSAPublicKey* dsa = dynamic_cast(&pub); + if (dsa) + { + bee.write(dsa->getParams().getP()); + bee.write(dsa->getParams().getQ()); + bee.write(dsa->getParams().getG()); + bee.write(dsa->getY()); + bee.close(); + + return bos.toByteArray(); + } + + const RSAPublicKey* rsa = dynamic_cast(&pub); + if (rsa) + { + bee.write(rsa->getModulus()); + bee.write(rsa->getPublicExponent()); + bee.close(); + + return bos.toByteArray(); + } + } + catch (IOException) + { + } + return 0; +} + +PrivateKey* BeeKeyFactory::engineGeneratePrivate(const KeySpec& spec) throw (InvalidKeySpecException) +{ + const EncodedKeySpec* enc = dynamic_cast(&spec); + + if (enc && enc->getFormat().caseCompare("BEE", 0) == 0) + { + const bytearray& encoding = enc->getEncoded(); + + PrivateKey* pri = decodePrivate(encoding.data(), 0, encoding.size()); + + if (pri) + return pri; + else + throw InvalidKeySpecException("Unable to decode this KeySpec to a PrivateKey"); + } + else + throw InvalidKeySpecException("Unsupported KeySpec"); +} + +PublicKey* BeeKeyFactory::engineGeneratePublic(const KeySpec& spec) throw (InvalidKeySpecException) +{ + const EncodedKeySpec* enc = dynamic_cast(&spec); + + if (enc && enc->getFormat().caseCompare("BEE", 0) == 0) + { + const bytearray& encoding = enc->getEncoded(); + + PublicKey* pub = decodePublic(encoding.data(), 0, encoding.size()); + + if (pub) + return pub; + else + throw InvalidKeySpecException("Unable to decode this KeySpec to a PublicKey"); + } + else + throw InvalidKeySpecException("Unsupported KeySpec"); +} + +KeySpec* BeeKeyFactory::engineGetKeySpec(const Key& key, const type_info& info) throw (InvalidKeySpecException) +{ + KeySpec* result = 0; + + if (info == typeid(EncodedKeySpec)) + { + const String* format = key.getFormat(); + + if (format && format->caseCompare("BEE", 0) == 0) + { + result = new BeeEncodedKeySpec(*key.getEncoded()); + } + else + { + bytearray* enc; + + const PublicKey* pub = dynamic_cast(&key); + + if (pub) + { + enc = encode(*pub); + } + else + { + const PrivateKey* pri = dynamic_cast(&key); + + if (pri) + { + enc = encode(*pri); + } + } + + if (enc) + { + result = new BeeEncodedKeySpec(*enc); + + delete enc; + } + } + + if (result) + return result; + else + throw InvalidKeySpecException("Unsupported key type"); + } + else + throw InvalidKeySpecException("Unsupported KeySpec type"); +} + +Key* BeeKeyFactory::engineTranslateKey(const Key&) throw (InvalidKeyException) +{ + throw InvalidKeyException("This KeyFactory can only be used for encoding and decoding"); +} diff --git a/beecrypt/c++/provider/BeeKeyFactory.h b/beecrypt/c++/provider/BeeKeyFactory.h new file mode 100644 index 0000000..87238d3 --- /dev/null +++ b/beecrypt/c++/provider/BeeKeyFactory.h @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file BeeKeyFactory.h + * \ingroup CXX_PROVIDER_m + */ + +#ifndef _CLASS_BEEKEYFACTORY_H +#define _CLASS_BEEKEYFACTORY_H + +#ifdef __cplusplus + +#include "beecrypt/c++/security/KeyFactorySpi.h" +using beecrypt::security::InvalidKeyException; +using beecrypt::security::Key; +using beecrypt::security::KeyFactorySpi; +using beecrypt::security::PrivateKey; +using beecrypt::security::PublicKey; +using beecrypt::security::spec::InvalidKeySpecException; +using beecrypt::security::spec::KeySpec; + +namespace beecrypt { + namespace provider { + class BeeKeyFactory : public KeyFactorySpi + { + public: + static PrivateKey* decodePrivate(const byte*, size_t, size_t); + static PublicKey* decodePublic(const byte*, size_t, size_t); + static bytearray* encode(const PrivateKey&); + static bytearray* encode(const PublicKey&); + + protected: + virtual PrivateKey* engineGeneratePrivate(const KeySpec&) throw (InvalidKeySpecException); + virtual PublicKey* engineGeneratePublic(const KeySpec&) throw (InvalidKeySpecException); + + virtual KeySpec* engineGetKeySpec(const Key&, const type_info&) throw (InvalidKeySpecException); + + virtual Key* engineTranslateKey(const Key&) throw (InvalidKeyException); + + public: + BeeKeyFactory(); + virtual ~BeeKeyFactory(); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/provider/BeeKeyStore.cxx b/beecrypt/c++/provider/BeeKeyStore.cxx new file mode 100644 index 0000000..1a6e870 --- /dev/null +++ b/beecrypt/c++/provider/BeeKeyStore.cxx @@ -0,0 +1,639 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/aes.h" +#include "beecrypt/pkcs12.h" +#include "beecrypt/sha256.h" + +#include "beecrypt/c++/crypto/Mac.h" +using beecrypt::crypto::Mac; +#include "beecrypt/c++/io/ByteArrayInputStream.h" +using beecrypt::io::ByteArrayInputStream; +#include "beecrypt/c++/io/DataInputStream.h" +using beecrypt::io::DataInputStream; +#include "beecrypt/c++/io/DataOutputStream.h" +using beecrypt::io::DataOutputStream; +#include "beecrypt/c++/crypto/MacInputStream.h" +using beecrypt::crypto::MacInputStream; +#include "beecrypt/c++/crypto/MacOutputStream.h" +using beecrypt::crypto::MacOutputStream; +#include "beecrypt/c++/security/SecureRandom.h" +using beecrypt::security::SecureRandom; +#include "beecrypt/c++/beeyond/PKCS12PBEKey.h" +using beecrypt::beeyond::PKCS12PBEKey; +#include "beecrypt/c++/provider/KeyProtector.h" +using beecrypt::provider::KeyProtector; +#include "beecrypt/c++/provider/BeeKeyStore.h" + +using namespace beecrypt::provider; + +namespace { + const array EMPTY_PASSWORD; +} + +#define BKS_MAGIC ((javaint) 0xbeecceec) +#define BKS_VERSION_1 ((javaint) 0x1) +#define BKS_PRIVATEKEY_ENTRY ((javaint) 0x1) +#define BKS_CERTIFICATE_ENTRY ((javaint) 0x2) + +BeeKeyStore::Entry::~Entry() +{ +} + +BeeKeyStore::KeyEntry::KeyEntry() +{ +} + +BeeKeyStore::KeyEntry::KeyEntry(const bytearray& b, const vector& c) +{ + encryptedkey = b; + for (vector::const_iterator it = c.begin(); it != c.end(); it++) + chain.push_back((*it)->clone()); +} + +BeeKeyStore::KeyEntry::~KeyEntry() +{ + // delete all the certificates in the chain + for (size_t i = 0; i < chain.size(); i++) + delete chain[i]; +} + +BeeKeyStore::CertEntry::CertEntry() +{ + cert = 0; +} + +BeeKeyStore::CertEntry::CertEntry(const Certificate& c) +{ + cert = c.clone(); +} + +BeeKeyStore::CertEntry::~CertEntry() +{ + if (cert) + { + delete cert; + cert = 0; + } +} + +BeeKeyStore::BeeKeyStore() +{ + _lock.init(); +} + +BeeKeyStore::~BeeKeyStore() +{ + _lock.lock(); + clearall(); + _lock.unlock(); + _lock.destroy(); +} + +BeeKeyStore::AliasEnum::AliasEnum(const BeeKeyStore::entry_map& map) +{ + _it = map.begin(); + _end = map.end(); +} + +BeeKeyStore::AliasEnum::~AliasEnum() throw () +{ +} + +bool BeeKeyStore::AliasEnum::hasMoreElements() throw () +{ + return _it != _end; +} + +const void* BeeKeyStore::AliasEnum::nextElement() throw (NoSuchElementException) +{ + if (_it == _end) + throw NoSuchElementException(); + + return (const void*) &((_it++)->first); +} + +void BeeKeyStore::clearall() +{ + keyfactory_map::iterator kit = _keyfactories.begin(); + while (kit != _keyfactories.end()) + { + delete kit->second; + _keyfactories.erase(kit++); + } + + certfactory_map::iterator cit = _certfactories.begin(); + while (cit != _certfactories.end()) + { + delete cit->second; + _certfactories.erase(cit++); + } + + entry_map::iterator eit = _entries.begin(); + while (eit != _entries.end()) + { + delete eit->second; + _entries.erase(eit++); + } +} + +Enumeration* BeeKeyStore::engineAliases() +{ + return new AliasEnum(_entries); +} + +bool BeeKeyStore::engineContainsAlias(const String& alias) +{ + return (_entries[alias] != 0); +} + +void BeeKeyStore::engineDeleteEntry(const String& alias) throw (KeyStoreException) +{ + _lock.lock(); + entry_map::iterator it = _entries.find(alias); + + if (it != _entries.end()) + { + delete it->second; + _entries.erase(it); + } + _lock.unlock(); +} + +const Date* BeeKeyStore::engineGetCreationDate(const String& alias) +{ + const Date* result = 0; + + _lock.lock(); + entry_map::iterator it = _entries.find(alias); + if (it != _entries.end()) + result = &(it->second->date); + _lock.unlock(); + return result; +} + +const Certificate* BeeKeyStore::engineGetCertificate(const String& alias) +{ + const Certificate* result = 0; + + _lock.lock(); + entry_map::iterator it = _entries.find(alias); + if (it != _entries.end()) + { + CertEntry* ce = dynamic_cast(it->second); + if (ce) + result = ce->cert; + } + _lock.unlock(); + return result; +} + +const String* BeeKeyStore::engineGetCertificateAlias(const Certificate& cert) +{ + const String* result = 0; + + _lock.lock(); + for (entry_map::const_iterator it = _entries.begin(); it != _entries.end(); ++it) + { + const CertEntry* ce = dynamic_cast(it->second); + if (ce) + { + if (cert == *(ce->cert)) + { + result = &(it->first); + break; + } + } + } + _lock.unlock(); + return result; +} + +const vector* BeeKeyStore::engineGetCertificateChain(const String& alias) +{ + const vector* result = 0; + + _lock.unlock(); + entry_map::iterator it = _entries.find(alias); + if (it != _entries.end()) + { + KeyEntry* ke = dynamic_cast(it->second); + if (ke) + result = &ke->chain; + } + _lock.unlock(); + return result; +} + +bool BeeKeyStore::engineIsCertificateEntry(const String& alias) +{ + bool result = false; + _lock.lock(); + entry_map::iterator it = _entries.find(alias); + if (it != _entries.end()) + result = (dynamic_cast(it->second) != 0); + _lock.unlock(); + return result; +} + +void BeeKeyStore::engineSetCertificateEntry(const String& alias, const Certificate& cert) throw (KeyStoreException) +{ + _entries[alias] = new CertEntry(cert); +} + +Key* BeeKeyStore::engineGetKey(const String& alias, const array& password) throw (NoSuchAlgorithmException, UnrecoverableKeyException) +{ + Key* result = 0; + + _lock.lock(); + entry_map::iterator it = _entries.find(alias); + if (it != _entries.end()) + { + KeyEntry* ke = dynamic_cast(it->second); + if (ke) + { + PKCS12PBEKey pbekey(password, &_salt, _iter); + + try + { + KeyProtector p(pbekey); + + result = p.recover(ke->encryptedkey); + } + catch (InvalidKeyException e) + { + _lock.unlock(); + throw KeyStoreException(e.getMessage()); + } + catch (...) + { + _lock.unlock(); + throw; + } + } + } + _lock.unlock(); + + return result; +} + +bool BeeKeyStore::engineIsKeyEntry(const String& alias) +{ + bool result = false; + _lock.lock(); + entry_map::iterator it = _entries.find(alias); + if (it != _entries.end()) + result = (dynamic_cast(it->second) != 0); + _lock.unlock(); + return result; +} + +void BeeKeyStore::engineSetKeyEntry(const String& alias, const bytearray& key, const vector& chain) throw (KeyStoreException) +{ + _lock.lock(); + _entries[alias] = new KeyEntry(key, chain); + _lock.unlock(); +} + +void BeeKeyStore::engineSetKeyEntry(const String& alias, const Key& key, const array& password, const vector& chain) throw (KeyStoreException) +{ + PKCS12PBEKey pbekey(password, &_salt, _iter); + + try + { + const PrivateKey* pri = dynamic_cast(&key); + if (pri) + { + KeyProtector p(pbekey); + + bytearray *tmp = p.protect(*pri); + + if (tmp) + engineSetKeyEntry(alias, *tmp, chain); + else + throw KeyStoreException("Failed to protect key"); + } + else + throw KeyStoreException("BeeKeyStore only supports storing of PrivateKey objects"); + } + catch (InvalidKeyException e) + { + throw KeyStoreException(e.getMessage()); + } +} + +size_t BeeKeyStore::engineSize() const +{ + return _entries.size(); +} + +void BeeKeyStore::engineLoad(InputStream* in, const array* password) throw (IOException, CertificateException, NoSuchAlgorithmException) +{ + _lock.lock(); + + if (in == 0) + { + randomGeneratorContext rngc; + + /* salt size default is 64 bytes */ + _salt.resize(64); + /* generate a new salt */ + randomGeneratorContextNext(&rngc, _salt.data(), _salt.size()); + /* set default iteration count */ + _iter = 1024; + + _lock.unlock(); + + return; + } + + Mac* m = 0; + + try + { + m = Mac::getInstance("HMAC-SHA-256"); + + MacInputStream mis(*in, *m); + DataInputStream dis(mis); + + mis.on(false); + + javaint magic = dis.readInt(); + javaint version = dis.readInt(); + + if (magic != BKS_MAGIC || version != BKS_VERSION_1) + throw IOException("Invalid KeyStore format"); + + clearall(); + + javaint saltsize = dis.readInt(); + if (saltsize <= 0) + throw IOException("Invalid KeyStore salt size"); + + _salt.resize(saltsize); + dis.readFully(_salt); + + _iter = dis.readInt(); + if (_iter <= 0) + throw IOException("Invalid KeyStore iteration count"); + + PKCS12PBEKey pbekey(password ? *password : EMPTY_PASSWORD, &_salt, _iter); + + m->init(pbekey); + + mis.on(true); + + javaint entrycount = dis.readInt(); + + if (entrycount <= 0) + throw IOException("Invalid KeyStore entry count"); + + for (javaint i = 0; i < entrycount; i++) + { + String alias; + + switch (dis.readInt()) + { + case BKS_PRIVATEKEY_ENTRY: + { + dis.readUTF(alias); + + KeyEntry* e = new KeyEntry; + + try + { + e->date.setTime(dis.readLong()); + + javaint keysize = dis.readInt(); + + if (keysize <= 0) + throw IOException("Invalid KeyStore key length"); + + e->encryptedkey.resize((size_t) keysize); + + dis.readFully(e->encryptedkey); + + javaint certcount = dis.readInt(); + + if (certcount <= 0) + throw IOException("Invalid KeyStore certificate count"); + + for (javaint j = 0; j < certcount; j++) + { + String type; + + dis.readUTF(type); + + // see if we have a CertificateFactory of this type available + CertificateFactory* cf = _certfactories[type]; + if (!cf) + { + // apparently not; get a new one and cache it + _certfactories[type] = cf = CertificateFactory::getInstance(type); + } + + javaint certsize = dis.readInt(); + + if (certsize <= 0) + throw IOException("Invalid KeyStore certificate size"); + + bytearray cert(certsize); + + dis.readFully(cert); + + ByteArrayInputStream bis(cert); + + e->chain.push_back(cf->generateCertificate(bis)); + } + + _entries[alias] = e; + } + catch (...) + { + delete e; + throw; + } + } + break; + + case BKS_CERTIFICATE_ENTRY: + { + dis.readUTF(alias); + + CertEntry* e = new CertEntry; + + try + { + e->date.setTime(dis.readLong()); + + String type; + + dis.readUTF(type); + + // see if we have a CertificateFactory of this type available + CertificateFactory* cf = _certfactories[type]; + if (!cf) + { + // apparently not; get a new one and cache it + _certfactories[type] = cf = CertificateFactory::getInstance(type); + } + + javaint certsize = dis.readInt(); + + if (certsize <= 0) + throw IOException("Invalid KeyStore certificate size"); + + bytearray cert(certsize); + + dis.readFully(cert); + + ByteArrayInputStream bis(cert); + + e->cert = cf->generateCertificate(bis); + + _entries[alias] = e; + } + catch (...) + { + delete e; + throw; + } + } + break; + + default: + throw IOException("Invalid KeyStore entry tag"); + } + } + + bytearray computed_mac, original_mac; + + mis.on(false); + + javaint macsize = dis.available(); + if (macsize <= 0) + throw IOException("Invalid KeyStore MAC size"); + + computed_mac = m->doFinal(); + if (macsize != computed_mac.size()) + throw KeyStoreException("KeyStore has been tampered with, or password was incorrect"); + + original_mac.resize(macsize); + dis.readFully(original_mac); + + if (computed_mac != original_mac) + throw KeyStoreException("KeyStore has been tampered with, or password was incorrect"); + + delete m; + } + catch (...) + { + if (m) + delete m; + + _lock.unlock(); + throw; + } + + _lock.unlock(); +} + +void BeeKeyStore::engineStore(OutputStream& out, const array* password) throw (IOException, CertificateException, NoSuchAlgorithmException) +{ + _lock.lock(); + + Mac* m = 0; + + try + { + m = Mac::getInstance("HMAC-SHA-256"); + + PKCS12PBEKey pbekey(password ? *password : EMPTY_PASSWORD, &_salt, _iter); + + m->init(pbekey); + + MacOutputStream mos(out, *m); + DataOutputStream dos(mos); + + mos.on(false); + dos.writeInt(BKS_MAGIC); + dos.writeInt(BKS_VERSION_1); + dos.writeInt(_salt.size()); + dos.write(_salt); + dos.writeInt(_iter); + mos.on(true); + dos.writeInt(_entries.size()); + + for (entry_map::const_iterator it = _entries.begin(); it != _entries.end(); ++it) + { + const KeyEntry* ke = dynamic_cast(it->second); + if (ke) + { + dos.writeInt(BKS_PRIVATEKEY_ENTRY); + dos.writeUTF(it->first); + dos.writeLong(ke->date.getTime()); + dos.writeInt(ke->encryptedkey.size()); + dos.write(ke->encryptedkey); + /* next do all the certificates for this key */ + dos.writeInt(ke->chain.size()); + for (vector::const_iterator cit = ke->chain.begin(); cit != ke->chain.end(); ++cit) + { + const Certificate* cert = *cit; + + dos.writeUTF(cert->getType()); + dos.writeInt(cert->getEncoded().size()); + dos.write(cert->getEncoded()); + } + continue; + } + + const CertEntry* ce = dynamic_cast(it->second); + if (ce) + { + dos.writeInt(BKS_CERTIFICATE_ENTRY); + dos.writeUTF(it->first); + dos.writeLong(ce->date.getTime()); + dos.writeUTF(ce->cert->getType()); + dos.writeInt(ce->cert->getEncoded().size()); + dos.write(ce->cert->getEncoded()); + continue; + } + + throw RuntimeException(); + } + /* don't call close on a FilterOutputStream because the + * underlying stream still has to write data! + */ + dos.flush(); + mos.flush(); + + out.write(m->doFinal()); + out.close(); + + _lock.unlock(); + } + catch (...) + { + _lock.unlock(); + throw; + } +} diff --git a/beecrypt/c++/provider/BeeKeyStore.h b/beecrypt/c++/provider/BeeKeyStore.h new file mode 100644 index 0000000..625346d --- /dev/null +++ b/beecrypt/c++/provider/BeeKeyStore.h @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file BeeKeyStore.h + * \ingroup CXX_PROVIDER_m + */ + +#ifndef _CLASS_BEEKEYSTORE_H +#define _CLASS_BEEKEYSTORE_H + +#ifdef __cplusplus + +#include "beecrypt/c++/mutex.h" +using beecrypt::mutex; +#include "beecrypt/c++/security/KeyStoreSpi.h" +using beecrypt::security::KeyStoreSpi; +#include "beecrypt/c++/security/KeyFactory.h" +using beecrypt::security::KeyFactory; +#include "beecrypt/c++/security/cert/CertificateFactory.h" +using beecrypt::security::cert::CertificateFactory; +#include "beecrypt/c++/util/Enumeration.h" +using beecrypt::util::Enumeration; + +#include +using std::map; + +namespace beecrypt { + namespace provider { + /*!\brief The default BeeCrypt KeyStore. + */ + class BeeKeyStore : public KeyStoreSpi + { + private: + mutex _lock; + bytearray _bmac; + bytearray _salt; + size_t _iter; + + struct Entry + { + Date date; + virtual ~Entry(); + }; + + struct KeyEntry : public Entry + { + bytearray encryptedkey; + vector chain; + + KeyEntry(); + KeyEntry(const bytearray& key, const vector&); + virtual ~KeyEntry(); + }; + + struct CertEntry : public Entry + { + Certificate* cert; + + CertEntry(); + CertEntry(const Certificate&); + virtual ~CertEntry(); + }; + + typedef map keyfactory_map; + keyfactory_map _keyfactories; + + typedef map certfactory_map; + certfactory_map _certfactories; + + typedef map entry_map; + entry_map _entries; + + struct AliasEnum : public Enumeration + { + entry_map::const_iterator _it; + entry_map::const_iterator _end; + + AliasEnum(const entry_map&); + virtual ~AliasEnum() throw (); + + virtual bool hasMoreElements() throw (); + virtual const void* nextElement() throw (NoSuchElementException); + }; + + void clearall(); + + protected: + virtual Enumeration* engineAliases(); + + virtual bool engineContainsAlias(const String& alias); + + virtual void engineDeleteEntry(const String& alias) throw (KeyStoreException); + virtual const Date* engineGetCreationDate(const String& alias); + + virtual const Certificate* engineGetCertificate(const String& alias); + virtual const String* engineGetCertificateAlias(const Certificate& cert); + virtual const vector* engineGetCertificateChain(const String& alias); + virtual bool engineIsCertificateEntry(const String& alias); + virtual void engineSetCertificateEntry(const String& alias, const Certificate& cert) throw (KeyStoreException); + + virtual Key* engineGetKey(const String& alias, const array& password) throw (NoSuchAlgorithmException, UnrecoverableKeyException); + virtual bool engineIsKeyEntry(const String& alias); + virtual void engineSetKeyEntry(const String& alias, const bytearray& key, const vector&) throw (KeyStoreException); + virtual void engineSetKeyEntry(const String& alias, const Key& key, const array& password, const vector&) throw (KeyStoreException); + + virtual size_t engineSize() const; + + virtual void engineLoad(InputStream* in, const array* password) throw (IOException, CertificateException, NoSuchAlgorithmException); + virtual void engineStore(OutputStream& out, const array* password) throw (IOException, CertificateException, NoSuchAlgorithmException); + + public: + BeeKeyStore(); + ~BeeKeyStore(); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/provider/BeeSecureRandom.cxx b/beecrypt/c++/provider/BeeSecureRandom.cxx new file mode 100644 index 0000000..3f30200 --- /dev/null +++ b/beecrypt/c++/provider/BeeSecureRandom.cxx @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/provider/BeeSecureRandom.h" + +using namespace beecrypt::provider; + +BeeSecureRandom::BeeSecureRandom() +{ +} + +BeeSecureRandom::BeeSecureRandom(const randomGenerator* rng) : _rngc(rng) +{ +} + +BeeSecureRandom::~BeeSecureRandom() +{ +} + +SecureRandomSpi* BeeSecureRandom::create() +{ + return new BeeSecureRandom(); +} + +void BeeSecureRandom::engineGenerateSeed(byte* data, size_t size) +{ + entropyGatherNext(data, size); +} + +void BeeSecureRandom::engineNextBytes(byte* data, size_t size) +{ + randomGeneratorContextNext(&_rngc, data, size); +} + +void BeeSecureRandom::engineSetSeed(const byte* data, size_t size) +{ + randomGeneratorContextSeed(&_rngc, data, size); +} diff --git a/beecrypt/c++/provider/BeeSecureRandom.h b/beecrypt/c++/provider/BeeSecureRandom.h new file mode 100644 index 0000000..1f21934 --- /dev/null +++ b/beecrypt/c++/provider/BeeSecureRandom.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file BeeSecureRandom.h + * \ingroup CXX_PROVIDER_m + */ + +#ifndef _CLASS_BEESECURERANDOM_H +#define _CLASS_BEESECURERANDOM_H + +#include "beecrypt/beecrypt.h" + +#ifdef __cplusplus + +#include "beecrypt/c++/security/SecureRandomSpi.h" +using beecrypt::security::SecureRandomSpi; + +namespace beecrypt { + namespace provider { + class BeeSecureRandom : public SecureRandomSpi + { + private: + randomGeneratorContext _rngc; + + protected: + BeeSecureRandom(const randomGenerator*); + + private: + static SecureRandomSpi* create(); + + virtual void engineGenerateSeed(byte*, size_t); + virtual void engineNextBytes(byte*, size_t); + virtual void engineSetSeed(const byte*, size_t); + + public: + BeeSecureRandom(); + virtual ~BeeSecureRandom(); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/provider/DHKeyFactory.cxx b/beecrypt/c++/provider/DHKeyFactory.cxx new file mode 100644 index 0000000..f9f42b2 --- /dev/null +++ b/beecrypt/c++/provider/DHKeyFactory.cxx @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/crypto/spec/DHPrivateKeySpec.h" +using beecrypt::crypto::spec::DHPrivateKeySpec; +#include "beecrypt/c++/crypto/spec/DHPublicKeySpec.h" +using beecrypt::crypto::spec::DHPublicKeySpec; +#include "beecrypt/c++/provider/DHKeyFactory.h" +#include "beecrypt/c++/provider/DHPrivateKeyImpl.h" +#include "beecrypt/c++/provider/DHPublicKeyImpl.h" +#include "beecrypt/c++/security/KeyFactory.h" +using beecrypt::security::KeyFactory; +#include "beecrypt/c++/security/spec/EncodedKeySpec.h" +using beecrypt::security::spec::EncodedKeySpec; + +using namespace beecrypt::provider; + +DHKeyFactory::DHKeyFactory() +{ +} + +DHKeyFactory::~DHKeyFactory() +{ +} + +PrivateKey* DHKeyFactory::engineGeneratePrivate(const KeySpec& spec) throw (InvalidKeySpecException) +{ + const DHPrivateKeySpec* dh = dynamic_cast(&spec); + if (dh) + { + return new DHPrivateKeyImpl(dh->getP(), dh->getG(), dh->getX()); + } + + const EncodedKeySpec* enc = dynamic_cast(&spec); + if (enc) + { + try + { + KeyFactory* kf = KeyFactory::getInstance(enc->getFormat()); + try + { + PrivateKey* pri = kf->generatePrivate(*enc); + delete kf; + return pri; + } + catch (...) + { + delete kf; + throw; + } + } + catch (NoSuchAlgorithmException) + { + throw InvalidKeySpecException("Unsupported KeySpec encoding format"); + } + } + throw InvalidKeySpecException("Unsupported KeySpec type"); +} + +PublicKey* DHKeyFactory::engineGeneratePublic(const KeySpec& spec) throw (InvalidKeySpecException) +{ + const DHPublicKeySpec* dh = dynamic_cast(&spec); + if (dh) + { + return new DHPublicKeyImpl(dh->getP(), dh->getG(), dh->getY()); + } + + const EncodedKeySpec* enc = dynamic_cast(&spec); + if (enc) + { + try + { + KeyFactory* kf = KeyFactory::getInstance(enc->getFormat()); + try + { + PublicKey* pub = kf->generatePublic(*enc); + delete kf; + return pub; + } + catch (...) + { + delete kf; + throw; + } + } + catch (NoSuchAlgorithmException) + { + throw InvalidKeySpecException("Unsupported KeySpec encoding format"); + } + } + throw InvalidKeySpecException("Unsupported KeySpec type"); +} + +KeySpec* DHKeyFactory::engineGetKeySpec(const Key& key, const type_info& info) throw (InvalidKeySpecException) +{ + const DHPublicKey* pub = dynamic_cast(&key); + if (pub) + { + if (info == typeid(KeySpec) || info == typeid(DHPrivateKeySpec)) + { + const DHParams& params = pub->getParams(); + + return new DHPublicKeySpec(params.getP(), params.getG(), pub->getY()); + } + /*!\todo also support EncodedKeySpec + */ + /* + if (info == typeid(EncodedKeySpec)) + { + } + */ + + throw InvalidKeySpecException("Unsupported KeySpec type"); + } + + const DHPrivateKey* pri = dynamic_cast(&key); + if (pri) + { + if (info == typeid(KeySpec) || info == typeid(DHPublicKeySpec)) + { + const DHParams& params = pri->getParams(); + + return new DHPrivateKeySpec(params.getP(), params.getG(), pri->getX()); + } + /*!\todo also support EncodedKeySpec + */ + /* + if (info == typeid(EncodedKeySpec)) + { + } + */ + + throw InvalidKeySpecException("Unsupported KeySpec type"); + } + + throw InvalidKeySpecException("Unsupported Key type"); +} + +Key* DHKeyFactory::engineTranslateKey(const Key& key) throw (InvalidKeyException) +{ + const DHPublicKey* pub = dynamic_cast(&key); + if (pub) + return new DHPublicKeyImpl(*pub); + + const DHPrivateKey* pri = dynamic_cast(&key); + if (pri) + return new DHPrivateKeyImpl(*pri); + + throw InvalidKeyException("Unsupported Key type"); +} diff --git a/beecrypt/c++/provider/DHKeyFactory.h b/beecrypt/c++/provider/DHKeyFactory.h new file mode 100644 index 0000000..7d367ac --- /dev/null +++ b/beecrypt/c++/provider/DHKeyFactory.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file DHKeyFactory.h + * \ingroup CXX_PROV_m + */ + +#ifndef _CLASS_DHKEYFACTORY_H +#define _CLASS_DHKEYFACTORY_H + +#ifdef __cplusplus + +#include "beecrypt/c++/security/KeyFactorySpi.h" +using beecrypt::security::InvalidKeyException; +using beecrypt::security::Key; +using beecrypt::security::KeyFactorySpi; +using beecrypt::security::PrivateKey; +using beecrypt::security::PublicKey; +using beecrypt::security::spec::InvalidKeySpecException; +using beecrypt::security::spec::KeySpec; + +namespace beecrypt { + namespace provider { + class DHKeyFactory : public KeyFactorySpi + { + protected: + virtual PrivateKey* engineGeneratePrivate(const KeySpec&) throw (InvalidKeySpecException); + virtual PublicKey* engineGeneratePublic(const KeySpec&) throw (InvalidKeySpecException); + + virtual KeySpec* engineGetKeySpec(const Key&, const type_info&) throw (InvalidKeySpecException); + + virtual Key* engineTranslateKey(const Key&) throw (InvalidKeyException); + + public: + DHKeyFactory(); + virtual ~DHKeyFactory(); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/provider/DHKeyPairGenerator.cxx b/beecrypt/c++/provider/DHKeyPairGenerator.cxx new file mode 100644 index 0000000..2e740a1 --- /dev/null +++ b/beecrypt/c++/provider/DHKeyPairGenerator.cxx @@ -0,0 +1,164 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/adapter.h" +#include "beecrypt/c++/crypto/spec/DHParameterSpec.h" +#include "beecrypt/c++/provider/DHKeyPairGenerator.h" +#include "beecrypt/c++/provider/DHPublicKeyImpl.h" +#include "beecrypt/c++/provider/DHPrivateKeyImpl.h" +#include "beecrypt/c++/provider/BeeCryptProvider.h" +#include "beecrypt/c++/security/KeyPair.h" + +#include "beecrypt/dldp.h" + +/* precomputed safe primes; it's easy to create generators for these; + * + * using a dldp_p struct, set p from the hex value; set q = p/2 and r = 2 + * then call dldp_pgonGenerator. + */ +namespace { + const char* P_2048 = "fd12e8b7e096a28a00fb548035953cf0eba64ceb5dff0f5672d376d59c196da729f6b5586f18e6f3f1a86c73c5b15662f59439613b309e52aa257488619e5f76a7c4c3f7a426bdeac66bf88343482941413cef06256b39c62744dcb97e7b78e36ec6b885b143f6f3ad0a1cd8a5713e338916613892a264d4a47e72b583fbdaf5bce2bbb0097f7e65cbc86d684882e5bb8196d522dcacd6ad00dfbcd8d21613bdb59c485a65a58325d792272c09ad1173e12c98d865adb4c4d676ada79830c58c37c42dff8536e28f148a23f296513816d3dfed0397a3d4d6e1fa24f07e1b01643a68b4274646a3b876e810206eddacea2b9ef7636a1da5880ef654288b857ea3"; + const char* P_1024 = "e64a3deeddb723e2e4db54c2b09567d196367a86b3b302be07e43ffd7f2e016f866de5135e375bdd2fba6ea9b4299010fafa36dc6b02ba3853cceea07ee94bfe30e0cc82a69c73163be26e0c4012dfa0b2839c97d6cd71eee59a303d6177c6a6740ca63bd04c1ba084d6c369dc2fbfaeebe951d58a4824de52b580442d8cae77"; +}; + +using namespace beecrypt::provider; + +DHKeyPairGenerator::DHKeyPairGenerator() +{ + _size = 0; + _spec = 0; + _srng = 0; +} + +DHKeyPairGenerator::~DHKeyPairGenerator() +{ + _size = 0; + if (_spec) + { + delete _spec; + _spec = 0; + } + _srng = 0; +} + +KeyPair* DHKeyPairGenerator::genpair(randomGeneratorContext* rngc) +{ + dhparam param; + size_t l; + mpnumber x; + mpnumber y; + + if (_spec) + { + param.p = _spec->getP(); + param.g = _spec->getG(); + l = _spec->getL(); + } + else + { + if (_size == 2048) + { + mpbsethex(¶m.p, P_2048); + } + else if (_size == 1024 || _size == 0) + { + mpbsethex(¶m.p, P_1024); + } + + if (_size == 2048 || _size == 1024 || _size == 0) + { + mpnumber q; + + /* set q to half of P */ + mpnset(&q, param.p.size, param.p.modl); + mpdivtwo(q.size, q.data); + mpbset(¶m.q, q.size, q.data); + /* set r to 2 */ + mpnsetw(¶m.r, 2); + + /* make a generator, order n */ + dldp_pgonGenerator(¶m, rngc); + } + else + { + if (dldp_pgonMakeSafe(¶m, rngc, _size)) + throw "unexpected error in dldp_pMakeSafe"; + } + } + + if (_spec && _spec->getL()) + dldp_pPair_s(¶m, rngc, &x, &y, _spec->getL()); + else + dldp_pPair (¶m, rngc, &x, &y); + + KeyPair* result = new KeyPair(new DHPublicKeyImpl(param, y), new DHPrivateKeyImpl(param, x)); + + x.wipe(); + + return result; +} + +KeyPair* DHKeyPairGenerator::engineGenerateKeyPair() +{ + if (_srng) + { + randomGeneratorContextAdapter rngc(_srng); + + return genpair(&rngc); + } + else + { + randomGeneratorContext rngc(randomGeneratorDefault()); + + return genpair(&rngc); + } +} + +void DHKeyPairGenerator::engineInitialize(const AlgorithmParameterSpec& spec, SecureRandom* random) throw (InvalidAlgorithmParameterException) +{ + const DHParameterSpec* dhspec = dynamic_cast(&spec); + + if (dhspec) + { + if (_spec) + delete _spec; + + _spec = new DHParameterSpec(*dhspec); + _srng = random; + } + else + throw InvalidAlgorithmParameterException("not a DHParameterSpec"); +} + +void DHKeyPairGenerator::engineInitialize(size_t keysize, SecureRandom* random) throw (InvalidParameterException) +{ + if (keysize < 768) + throw InvalidParameterException("Safe prime size must be at least 768 bits"); + + _size = keysize; + if (_spec) + { + delete _spec; + _spec = 0; + } + _srng = random; +} diff --git a/beecrypt/c++/provider/DHKeyPairGenerator.h b/beecrypt/c++/provider/DHKeyPairGenerator.h new file mode 100644 index 0000000..a01be64 --- /dev/null +++ b/beecrypt/c++/provider/DHKeyPairGenerator.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file DHKeyPairGenerator.h + * \ingroup CXX_PROV_m + */ + +#ifndef _CLASS_DHKEYPAIRGENERATOR_H +#define _CLASS_DHKEYPAIRGENERATOR_H + +#ifdef __cplusplus + +#include "beecrypt/c++/crypto/spec/DHParameterSpec.h" +using beecrypt::crypto::spec::DHParameterSpec; +#include "beecrypt/c++/security/KeyPairGeneratorSpi.h" +using beecrypt::security::KeyPairGeneratorSpi; + +namespace beecrypt { + namespace provider { + class DHKeyPairGenerator : public KeyPairGeneratorSpi + { + private: + size_t _size; + size_t _l; + DHParameterSpec* _spec; + SecureRandom* _srng; + + KeyPair* genpair(randomGeneratorContext*); + + protected: + virtual KeyPair* engineGenerateKeyPair(); + + virtual void engineInitialize(const AlgorithmParameterSpec&, SecureRandom*) throw (InvalidAlgorithmParameterException); + virtual void engineInitialize(size_t, SecureRandom*) throw (InvalidParameterException); + + public: + DHKeyPairGenerator(); + virtual ~DHKeyPairGenerator(); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/provider/DHParameterGenerator.cxx b/beecrypt/c++/provider/DHParameterGenerator.cxx new file mode 100644 index 0000000..d43aa7e --- /dev/null +++ b/beecrypt/c++/provider/DHParameterGenerator.cxx @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/adapter.h" +using beecrypt::randomGeneratorContextAdapter; +#include "beecrypt/c++/provider/BeeCryptProvider.h" +#include "beecrypt/c++/provider/DHParameterGenerator.h" +#include "beecrypt/c++/security/AlgorithmParameters.h" +using beecrypt::security::AlgorithmParameters; +#include "beecrypt/c++/crypto/spec/DHParameterSpec.h" +using beecrypt::crypto::spec::DHParameterSpec; + +using namespace beecrypt::provider; + +DHParameterGenerator::DHParameterGenerator() +{ + _size = 0; + _spec = 0; + _srng = 0; +} + +DHParameterGenerator::~DHParameterGenerator() +{ + if (_spec) + { + delete _spec; + _spec = 0; + } + _size = 0; + _srng = 0; +} + +AlgorithmParameters* DHParameterGenerator::engineGenerateParameters() +{ + if (!_spec) + { + dldp_p param; + + if (_srng) + { + randomGeneratorContextAdapter rngc(_srng); + if (dldp_pgonMakeSafe(¶m, &rngc, _size)) + throw "unexpected error in dldp_pMake"; + } + else + { + randomGeneratorContext rngc(randomGeneratorDefault()); + if (dldp_pgonMakeSafe(¶m, &rngc, _size)) + throw "unexpected error in dldp_pMake"; + } + + _spec = new DHParameterSpec(param.p, param.g); + } + + try + { + AlgorithmParameters* param = AlgorithmParameters::getInstance("DH"); + + param->init(*_spec); + + return param; + } + catch (Exception* ex) + { + // shouldn't happen + delete ex; + } + + return 0; +} + +void DHParameterGenerator::engineInit(const AlgorithmParameterSpec& spec, SecureRandom* random) throw (InvalidAlgorithmParameterException) +{ + const DHParameterSpec* dhspec = dynamic_cast(&spec); + + if (dhspec) + { + if (_spec) + { + delete _spec; + _spec = 0; + } + + _spec = new DHParameterSpec(*dhspec); + + _srng = random; + } + else + throw InvalidAlgorithmParameterException("expected DHParameterSpec"); +} + +void DHParameterGenerator::engineInit(size_t keysize, SecureRandom* random) throw (InvalidParameterException) +{ + if ((keysize < 768) || ((keysize & 0x3f) != 0)) + throw InvalidParameterException("Prime size must be greater than 768 and be a multiple of 64"); + + _size = keysize; + if (_spec) + { + delete _spec; + _spec = 0; + } + _srng = random; +} diff --git a/beecrypt/c++/provider/DHParameterGenerator.h b/beecrypt/c++/provider/DHParameterGenerator.h new file mode 100644 index 0000000..42c87c1 --- /dev/null +++ b/beecrypt/c++/provider/DHParameterGenerator.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file DHParameterGenerator.h + * \ingroup CXX_PROV_m + */ + +#ifndef _CLASS_DHPARAMETERGENERATOR_H +#define _CLASS_DHPARAMETERGENERATOR_H + +#include "beecrypt/dldp.h" + +#ifdef __cplusplus + +#include "beecrypt/c++/security/AlgorithmParameterGeneratorSpi.h" +using beecrypt::security::AlgorithmParameterGeneratorSpi; +#include "beecrypt/c++/crypto/spec/DHParameterSpec.h" +using beecrypt::crypto::spec::DHParameterSpec; + +namespace beecrypt { + namespace provider { + class DHParameterGenerator : public AlgorithmParameterGeneratorSpi + { + private: + size_t _size; + DHParameterSpec* _spec; + SecureRandom* _srng; + + protected: + virtual AlgorithmParameters* engineGenerateParameters(); + + virtual void engineInit(const AlgorithmParameterSpec&, SecureRandom*) throw (InvalidAlgorithmParameterException); + virtual void engineInit(size_t, SecureRandom*) throw (InvalidParameterException); + + public: + DHParameterGenerator(); + virtual ~DHParameterGenerator(); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/provider/DHParameters.cxx b/beecrypt/c++/provider/DHParameters.cxx new file mode 100644 index 0000000..0b06a8a --- /dev/null +++ b/beecrypt/c++/provider/DHParameters.cxx @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/provider/BeeCryptProvider.h" +#include "beecrypt/c++/provider/DHParameters.h" + +using namespace beecrypt::provider; + +DHParameters::DHParameters() +{ + _spec = 0; +} + +DHParameters::~DHParameters() +{ + if (_spec) + { + delete _spec; + _spec = 0; + } +} + +AlgorithmParameterSpec* DHParameters::engineGetParameterSpec(const type_info& info) throw (InvalidParameterSpecException) +{ + if (info == typeid(AlgorithmParameterSpec) || info == typeid(DHParameterSpec)) + { + if (_spec) + { + return new DHParameterSpec(*_spec); + } + else + throw InvalidParameterSpecException("not initialized"); + } + else + throw InvalidParameterSpecException("expected a DHParameterSpec"); +} + +void DHParameters::engineInit(const AlgorithmParameterSpec& spec) throw (InvalidParameterSpecException) +{ + const DHParameterSpec* tmp = dynamic_cast(&spec); + + if (tmp) + { + if (_spec) + { + delete _spec; + _spec = 0; + } + _spec = new DHParameterSpec(*tmp); + } + else + throw InvalidParameterSpecException("expected a DHParameterSpec"); +} + +void DHParameters::engineInit(const byte*, size_t) +{ + throw "not implemented"; +} + +void DHParameters::engineInit(const byte*, size_t, const String& format) +{ + throw "not implemented"; +} diff --git a/beecrypt/c++/provider/DHParameters.h b/beecrypt/c++/provider/DHParameters.h new file mode 100644 index 0000000..0beb6ba --- /dev/null +++ b/beecrypt/c++/provider/DHParameters.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file DHParameters.h + * \ingroup CXX_PROV_m + */ + +#ifndef _CLASS_DHPARAMETERS_H +#define _CLASS_DHPARAMETERS_H + +#ifdef __cplusplus + +#include "beecrypt/c++/security/AlgorithmParametersSpi.h" +using beecrypt::security::AlgorithmParametersSpi; +#include "beecrypt/c++/crypto/spec/DHParameterSpec.h" +using beecrypt::crypto::spec::DHParameterSpec; + +namespace beecrypt { + namespace provider { + class DHParameters : public AlgorithmParametersSpi + { + private: + DHParameterSpec* _spec; + + protected: + virtual AlgorithmParameterSpec* engineGetParameterSpec(const type_info&) throw (InvalidParameterSpecException); + + virtual void engineInit(const AlgorithmParameterSpec&) throw (InvalidParameterSpecException); + virtual void engineInit(const byte*, size_t); + virtual void engineInit(const byte*, size_t, const String&); + + public: + DHParameters(); + virtual ~DHParameters(); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/provider/DHPrivateKeyImpl.cxx b/beecrypt/c++/provider/DHPrivateKeyImpl.cxx new file mode 100644 index 0000000..7055629 --- /dev/null +++ b/beecrypt/c++/provider/DHPrivateKeyImpl.cxx @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/resource.h" +#include "beecrypt/c++/provider/DHPrivateKeyImpl.h" +#include "beecrypt/c++/provider/BeeKeyFactory.h" + +using namespace beecrypt::provider; + +DHPrivateKeyImpl::DHPrivateKeyImpl(const DHPrivateKey& copy) +{ + _params = new DHParameterSpec(copy.getParams()); + _x = copy.getX(); + _enc = 0; +} + +DHPrivateKeyImpl::DHPrivateKeyImpl(const DHParams& params, const mpnumber& x) +{ + _params = new DHParameterSpec(params.getP(), params.getG(), params.getL()); + _x = x; + _enc = 0; +} + +DHPrivateKeyImpl::DHPrivateKeyImpl(const dhparam& params, const mpnumber& x) +{ + _params = new DHParameterSpec(params.p, params.g); + _x = x; + _enc = 0; +} + +DHPrivateKeyImpl::DHPrivateKeyImpl(const mpbarrett& p, const mpnumber& g, const mpnumber& x) +{ + _params = new DHParameterSpec(p, g); + _x = x; + _enc = 0; +} + +DHPrivateKeyImpl::~DHPrivateKeyImpl() +{ + delete _params; + _x.wipe(); + if (_enc); + delete _enc; +} + +DHPrivateKey* DHPrivateKeyImpl::clone() const +{ + return new DHPrivateKeyImpl(*this); +} + +const DHParams& DHPrivateKeyImpl::getParams() const throw () +{ + return *_params; +} + +const mpnumber& DHPrivateKeyImpl::getX() const throw () +{ + return _x; +} + +const bytearray* DHPrivateKeyImpl::getEncoded() const +{ + if (!_enc) + _enc = BeeKeyFactory::encode(*this); + + return _enc; +} + +const String& DHPrivateKeyImpl::getAlgorithm() const throw () +{ + static const String ALGORITHM = UNICODE_STRING_SIMPLE("DH"); + return ALGORITHM; +} + +const String* DHPrivateKeyImpl::getFormat() const throw () +{ + static const String FORMAT = UNICODE_STRING_SIMPLE("BEE"); + return &FORMAT; +} diff --git a/beecrypt/c++/provider/DHPrivateKeyImpl.h b/beecrypt/c++/provider/DHPrivateKeyImpl.h new file mode 100644 index 0000000..164fb02 --- /dev/null +++ b/beecrypt/c++/provider/DHPrivateKeyImpl.h @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file DHPrivateKeyImpl.h + * \ingroup CXX_PROV_m + */ + +#ifndef _CLASS_DHPRIVATEKEYIMPL_H +#define _CLASS_DHPRIVATEKEYIMPL_H + +#ifdef __cplusplus + +#include "beecrypt/c++/crypto/interfaces/DHPrivateKey.h" +using beecrypt::crypto::interfaces::DHPrivateKey; +#include "beecrypt/c++/crypto/spec/DHParameterSpec.h" +using beecrypt::crypto::spec::DHParameterSpec; + +using beecrypt::bytearray; +using beecrypt::crypto::interfaces::DHParams; +using beecrypt::lang::String; + +namespace beecrypt { + namespace provider { + class DHPrivateKeyImpl : public DHPrivateKey + { + private: + DHParameterSpec* _params; + mpnumber _x; + mutable bytearray* _enc; + + public: + DHPrivateKeyImpl(const DHPrivateKey&); + DHPrivateKeyImpl(const DHParams&, const mpnumber&); + DHPrivateKeyImpl(const dhparam&, const mpnumber&); + DHPrivateKeyImpl(const mpbarrett&, const mpnumber&, const mpnumber&); + virtual ~DHPrivateKeyImpl(); + + virtual DHPrivateKey* clone() const; + + virtual const DHParams& getParams() const throw (); + virtual const mpnumber& getX() const throw (); + + virtual const bytearray* getEncoded() const; + + virtual const String& getAlgorithm() const throw (); + virtual const String* getFormat() const throw (); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/provider/DHPublicKeyImpl.cxx b/beecrypt/c++/provider/DHPublicKeyImpl.cxx new file mode 100644 index 0000000..65689b7 --- /dev/null +++ b/beecrypt/c++/provider/DHPublicKeyImpl.cxx @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/provider/BeeKeyFactory.h" +#include "beecrypt/c++/provider/DHPublicKeyImpl.h" + +using namespace beecrypt::provider; + +DHPublicKeyImpl::DHPublicKeyImpl(const DHPublicKey& copy) +{ + _params = new DHParameterSpec(copy.getParams()); + _y = copy.getY(); + _enc = 0; +} + +DHPublicKeyImpl::DHPublicKeyImpl(const DHParams& params, const mpnumber& y) +{ + _params = new DHParameterSpec(params.getP(), params.getG(), params.getL()); + _y = y; + _enc = 0; +} + +DHPublicKeyImpl::DHPublicKeyImpl(const dhparam& params, const mpnumber& y) +{ + _params = new DHParameterSpec(params.p, params.g); + _y = y; + _enc = 0; +} + +DHPublicKeyImpl::DHPublicKeyImpl(const mpbarrett& p, const mpnumber& g, const mpnumber& y) +{ + _params = new DHParameterSpec(p, g); + _y = y; + _enc = 0; +} + +DHPublicKeyImpl::~DHPublicKeyImpl() +{ + delete _params; + if (_enc) + delete _enc; +} + +DHPublicKey* DHPublicKeyImpl::clone() const +{ + return new DHPublicKeyImpl(*this); +} + +const DHParams& DHPublicKeyImpl::getParams() const throw () +{ + return *_params; +} + +const mpnumber& DHPublicKeyImpl::getY() const throw () +{ + return _y; +} + +const bytearray* DHPublicKeyImpl::getEncoded() const +{ + if (!_enc) + _enc = BeeKeyFactory::encode(*this); + + return _enc; +} + +const String& DHPublicKeyImpl::getAlgorithm() const throw () +{ + static const String ALGORITHM = UNICODE_STRING_SIMPLE("DH"); + return ALGORITHM; +} + +const String* DHPublicKeyImpl::getFormat() const throw () +{ + static const String FORMAT = UNICODE_STRING_SIMPLE("BEE"); + return &FORMAT; +} diff --git a/beecrypt/c++/provider/DHPublicKeyImpl.h b/beecrypt/c++/provider/DHPublicKeyImpl.h new file mode 100644 index 0000000..a1d3be5 --- /dev/null +++ b/beecrypt/c++/provider/DHPublicKeyImpl.h @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file DHPublicKeyImpl.h + * \ingroup CXX_PROV_m + */ + +#ifndef _CLASS_DHPUBLICKEYIMPL_H +#define _CLASS_DHPUBLICKEYIMPL_H + +#ifdef __cplusplus + +#include "beecrypt/c++/crypto/interfaces/DHPublicKey.h" +using beecrypt::crypto::interfaces::DHPublicKey; +#include "beecrypt/c++/crypto/spec/DHParameterSpec.h" +using beecrypt::crypto::spec::DHParameterSpec; + +using beecrypt::bytearray; +using beecrypt::crypto::interfaces::DHParams; +using beecrypt::lang::String; + +namespace beecrypt { + namespace provider { + class DHPublicKeyImpl : public DHPublicKey + { + private: + DHParameterSpec* _params; + mpnumber _y; + mutable bytearray* _enc; + + public: + DHPublicKeyImpl(const DHPublicKey&); + DHPublicKeyImpl(const DHParams&, const mpnumber&); + DHPublicKeyImpl(const dhparam&, const mpnumber&); + DHPublicKeyImpl(const mpbarrett&, const mpnumber&, const mpnumber&); + ~DHPublicKeyImpl(); + + virtual DHPublicKey* clone() const; + + virtual const DHParams& getParams() const throw (); + virtual const mpnumber& getY() const throw (); + + virtual const bytearray* getEncoded() const; + + virtual const String& getAlgorithm() const throw (); + virtual const String* getFormat() const throw (); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/provider/DSAKeyFactory.cxx b/beecrypt/c++/provider/DSAKeyFactory.cxx new file mode 100644 index 0000000..249368f --- /dev/null +++ b/beecrypt/c++/provider/DSAKeyFactory.cxx @@ -0,0 +1,171 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/provider/DSAKeyFactory.h" +#include "beecrypt/c++/provider/DSAPrivateKeyImpl.h" +#include "beecrypt/c++/provider/DSAPublicKeyImpl.h" +#include "beecrypt/c++/security/KeyFactory.h" +using beecrypt::security::KeyFactory; +#include "beecrypt/c++/security/spec/DSAPrivateKeySpec.h" +using beecrypt::security::spec::DSAPrivateKeySpec; +#include "beecrypt/c++/security/spec/DSAPublicKeySpec.h" +using beecrypt::security::spec::DSAPublicKeySpec; +#include "beecrypt/c++/security/spec/EncodedKeySpec.h" +using beecrypt::security::spec::EncodedKeySpec; + +using namespace beecrypt::provider; + +DSAKeyFactory::DSAKeyFactory() +{ +} + +DSAKeyFactory::~DSAKeyFactory() +{ +} + +PrivateKey* DSAKeyFactory::engineGeneratePrivate(const KeySpec& spec) throw (InvalidKeySpecException) +{ + const DSAPrivateKeySpec* dsa = dynamic_cast(&spec); + if (dsa) + { + return new DSAPrivateKeyImpl(dsa->getP(), dsa->getQ(), dsa->getG(), dsa->getX()); + } + + const EncodedKeySpec* enc = dynamic_cast(&spec); + if (enc) + { + try + { + KeyFactory* kf = KeyFactory::getInstance(enc->getFormat()); + try + { + PrivateKey* pri = kf->generatePrivate(*enc); + delete kf; + return pri; + } + catch (...) + { + delete kf; + throw; + } + } + catch (NoSuchAlgorithmException) + { + throw InvalidKeySpecException("Unsupported KeySpec encoding format"); + } + } + throw InvalidKeySpecException("Unsupported KeySpec type"); +} + +PublicKey* DSAKeyFactory::engineGeneratePublic(const KeySpec& spec) throw (InvalidKeySpecException) +{ + const DSAPublicKeySpec* dsa = dynamic_cast(&spec); + if (dsa) + { + return new DSAPublicKeyImpl(dsa->getP(), dsa->getQ(), dsa->getG(), dsa->getY()); + } + + const EncodedKeySpec* enc = dynamic_cast(&spec); + if (enc) + { + try + { + KeyFactory* kf = KeyFactory::getInstance(enc->getFormat()); + try + { + PublicKey* pub = kf->generatePublic(*enc); + delete kf; + return pub; + } + catch (...) + { + delete kf; + throw; + } + } + catch (NoSuchAlgorithmException) + { + throw InvalidKeySpecException("Unsupported KeySpec encoding format"); + } + } + throw InvalidKeySpecException("Unsupported KeySpec type"); +} + +KeySpec* DSAKeyFactory::engineGetKeySpec(const Key& key, const type_info& info) throw (InvalidKeySpecException) +{ + const DSAPublicKey* pub = dynamic_cast(&key); + + if (pub) + { + if (info == typeid(KeySpec) || info == typeid(DSAPublicKeySpec)) + { + const DSAParams& params = pub->getParams(); + + return new DSAPublicKeySpec(params.getP(), params.getQ(), params.getG(), pub->getY()); + } + /*!\todo also support EncodeKeySpec + */ + /* + if (info == typeid(EncodedKeySpec)) + { + } + */ + + throw InvalidKeySpecException("Unsupported KeySpec type"); + } + + const DSAPrivateKey* pri = dynamic_cast(&key); + + if (pri) + { + if (info == typeid(KeySpec) || info == typeid(DSAPrivateKeySpec)) + { + const DSAParams& params = pri->getParams(); + + return new DSAPrivateKeySpec(params.getP(), params.getQ(), params.getG(), pri->getX()); + } + /*!\todo also support EncodeKeySpec + */ + /* + if (info == typeid(EncodedKeySpec)) + { + } + */ + + throw InvalidKeySpecException("Unsupported KeySpec type"); + } + + throw InvalidKeySpecException("Unsupported Key type"); +} + +Key* DSAKeyFactory::engineTranslateKey(const Key& key) throw (InvalidKeyException) +{ + const DSAPublicKey* pub = dynamic_cast(&key); + if (pub) + return new DSAPublicKeyImpl(*pub); + + const DSAPrivateKey* pri = dynamic_cast(&key); + if (pri) + return new DSAPrivateKeyImpl(*pri); + + throw InvalidKeyException("Unsupported Key type"); +} diff --git a/beecrypt/c++/provider/DSAKeyFactory.h b/beecrypt/c++/provider/DSAKeyFactory.h new file mode 100644 index 0000000..b9c360b --- /dev/null +++ b/beecrypt/c++/provider/DSAKeyFactory.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file DSAKeyFactory.h + * \ingroup CXX_PROV_m + */ + +#ifndef _CLASS_DSAKEYFACTORY_H +#define _CLASS_DSAKEYFACTORY_H + +#ifdef __cplusplus + +#include "beecrypt/c++/security/KeyFactorySpi.h" +using beecrypt::security::InvalidKeyException; +using beecrypt::security::Key; +using beecrypt::security::KeyFactorySpi; +using beecrypt::security::PrivateKey; +using beecrypt::security::PublicKey; +using beecrypt::security::spec::InvalidKeySpecException; +using beecrypt::security::spec::KeySpec; + +namespace beecrypt { + namespace provider { + class DSAKeyFactory : public KeyFactorySpi + { + protected: + virtual PrivateKey* engineGeneratePrivate(const KeySpec&) throw (InvalidKeySpecException); + virtual PublicKey* engineGeneratePublic(const KeySpec&) throw (InvalidKeySpecException); + + virtual KeySpec* engineGetKeySpec(const Key&, const type_info&) throw (InvalidKeySpecException); + + virtual Key* engineTranslateKey(const Key&) throw (InvalidKeyException); + + public: + DSAKeyFactory(); + virtual ~DSAKeyFactory(); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/provider/DSAKeyPairGenerator.cxx b/beecrypt/c++/provider/DSAKeyPairGenerator.cxx new file mode 100644 index 0000000..139c83f --- /dev/null +++ b/beecrypt/c++/provider/DSAKeyPairGenerator.cxx @@ -0,0 +1,161 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/adapter.h" +using beecrypt::randomGeneratorContextAdapter; +#include "beecrypt/c++/provider/BeeCryptProvider.h" +#include "beecrypt/c++/provider/DSAKeyPairGenerator.h" +#include "beecrypt/c++/provider/DSAPublicKeyImpl.h" +#include "beecrypt/c++/provider/DSAPrivateKeyImpl.h" +#include "beecrypt/c++/security/KeyPair.h" +using beecrypt::security::KeyPair; +#include "beecrypt/c++/security/spec/DSAParameterSpec.h" +using beecrypt::security::spec::DSAParameterSpec; + +namespace { + const char* P_512 = "fca682ce8e12caba26efccf7110e526db078b05edecbcd1eb4a208f3ae1617ae01f35b91a47e6df63413c5e12ed0899bcd132acd50d99151bdc43ee737592e17"; + const char* Q_512 = "962eddcc369cba8ebb260ee6b6a126d9346e38c5"; + const char* G_512 = "678471b27a9cf44ee91a49c5147db1a9aaf244f05a434d6486931d2d14271b9e35030b71fd73da179069b32e2935630e1c2062354d0da20a6c416e50be794ca4"; + + const char* P_768 = "e9e642599d355f37c97ffd3567120b8e25c9cd43e927b3a9670fbec5d890141922d2c3b3ad2480093799869d1e846aab49fab0ad26d2ce6a22219d470bce7d777d4a21fbe9c270b57f607002f3cef8393694cf45ee3688c11a8c56ab127a3daf"; + const char* Q_768 = "9cdbd84c9f1ac2f38d0f80f42ab952e7338bf511"; + const char* G_768 = "30470ad5a005fb14ce2d9dcd87e38bc7d1b1c5facbaecbe95f190aa7a31d23c4dbbcbe06174544401a5b2c020965d8c2bd2171d3668445771f74ba084d2029d83c1c158547f3a9f1a2715be23d51ae4d3e5a1f6a7064f316933a346d3f529252"; + + const char* P_1024 = "fd7f53811d75122952df4a9c2eece4e7f611b7523cef4400c31e3f80b6512669455d402251fb593d8d58fabfc5f5ba30f6cb9b556cd7813b801d346ff26660b76b9950a5a49f9fe8047b1022c24fbba9d7feb7c61bf83b57e7c6a8a6150f04fb83f6d3c51ec3023554135a169132f675f3ae2b61d72aeff22203199dd14801c7"; + const char* Q_1024 = "9760508f15230bccb292b982a2eb840bf0581cf5"; + const char* G_1024 = "f7e1a085d69b3ddecbbcab5c36b857b97994afbbfa3aea82f9574c0b3d0782675159578ebad4594fe67107108180b449167123e84c281613b7cf09328cc8a6e13c167a8b547c8d28e0a3ae1e2bb3a675916ea37f0bfa213562f1fb627a01243bcca4f1bea8519089a883dfe15ae59f06928b665e807b552564014c3bfecf492a"; +}; + +using namespace beecrypt::provider; + +DSAKeyPairGenerator::DSAKeyPairGenerator() +{ + _size = 0; + _spec = 0; + _srng = 0; +} + +DSAKeyPairGenerator::~DSAKeyPairGenerator() +{ + _size = 0; + if (_spec) + { + delete _spec; + _spec = 0; + } + _srng = 0; +} + +KeyPair* DSAKeyPairGenerator::genpair(randomGeneratorContext* rngc) +{ + dsaparam param; + mpnumber x; + mpnumber y; + + if (_spec) + { + param.p = _spec->getP(); + param.q = _spec->getQ(); + param.g = _spec->getG(); + } + else + { + if (_size == 512) + { + mpbsethex(¶m.p, P_512); + mpbsethex(¶m.q, Q_512); + mpnsethex(¶m.g, G_512); + } + else if (_size == 768) + { + mpbsethex(¶m.p, P_768); + mpbsethex(¶m.q, Q_768); + mpnsethex(¶m.g, G_768); + } + else if ((_size == 1024) || !_size) + { + mpbsethex(¶m.p, P_1024); + mpbsethex(¶m.q, Q_1024); + mpnsethex(¶m.g, G_1024); + } + else + { + if (dsaparamMake(¶m, rngc, _size)) + throw "unexpected error in dsaparamMake"; + } + } + + if (dldp_pPair(¶m, rngc, &x, &y)) + throw "unexpected error in dldp_pPair"; + + KeyPair* result = new KeyPair(new DSAPublicKeyImpl(param, y), new DSAPrivateKeyImpl(param, x)); + + x.wipe(); + + return result; +} + +KeyPair* DSAKeyPairGenerator::engineGenerateKeyPair() +{ + if (_srng) + { + randomGeneratorContextAdapter rngc(_srng); + + return genpair(&rngc); + } + else + { + randomGeneratorContext rngc(randomGeneratorDefault()); + + return genpair(&rngc); + } +} + +void DSAKeyPairGenerator::engineInitialize(const AlgorithmParameterSpec& spec, SecureRandom* random) throw (InvalidAlgorithmParameterException) +{ + const DSAParameterSpec* dsaspec = dynamic_cast(&spec); + + if (dsaspec) + { + if (_spec) + delete _spec; + + _spec = new DSAParameterSpec(*dsaspec); + _srng = random; + } + else + throw InvalidAlgorithmParameterException("not a DSAParameterSpec"); +} + +void DSAKeyPairGenerator::engineInitialize(size_t keysize, SecureRandom* random) throw (InvalidParameterException) +{ + if ((keysize < 512) || (keysize > 1024) || ((keysize & 0x3f) != 0)) + throw InvalidParameterException("Prime size must range from 512 to 1024 bits and be a multiple of 64"); + + _size = keysize; + if (_spec) + { + delete _spec; + _spec = 0; + } + _srng = random; +} diff --git a/beecrypt/c++/provider/DSAKeyPairGenerator.h b/beecrypt/c++/provider/DSAKeyPairGenerator.h new file mode 100644 index 0000000..a9f8346 --- /dev/null +++ b/beecrypt/c++/provider/DSAKeyPairGenerator.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file DSAKeyPairGenerator.h + * \ingroup CXX_PROV_m + */ + +#ifndef _CLASS_DSAKEYPAIRGENERATOR_H +#define _CLASS_DSAKEYPAIRGENERATOR_H + +#ifdef __cplusplus + +#include "beecrypt/c++/security/KeyPairGeneratorSpi.h" +using beecrypt::security::KeyPairGeneratorSpi; +#include "beecrypt/c++/security/SecureRandom.h" +using beecrypt::security::SecureRandom; +#include "beecrypt/c++/security/spec/DSAParameterSpec.h" +using beecrypt::security::spec::DSAParameterSpec; + +namespace beecrypt { + namespace provider { + class DSAKeyPairGenerator : public KeyPairGeneratorSpi + { + private: + size_t _size; + DSAParameterSpec* _spec; + SecureRandom* _srng; + + KeyPair* genpair(randomGeneratorContext*); + + protected: + virtual KeyPair* engineGenerateKeyPair(); + + virtual void engineInitialize(const AlgorithmParameterSpec&, SecureRandom*) throw (InvalidAlgorithmParameterException); + virtual void engineInitialize(size_t, SecureRandom*) throw (InvalidParameterException); + + public: + DSAKeyPairGenerator(); + virtual ~DSAKeyPairGenerator(); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/provider/DSAParameterGenerator.cxx b/beecrypt/c++/provider/DSAParameterGenerator.cxx new file mode 100644 index 0000000..7acb2f0 --- /dev/null +++ b/beecrypt/c++/provider/DSAParameterGenerator.cxx @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/adapter.h" +using beecrypt::randomGeneratorContextAdapter; +#include "beecrypt/c++/provider/BeeCryptProvider.h" +#include "beecrypt/c++/provider/DSAParameterGenerator.h" +#include "beecrypt/c++/security/AlgorithmParameters.h" +using beecrypt::security::AlgorithmParameters; +#include "beecrypt/c++/security/spec/DSAParameterSpec.h" +using beecrypt::security::spec::DSAParameterSpec; + +using namespace beecrypt::provider; + +DSAParameterGenerator::DSAParameterGenerator() +{ + _size = 0; + _spec = 0; + _srng = 0; +} + +DSAParameterGenerator::~DSAParameterGenerator() +{ + if (_spec) + { + delete _spec; + _spec = 0; + } + _size = 0; + _srng = 0; +} + +AlgorithmParameters* DSAParameterGenerator::engineGenerateParameters() +{ + if (!_spec) + { + dsaparam param; + + if (_srng) + { + randomGeneratorContextAdapter rngc(_srng); + if (dsaparamMake(¶m, &rngc, _size)) + throw "unexpected error in dsaparamMake"; + } + else + { + randomGeneratorContext rngc(randomGeneratorDefault()); + if (dsaparamMake(¶m, &rngc, _size)) + throw "unexpected error in dsaparamMake"; + } + + _spec = new DSAParameterSpec(param.p, param.q, param.g); + } + + try + { + AlgorithmParameters* param = AlgorithmParameters::getInstance("DSA"); + + param->init(*_spec); + + return param; + } + catch (Exception* ex) + { + // shouldn't happen + delete ex; + } + + return 0; +} + +void DSAParameterGenerator::engineInit(const AlgorithmParameterSpec& spec, SecureRandom* random) throw (InvalidAlgorithmParameterException) +{ + const DSAParameterSpec* dsaspec = dynamic_cast(&spec); + + if (dsaspec) + { + if (_spec) + { + delete _spec; + _spec = 0; + } + + _spec = new DSAParameterSpec(*dsaspec); + + _srng = random; + } + else + throw InvalidAlgorithmParameterException("expected DSAParameterSpec"); +} + +void DSAParameterGenerator::engineInit(size_t keysize, SecureRandom* random) throw (InvalidParameterException) +{ + if ((keysize < 512) || (keysize > 1024) || ((keysize & 0x3f) != 0)) + throw InvalidParameterException("Prime size must range from 512 to 1024 bits and be a multiple of 64"); + + _size = keysize; + if (_spec) + { + delete _spec; + _spec = 0; + } + _srng = random; +} diff --git a/beecrypt/c++/provider/DSAParameterGenerator.h b/beecrypt/c++/provider/DSAParameterGenerator.h new file mode 100644 index 0000000..2cbdfee --- /dev/null +++ b/beecrypt/c++/provider/DSAParameterGenerator.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file DSAParameterGenerator.h + * \ingroup CXX_PROV_m + */ + +#ifndef _CLASS_DSAPARAMETERGENERATOR_H +#define _CLASS_DSAPARAMETERGENERATOR_H + +#ifdef __cplusplus + +#include "beecrypt/c++/security/AlgorithmParameterGeneratorSpi.h" +using beecrypt::security::AlgorithmParameterGeneratorSpi; +#include "beecrypt/c++/security/spec/DSAParameterSpec.h" +using beecrypt::security::spec::DSAParameterSpec; + +namespace beecrypt { + namespace provider { + class DSAParameterGenerator : public AlgorithmParameterGeneratorSpi + { + private: + size_t _size; + DSAParameterSpec* _spec; + SecureRandom* _srng; + + protected: + virtual AlgorithmParameters* engineGenerateParameters(); + + virtual void engineInit(const AlgorithmParameterSpec&, SecureRandom*) throw (InvalidAlgorithmParameterException); + virtual void engineInit(size_t, SecureRandom*) throw (InvalidParameterException); + + public: + DSAParameterGenerator(); + virtual ~DSAParameterGenerator(); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/provider/DSAParameters.cxx b/beecrypt/c++/provider/DSAParameters.cxx new file mode 100644 index 0000000..f5cc996 --- /dev/null +++ b/beecrypt/c++/provider/DSAParameters.cxx @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/provider/BeeCryptProvider.h" +#include "beecrypt/c++/provider/DSAParameters.h" + +using namespace beecrypt::provider; + +DSAParameters::DSAParameters() +{ + _spec = 0; +} + +DSAParameters::~DSAParameters() +{ + if (_spec) + { + delete _spec; + _spec = 0; + } +} + +AlgorithmParameterSpec* DSAParameters::engineGetParameterSpec(const type_info& info) throw (InvalidParameterSpecException) +{ + if (info == typeid(AlgorithmParameterSpec) || info == typeid(DSAParameterSpec)) + { + if (_spec) + { + return new DSAParameterSpec(*_spec); + } + else + throw InvalidParameterSpecException("not initialized"); + } + else + throw InvalidParameterSpecException("expected a DSAParameterSpec"); +} + +void DSAParameters::engineInit(const AlgorithmParameterSpec& spec) throw (InvalidParameterSpecException) +{ + const DSAParameterSpec* tmp = dynamic_cast(&spec); + + if (tmp) + { + if (_spec) + { + delete _spec; + _spec = 0; + } + _spec = new DSAParameterSpec(*tmp); + } + else + throw InvalidParameterSpecException("expected a DSAParameterSpec"); +} + +void DSAParameters::engineInit(const byte*, size_t) +{ + throw "not implemented"; +} + +void DSAParameters::engineInit(const byte*, size_t, const String& format) +{ + throw "not implemented"; +} diff --git a/beecrypt/c++/provider/DSAParameters.h b/beecrypt/c++/provider/DSAParameters.h new file mode 100644 index 0000000..ed12ef2 --- /dev/null +++ b/beecrypt/c++/provider/DSAParameters.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file DSAParameters.h + * \ingroup CXX_PROV_m + */ + +#ifndef _CLASS_DSAPARAMETERS_H +#define _CLASS_DSAPARAMETERS_H + +#ifdef __cplusplus + +#include "beecrypt/c++/security/AlgorithmParametersSpi.h" +using beecrypt::security::AlgorithmParametersSpi; +#include "beecrypt/c++/security/spec/DSAParameterSpec.h" +using beecrypt::security::spec::DSAParameterSpec; + +namespace beecrypt { + namespace provider { + class DSAParameters : public AlgorithmParametersSpi + { + // friend class DSAParameterGenerator; + + private: + DSAParameterSpec* _spec; + + protected: + virtual AlgorithmParameterSpec* engineGetParameterSpec(const type_info&) throw (InvalidParameterSpecException); + + virtual void engineInit(const AlgorithmParameterSpec&) throw (InvalidParameterSpecException); + virtual void engineInit(const byte*, size_t); + virtual void engineInit(const byte*, size_t, const String&); + + public: + DSAParameters(); + virtual ~DSAParameters(); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/provider/DSAPrivateKeyImpl.cxx b/beecrypt/c++/provider/DSAPrivateKeyImpl.cxx new file mode 100644 index 0000000..1389eff --- /dev/null +++ b/beecrypt/c++/provider/DSAPrivateKeyImpl.cxx @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/resource.h" +#include "beecrypt/c++/provider/DSAPrivateKeyImpl.h" +#include "beecrypt/c++/provider/BeeKeyFactory.h" + +using namespace beecrypt::provider; + +DSAPrivateKeyImpl::DSAPrivateKeyImpl(const DSAPrivateKey& copy) +{ + _params = new DSAParameterSpec(copy.getParams()); + _x = copy.getX(); + _enc = 0; +} + +DSAPrivateKeyImpl::DSAPrivateKeyImpl(const DSAParams& params, const mpnumber& x) +{ + _params = new DSAParameterSpec(params.getP(), params.getQ(), params.getG()); + _x = x; + _enc = 0; +} + +DSAPrivateKeyImpl::DSAPrivateKeyImpl(const dsaparam& params, const mpnumber& x) +{ + _params = new DSAParameterSpec(params.p, params.q, params.g); + _x = x; + _enc = 0; +} + +DSAPrivateKeyImpl::DSAPrivateKeyImpl(const mpbarrett& p, const mpbarrett& q, const mpnumber& g, const mpnumber& x) +{ + _params = new DSAParameterSpec(p, q, g); + _x = x; + _enc = 0; +} + +DSAPrivateKeyImpl::~DSAPrivateKeyImpl() +{ + delete _params; + _x.wipe(); + if (_enc) + delete _enc; +} + +DSAPrivateKey* DSAPrivateKeyImpl::clone() const +{ + return new DSAPrivateKeyImpl(*this); +} + +const DSAParams& DSAPrivateKeyImpl::getParams() const throw () +{ + return *_params; +} + +const mpnumber& DSAPrivateKeyImpl::getX() const throw () +{ + return _x; +} + +const bytearray* DSAPrivateKeyImpl::getEncoded() const +{ + if (!_enc) + _enc = BeeKeyFactory::encode(*this); + + return _enc; +} + +const String& DSAPrivateKeyImpl::getAlgorithm() const throw () +{ + static const String ALGORITHM = UNICODE_STRING_SIMPLE("DSA"); + return ALGORITHM; +} + +const String* DSAPrivateKeyImpl::getFormat() const throw () +{ + static const String FORMAT = UNICODE_STRING_SIMPLE("BEE"); + return &FORMAT; +} diff --git a/beecrypt/c++/provider/DSAPrivateKeyImpl.h b/beecrypt/c++/provider/DSAPrivateKeyImpl.h new file mode 100644 index 0000000..3d14a05 --- /dev/null +++ b/beecrypt/c++/provider/DSAPrivateKeyImpl.h @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file DSAPrivateKeyImpl.h + * \ingroup CXX_PROV_m + */ + +#ifndef _CLASS_DSAPRIVATEKEYIMPL_H +#define _CLASS_DSAPRIVATEKEYIMPL_H + +#ifdef __cplusplus + +#include "beecrypt/c++/security/interfaces/DSAPrivateKey.h" +using beecrypt::security::interfaces::DSAPrivateKey; +#include "beecrypt/c++/security/spec/DSAParameterSpec.h" +using beecrypt::security::spec::DSAParameterSpec; + +namespace beecrypt { + namespace provider { + class DSAPrivateKeyImpl : public DSAPrivateKey + { + private: + DSAParameterSpec* _params; + mpnumber _x; + mutable bytearray* _enc; + + public: + DSAPrivateKeyImpl(const DSAPrivateKey&); + DSAPrivateKeyImpl(const DSAParams&, const mpnumber&); + DSAPrivateKeyImpl(const dsaparam&, const mpnumber&); + DSAPrivateKeyImpl(const mpbarrett&, const mpbarrett&, const mpnumber&, const mpnumber&); + + virtual ~DSAPrivateKeyImpl(); + + virtual DSAPrivateKey* clone() const; + + virtual const DSAParams& getParams() const throw (); + virtual const mpnumber& getX() const throw (); + + virtual const bytearray* getEncoded() const; + virtual const String& getAlgorithm() const throw (); + virtual const String* getFormat() const throw (); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/provider/DSAPublicKeyImpl.cxx b/beecrypt/c++/provider/DSAPublicKeyImpl.cxx new file mode 100644 index 0000000..29c8a71 --- /dev/null +++ b/beecrypt/c++/provider/DSAPublicKeyImpl.cxx @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/resource.h" +#include "beecrypt/c++/provider/DSAPublicKeyImpl.h" +#include "beecrypt/c++/provider/BeeKeyFactory.h" + +using namespace beecrypt::provider; + +DSAPublicKeyImpl::DSAPublicKeyImpl(const DSAPublicKey& copy) +{ + _params = new DSAParameterSpec(copy.getParams()); + _y = copy.getY(); + _enc = 0; +} + +DSAPublicKeyImpl::DSAPublicKeyImpl(const DSAParams& params, const mpnumber& y) +{ + _params = new DSAParameterSpec(params.getP(), params.getQ(), params.getG()); + _y = y; + _enc = 0; +} + +DSAPublicKeyImpl::DSAPublicKeyImpl(const dsaparam& params, const mpnumber& y) +{ + _params = new DSAParameterSpec(params.p, params.q, params.g); + _y = y; + _enc = 0; +} + +DSAPublicKeyImpl::DSAPublicKeyImpl(const mpbarrett& p, const mpbarrett& q, const mpnumber& g, const mpnumber& y) +{ + _params = new DSAParameterSpec(p, q, g); + _y = y; + _enc = 0; +} + +DSAPublicKeyImpl::~DSAPublicKeyImpl() +{ + delete _params; + if (_enc) + delete _enc; +} + +DSAPublicKey* DSAPublicKeyImpl::clone() const +{ + return new DSAPublicKeyImpl(*this); +} + +const DSAParams& DSAPublicKeyImpl::getParams() const throw () +{ + return *_params; +} + +const mpnumber& DSAPublicKeyImpl::getY() const throw () +{ + return _y; +} + +const bytearray* DSAPublicKeyImpl::getEncoded() const +{ + if (!_enc) + _enc = BeeKeyFactory::encode(*this); + + return _enc; +} + +const String& DSAPublicKeyImpl::getAlgorithm() const throw () +{ + static const String ALGORITHM = UNICODE_STRING_SIMPLE("DSA"); + return ALGORITHM; +} + +const String* DSAPublicKeyImpl::getFormat() const throw () +{ + static const String FORMAT = UNICODE_STRING_SIMPLE("BEE"); + return &FORMAT; +} diff --git a/beecrypt/c++/provider/DSAPublicKeyImpl.h b/beecrypt/c++/provider/DSAPublicKeyImpl.h new file mode 100644 index 0000000..85c5320 --- /dev/null +++ b/beecrypt/c++/provider/DSAPublicKeyImpl.h @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file DSAPublicKeyImpl.h + * \ingroup CXX_PROV_m + */ + +#ifndef _CLASS_DSAPUBLICKEYIMPL_H +#define _CLASS_DSAPUBLICKEYIMPL_H + +#ifdef __cplusplus + +#include "beecrypt/c++/security/interfaces/DSAPublicKey.h" +using beecrypt::security::interfaces::DSAPublicKey; +#include "beecrypt/c++/security/spec/DSAParameterSpec.h" +using beecrypt::security::spec::DSAParameterSpec; + +namespace beecrypt { + namespace provider { + class DSAPublicKeyImpl : public DSAPublicKey + { + private: + DSAParameterSpec* _params; + mpnumber _y; + mutable bytearray* _enc; + + public: + DSAPublicKeyImpl(const DSAPublicKey&); + DSAPublicKeyImpl(const DSAParams&, const mpnumber&); + DSAPublicKeyImpl(const dsaparam&, const mpnumber&); + DSAPublicKeyImpl(const mpbarrett&, const mpbarrett&, const mpnumber&, const mpnumber&); + virtual ~DSAPublicKeyImpl(); + + virtual DSAPublicKey* clone() const; + + virtual const DSAParams& getParams() const throw (); + virtual const mpnumber& getY() const throw (); + + virtual const bytearray* getEncoded() const; + virtual const String& getAlgorithm() const throw (); + virtual const String* getFormat() const throw (); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/provider/HMACMD5.cxx b/beecrypt/c++/provider/HMACMD5.cxx new file mode 100644 index 0000000..93c1bc7 --- /dev/null +++ b/beecrypt/c++/provider/HMACMD5.cxx @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/pkcs12.h" + +#include "beecrypt/c++/crypto/interfaces/PBEKey.h" +using beecrypt::crypto::interfaces::PBEKey; +#include "beecrypt/c++/lang/NullPointerException.h" +using beecrypt::lang::NullPointerException; +#include "beecrypt/c++/provider/HMACMD5.h" + +using namespace beecrypt::provider; + +HMACMD5::HMACMD5() : _digest(16) +{ +} + +HMACMD5::~HMACMD5() +{ +} + +HMACMD5* HMACMD5::clone() const +{ + HMACMD5* result = new HMACMD5(); + + memcpy(&result->_param, &_param, sizeof(hmacmd5Param)); + + return result; +} + +const bytearray& HMACMD5::engineDoFinal() +{ + hmacmd5Digest(&_param, _digest.data()); + + return _digest; +} + +size_t HMACMD5::engineDoFinal(byte* data, size_t offset, size_t length) throw (ShortBufferException) +{ + if (!data) + throw NullPointerException(); + + if (length < 16) + throw ShortBufferException(); + + hmacmd5Digest(&_param, data); + + return 16; +} + +size_t HMACMD5::engineGetMacLength() +{ + return 16; +} + +void HMACMD5::engineReset() +{ + hmacmd5Reset(&_param); +} + +void HMACMD5::engineUpdate(byte b) +{ + hmacmd5Update(&_param, &b, 1); +} + +void HMACMD5::engineUpdate(const byte* data, size_t offset, size_t length) +{ + hmacmd5Update(&_param, data+offset, length); +} + +void HMACMD5::engineInit(const Key& key, const AlgorithmParameterSpec* spec) throw (InvalidKeyException, InvalidAlgorithmParameterException) +{ + if (spec) + throw InvalidAlgorithmParameterException("No AlgorithmParameterSpec supported"); + + const PBEKey* pbe = dynamic_cast(&key); + if (pbe) + { + byte _mac_key[16]; + bytearray _rawk, _salt; + size_t _iter; + + if (pbe->getEncoded()) + _rawk = *(pbe->getEncoded()); + else + throw InvalidKeyException("PBEKey must have an encoding"); + + if (pbe->getSalt()) + _salt = *(pbe->getSalt()); + + _iter = pbe->getIterationCount(); + + if (pkcs12_derive_key(&md5, PKCS12_ID_MAC, _rawk.data(), _rawk.size(), _salt.data(), _salt.size(), _iter, _mac_key, 16)) + throw InvalidKeyException("pkcs12_derive_key returned error"); + + hmacmd5Setup(&_param, _mac_key, 128); + + return; + } + + throw InvalidKeyException("Expected a PBEKey"); +} diff --git a/beecrypt/c++/provider/HMACMD5.h b/beecrypt/c++/provider/HMACMD5.h new file mode 100644 index 0000000..586688c --- /dev/null +++ b/beecrypt/c++/provider/HMACMD5.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file HMACMD5.h + * \ingroup CXX_PROV_m + */ + +#ifndef _CLASS_HMACMD5_H +#define _CLASS_HMACMD5_H + +#include "beecrypt/beecrypt.h" +#include "beecrypt/hmacmd5.h" + +#ifdef __cplusplus + +#include "beecrypt/c++/crypto/MacSpi.h" +using beecrypt::crypto::MacSpi; + +namespace beecrypt { + namespace provider { + class HMACMD5 : public MacSpi + { + private: + hmacmd5Param _param; + bytearray _digest; + + protected: + virtual const bytearray& engineDoFinal(); + virtual size_t engineDoFinal(byte*, size_t, size_t) throw (ShortBufferException); + virtual size_t engineGetMacLength(); + virtual void engineInit(const Key&, const AlgorithmParameterSpec* spec) throw (InvalidKeyException, InvalidAlgorithmParameterException); + virtual void engineReset(); + virtual void engineUpdate(byte); + virtual void engineUpdate(const byte*, size_t, size_t); + + public: + HMACMD5(); + virtual ~HMACMD5(); + + virtual HMACMD5* clone() const; + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/provider/HMACSHA1.cxx b/beecrypt/c++/provider/HMACSHA1.cxx new file mode 100644 index 0000000..af59b93 --- /dev/null +++ b/beecrypt/c++/provider/HMACSHA1.cxx @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/pkcs12.h" + +#include "beecrypt/c++/crypto/interfaces/PBEKey.h" +using beecrypt::crypto::interfaces::PBEKey; +#include "beecrypt/c++/lang/NullPointerException.h" +using beecrypt::lang::NullPointerException; +#include "beecrypt/c++/provider/HMACSHA1.h" + +using namespace beecrypt::provider; + +HMACSHA1::HMACSHA1() : _digest(20) +{ +} + +HMACSHA1::~HMACSHA1() +{ +} + +HMACSHA1* HMACSHA1::clone() const +{ + HMACSHA1* result = new HMACSHA1(); + + memcpy(&result->_param, &_param, sizeof(hmacsha1Param)); + + return result; +} + +const bytearray& HMACSHA1::engineDoFinal() +{ + hmacsha1Digest(&_param, _digest.data()); + + return _digest; +} + +size_t HMACSHA1::engineDoFinal(byte* data, size_t offset, size_t length) throw (ShortBufferException) +{ + if (!data) + throw NullPointerException(); + + if (length < 20) + throw ShortBufferException(); + + hmacsha1Digest(&_param, data); + + return 20; +} + +size_t HMACSHA1::engineGetMacLength() +{ + return 20; +} + +void HMACSHA1::engineReset() +{ + hmacsha1Reset(&_param); +} + +void HMACSHA1::engineUpdate(byte b) +{ + hmacsha1Update(&_param, &b, 1); +} + +void HMACSHA1::engineUpdate(const byte* data, size_t offset, size_t length) +{ + hmacsha1Update(&_param, data+offset, length); +} + +void HMACSHA1::engineInit(const Key& key, const AlgorithmParameterSpec* spec) throw (InvalidKeyException, InvalidAlgorithmParameterException) +{ + if (spec) + throw InvalidAlgorithmParameterException("No AlgorithmParameterSpec supported"); + + const PBEKey* pbe = dynamic_cast(&key); + if (pbe) + { + byte _mac_key[20]; + bytearray _rawk, _salt; + size_t _iter; + + if (pbe->getEncoded()) + _rawk = *(pbe->getEncoded()); + else + throw InvalidKeyException("PBEKey must have an encoding"); + + if (pbe->getSalt()) + _salt = *(pbe->getSalt()); + + _iter = pbe->getIterationCount(); + + if (pkcs12_derive_key(&sha1, PKCS12_ID_MAC, _rawk.data(), _rawk.size(), _salt.data(), _salt.size(), _iter, _mac_key, 20)) + throw InvalidKeyException("pkcs12_derive_key returned error"); + + hmacsha1Setup(&_param, _mac_key, 160); + + return; + } + + throw InvalidKeyException("Expected a PBEKey"); +} diff --git a/beecrypt/c++/provider/HMACSHA1.h b/beecrypt/c++/provider/HMACSHA1.h new file mode 100644 index 0000000..19b48be --- /dev/null +++ b/beecrypt/c++/provider/HMACSHA1.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file HMACSHA1.h + * \ingroup CXX_PROV_m + */ + +#ifndef _CLASS_HMACSHA1_H +#define _CLASS_HMACSHA1_H + +#include "beecrypt/beecrypt.h" +#include "beecrypt/hmacsha1.h" + +#ifdef __cplusplus + +#include "beecrypt/c++/crypto/MacSpi.h" +using beecrypt::crypto::MacSpi; + +namespace beecrypt { + namespace provider { + class HMACSHA1 : public MacSpi + { + private: + hmacsha1Param _param; + bytearray _digest; + + protected: + virtual const bytearray& engineDoFinal(); + virtual size_t engineDoFinal(byte*, size_t, size_t) throw (ShortBufferException); + virtual size_t engineGetMacLength(); + virtual void engineInit(const Key&, const AlgorithmParameterSpec* spec) throw (InvalidKeyException, InvalidAlgorithmParameterException); + virtual void engineReset(); + virtual void engineUpdate(byte); + virtual void engineUpdate(const byte*, size_t, size_t); + + public: + HMACSHA1(); + virtual ~HMACSHA1(); + + virtual HMACSHA1* clone() const; + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/provider/HMACSHA256.cxx b/beecrypt/c++/provider/HMACSHA256.cxx new file mode 100644 index 0000000..6c22db0 --- /dev/null +++ b/beecrypt/c++/provider/HMACSHA256.cxx @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/pkcs12.h" + +#include "beecrypt/c++/crypto/interfaces/PBEKey.h" +using beecrypt::crypto::interfaces::PBEKey; +#include "beecrypt/c++/lang/NullPointerException.h" +using beecrypt::lang::NullPointerException; +#include "beecrypt/c++/provider/HMACSHA256.h" + +using namespace beecrypt::provider; + +HMACSHA256::HMACSHA256() : _digest(32) +{ +} + +HMACSHA256::~HMACSHA256() +{ +} + +HMACSHA256* HMACSHA256::clone() const +{ + HMACSHA256* result = new HMACSHA256(); + + memcpy(&result->_param, &_param, sizeof(hmacsha256Param)); + + return result; +} + +const bytearray& HMACSHA256::engineDoFinal() +{ + hmacsha256Digest(&_param, _digest.data()); + + return _digest; +} + +size_t HMACSHA256::engineDoFinal(byte* data, size_t offset, size_t length) throw (ShortBufferException) +{ + if (!data) + throw NullPointerException(); + + if (length < 32) + throw ShortBufferException(); + + hmacsha256Digest(&_param, data); + + return 32; +} + +size_t HMACSHA256::engineGetMacLength() +{ + return 32; +} + +void HMACSHA256::engineReset() +{ + hmacsha256Reset(&_param); +} + +void HMACSHA256::engineUpdate(byte b) +{ + hmacsha256Update(&_param, &b, 1); +} + +void HMACSHA256::engineUpdate(const byte* data, size_t offset, size_t length) +{ + hmacsha256Update(&_param, data+offset, length); +} + +void HMACSHA256::engineInit(const Key& key, const AlgorithmParameterSpec* spec) throw (InvalidKeyException, InvalidAlgorithmParameterException) +{ + if (spec) + throw InvalidAlgorithmParameterException("No AlgorithmParameterSpec supported"); + + const PBEKey* pbe = dynamic_cast(&key); + if (pbe) + { + byte _mac_key[32]; + bytearray _rawk, _salt; + size_t _iter; + + if (pbe->getEncoded()) + _rawk = *(pbe->getEncoded()); + else + throw InvalidKeyException("PBEKey must have an encoding"); + + if (pbe->getSalt()) + _salt = *(pbe->getSalt()); + + _iter = pbe->getIterationCount(); + + if (pkcs12_derive_key(&sha256, PKCS12_ID_MAC, _rawk.data(), _rawk.size(), _salt.data(), _salt.size(), _iter, _mac_key, 32)) + throw InvalidKeyException("pkcs12_derive_key returned error"); + + hmacsha256Setup(&_param, _mac_key, 256); + + return; + } + + throw InvalidKeyException("Expected a PBEKey"); +} diff --git a/beecrypt/c++/provider/HMACSHA256.h b/beecrypt/c++/provider/HMACSHA256.h new file mode 100644 index 0000000..445b28d --- /dev/null +++ b/beecrypt/c++/provider/HMACSHA256.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file HMACSHA256.h + * \ingroup CXX_PROV_m + */ + +#ifndef _CLASS_HMACSHA256_H +#define _CLASS_HMACSHA256_H + +#include "beecrypt/beecrypt.h" +#include "beecrypt/hmacsha256.h" + +#ifdef __cplusplus + +#include "beecrypt/c++/crypto/MacSpi.h" +using beecrypt::crypto::MacSpi; + +namespace beecrypt { + namespace provider { + class HMACSHA256 : public MacSpi + { + private: + hmacsha256Param _param; + bytearray _digest; + + protected: + virtual const bytearray& engineDoFinal(); + virtual size_t engineDoFinal(byte*, size_t, size_t) throw (ShortBufferException); + virtual size_t engineGetMacLength(); + virtual void engineInit(const Key&, const AlgorithmParameterSpec* spec) throw (InvalidKeyException, InvalidAlgorithmParameterException); + virtual void engineReset(); + virtual void engineUpdate(byte); + virtual void engineUpdate(const byte*, size_t, size_t); + + public: + HMACSHA256(); + virtual ~HMACSHA256(); + + virtual HMACSHA256* clone() const; + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/provider/KeyProtector.cxx b/beecrypt/c++/provider/KeyProtector.cxx new file mode 100644 index 0000000..5a7c71e --- /dev/null +++ b/beecrypt/c++/provider/KeyProtector.cxx @@ -0,0 +1,259 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/beecrypt.h" +#include "beecrypt/aes.h" +#include "beecrypt/blockmode.h" +#include "beecrypt/blockpad.h" +#include "beecrypt/hmacsha256.h" +#include "beecrypt/pkcs12.h" +#include "beecrypt/sha256.h" +#include "beecrypt/c++/provider/KeyProtector.h" +#include "beecrypt/c++/beeyond/AnyEncodedKeySpec.h" +using beecrypt::beeyond::AnyEncodedKeySpec; +#include "beecrypt/c++/crypto/BadPaddingException.h" +using beecrypt::crypto::BadPaddingException; +#include "beecrypt/c++/io/ByteArrayInputStream.h" +using beecrypt::io::ByteArrayInputStream; +#include "beecrypt/c++/io/ByteArrayOutputStream.h" +using beecrypt::io::ByteArrayOutputStream; +#include "beecrypt/c++/io/DataInputStream.h" +using beecrypt::io::DataInputStream; +#include "beecrypt/c++/io/DataOutputStream.h" +using beecrypt::io::DataOutputStream; +#include "beecrypt/c++/lang/NullPointerException.h" +using beecrypt::lang::NullPointerException; +#include "beecrypt/c++/security/KeyFactory.h" +using beecrypt::security::KeyFactory; + +using namespace beecrypt::provider; + +namespace { + /* eventually these will be moved to a different location */ + void pkcs5_pad(size_t blockbytes, bytearray& b) + { + size_t unpadded_size = b.size(); + + byte padvalue = blockbytes - (unpadded_size % blockbytes); + + b.resize(unpadded_size + padvalue); + + memset(b.data() + unpadded_size, padvalue, padvalue); + } + + void pkcs5_unpad(size_t blockbytes, bytearray& b) throw (BadPaddingException) + { + byte padvalue = b[b.size() - 1]; + + if (padvalue > blockbytes) + throw BadPaddingException(); + + for (size_t i = (b.size() - padvalue); i < (b.size() - 1); i++) + if (b[i] != padvalue) + throw BadPaddingException(); + + b.resize(b.size() - padvalue); + } +} + +KeyProtector::KeyProtector(PBEKey& key) throw (InvalidKeyException) +{ + bytearray _rawk, _salt; + size_t _iter; + + if (key.getEncoded()) + _rawk = *(key.getEncoded()); + else + throw InvalidKeyException("PBEKey must have an encoding"); + + if (key.getSalt()) + _salt = *(key.getSalt()); + + _iter = key.getIterationCount(); + + if (pkcs12_derive_key(&sha256, PKCS12_ID_CIPHER, _rawk.data(), _rawk.size(), _salt.data(), _salt.size(), _iter, _cipher_key, 32)) + throw InvalidKeyException("pkcs12_derive_key returned error"); + + if (pkcs12_derive_key(&sha256, PKCS12_ID_MAC, _rawk.data(), _rawk.size(), _salt.data(), _salt.size(), _iter, _mac_key, 32)) + throw InvalidKeyException("pkcs12_derive_key returned error"); + + if (pkcs12_derive_key(&sha256, PKCS12_ID_IV, _rawk.data(), _rawk.size(), _salt.data(), _salt.size(), _iter, _iv, 16)) + throw InvalidKeyException("pkcs12_derive_key returned error"); +} + +KeyProtector::~KeyProtector() throw () +{ + // wipe everything + memset(_cipher_key, 0, 32); + memset(_mac_key, 0, 32); + memset(_iv, 0, 16); +} + +bytearray* KeyProtector::protect(const PrivateKey& pri) throw () +{ + if (!pri.getEncoded()) + return 0; + + if (!pri.getFormat()) + return 0; + + /* Eventually we'll substitute this with the following construction: + * DataOutputStream(CipherOutputStream(ByteArrayOutputStream))) + */ + ByteArrayOutputStream bos; + DataOutputStream dos(bos); + + try + { + const bytearray* encoded_key = pri.getEncoded(); + + dos.writeUTF(pri.getAlgorithm()); + dos.writeUTF(*pri.getFormat()); + dos.writeInt(encoded_key->size()); + dos.write(*encoded_key); + dos.close(); + + bytearray cleartext, ciphertext, mac(hmacsha256.digestsize); + bos.toByteArray(cleartext); + + // Compute the MAC before padding + keyedHashFunctionContext mc(&hmacsha256); + keyedHashFunctionContextSetup(&mc, _mac_key, 256); + keyedHashFunctionContextUpdate(&mc, cleartext.data(), cleartext.size()); + keyedHashFunctionContextDigest(&mc, mac.data()); + + // Pad the cleartext + pkcs5_pad(aes.blocksize, cleartext); + + // Set the ciphertext size equal to the cleartext size + ciphertext.resize(cleartext.size()); + + // Encrypt the cleartext + blockCipherContext bc(&aes); + blockCipherContextSetup(&bc, _cipher_key, 256, ENCRYPT); + blockCipherContextSetIV(&bc, _iv); + blockCipherContextCBC(&bc, (uint32_t*) ciphertext.data(), (const uint32_t*) cleartext.data(), cleartext.size() / 16); + + // Return the concatenation of the two bytearrays + return new bytearray(ciphertext + mac); + } + catch (IOException) + { + } + + return 0; +} + +PrivateKey* KeyProtector::recover(const byte* data, size_t size) throw (NoSuchAlgorithmException, UnrecoverableKeyException) +{ + // If we don't have at least enough data for the digest then bail out + if (size <= hmacsha256.digestsize) + throw UnrecoverableKeyException("encrypted key data way too short"); + + size_t ciphertext_size = size - hmacsha256.digestsize; + + // Check if we have a whole number of blocks in the data + if ((ciphertext_size % aes.blocksize) != 0) + throw UnrecoverableKeyException("encrypted key data is not a whole number of blocks"); + + bytearray ciphertext(data, ciphertext_size), cleartext(ciphertext_size); + + // Decrypt the ciphertext + blockCipherContext bc(&aes); + blockCipherContextSetup(&bc, _cipher_key, 256, DECRYPT); + blockCipherContextSetIV(&bc, _iv); + blockCipherContextCBC(&bc, (uint32_t*) cleartext.data(), (const uint32_t*) ciphertext.data(), ciphertext_size / 16); + + try + { + pkcs5_unpad(aes.blocksize, cleartext); + } + catch (BadPaddingException) + { + // Corrupted data, most likely due to bad password + throw UnrecoverableKeyException("bad padding"); + } + + bytearray mac(hmacsha256.digestsize); + + // Verify the MAC before recovering the key + keyedHashFunctionContext mc(&hmacsha256); + keyedHashFunctionContextSetup(&mc, _mac_key, 256); + keyedHashFunctionContextUpdate(&mc, cleartext.data(), cleartext.size()); + keyedHashFunctionContextDigest(&mc, mac.data()); + + // Compare the two MACs and bail out if they're different + if (memcmp(data + ciphertext_size, mac.data(), hmacsha256.digestsize)) + return 0; + + // Now we're sure the password was correct, and we have the decrypted data + + ByteArrayInputStream bis(cleartext); + DataInputStream dis(bis); + + try + { + String algorithm, format; + bytearray enc; + + dis.readUTF(algorithm); + dis.readUTF(format); + + javaint encsize = dis.readInt(); + if (encsize <= 0) + throw IOException(); + + enc.resize(encsize); + + dis.readFully(enc); + + AnyEncodedKeySpec spec(format, enc); + KeyFactory* kf; + PrivateKey* pri; + + try + { + kf = KeyFactory::getInstance(algorithm); + pri = kf->generatePrivate(spec); + + delete kf; + + return pri; + } + catch (InvalidKeySpecException) + { + delete kf; + } + catch (NoSuchAlgorithmException) + { + } + } + catch (IOException) + { + } + throw UnrecoverableKeyException("parsing error in decrypted key"); +} + +PrivateKey* KeyProtector::recover(const bytearray& b) throw (NoSuchAlgorithmException, UnrecoverableKeyException) +{ + return recover(b.data(), b.size()); +} diff --git a/beecrypt/c++/provider/KeyProtector.h b/beecrypt/c++/provider/KeyProtector.h new file mode 100644 index 0000000..0332b16 --- /dev/null +++ b/beecrypt/c++/provider/KeyProtector.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _CLASS_KEYPROTECTOR_H +#define _CLASS_KEYPROTECTOR_H + +#include "beecrypt/api.h" + +#ifdef __cplusplus + +#include "beecrypt/c++/crypto/interfaces/PBEKey.h" +using beecrypt::crypto::interfaces::PBEKey; +#include "beecrypt/c++/security/PrivateKey.h" +using beecrypt::security::PrivateKey; +#include "beecrypt/c++/security/InvalidKeyException.h" +using beecrypt::security::InvalidKeyException; +#include "beecrypt/c++/security/UnrecoverableKeyException.h" +using beecrypt::security::UnrecoverableKeyException; +#include "beecrypt/c++/security/NoSuchAlgorithmException.h" +using beecrypt::security::NoSuchAlgorithmException; + +namespace beecrypt { + namespace provider { + class KeyProtector + { + private: + byte _cipher_key[32]; + byte _mac_key[32]; + byte _iv[16]; + + public: + KeyProtector(PBEKey&) throw (InvalidKeyException); + ~KeyProtector() throw (); + + bytearray* protect(const PrivateKey&) throw (); + + PrivateKey* recover(const bytearray&) throw (NoSuchAlgorithmException, UnrecoverableKeyException); + PrivateKey* recover(const byte*, size_t) throw (NoSuchAlgorithmException, UnrecoverableKeyException); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/provider/MD5Digest.cxx b/beecrypt/c++/provider/MD5Digest.cxx new file mode 100644 index 0000000..51c9749 --- /dev/null +++ b/beecrypt/c++/provider/MD5Digest.cxx @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/lang/NullPointerException.h" +using beecrypt::lang::NullPointerException; +#include "beecrypt/c++/provider/MD5Digest.h" + +using namespace beecrypt::provider; + +MD5Digest::MD5Digest() : _digest(16) +{ + md5Reset(&_param); +} + +MD5Digest::~MD5Digest() +{ +} + +MD5Digest* MD5Digest::clone() const +{ + MD5Digest* result = new MD5Digest(); + + memcpy(&result->_param, &_param, sizeof(md5Param)); + + return result; +} + +const bytearray& MD5Digest::engineDigest() +{ + md5Digest(&_param, _digest.data()); + + return _digest; +} + +size_t MD5Digest::engineDigest(byte* data, size_t offset, size_t length) throw (ShortBufferException) +{ + if (!data) + throw NullPointerException(); + + if (length < 16) + throw ShortBufferException(); + + md5Digest(&_param, data); + + return 16; +} + +size_t MD5Digest::engineGetDigestLength() +{ + return 16; +} + +void MD5Digest::engineReset() +{ + md5Reset(&_param); +} + +void MD5Digest::engineUpdate(byte b) +{ + md5Update(&_param, &b, 1); +} + +void MD5Digest::engineUpdate(const byte* data, size_t offset, size_t length) +{ + md5Update(&_param, data+offset, length); +} diff --git a/beecrypt/c++/provider/MD5Digest.h b/beecrypt/c++/provider/MD5Digest.h new file mode 100644 index 0000000..f4bf7ba --- /dev/null +++ b/beecrypt/c++/provider/MD5Digest.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file MD5Digest.h + * \ingroup CXX_PROV_m + */ + +#ifndef _CLASS_MD5DIGEST_H +#define _CLASS_MD5DIGEST_H + +#include "beecrypt/beecrypt.h" +#include "beecrypt/md5.h" + +#ifdef __cplusplus + +#include "beecrypt/c++/security/MessageDigestSpi.h" +using beecrypt::security::MessageDigestSpi; + +namespace beecrypt { + namespace provider { + class MD5Digest : public MessageDigestSpi + { + private: + md5Param _param; + bytearray _digest; + + protected: + virtual const bytearray& engineDigest(); + virtual size_t engineDigest(byte*, size_t, size_t) throw (ShortBufferException); + virtual size_t engineGetDigestLength(); + virtual void engineReset(); + virtual void engineUpdate(byte); + virtual void engineUpdate(const byte*, size_t, size_t); + + public: + MD5Digest(); + virtual ~MD5Digest(); + + virtual MD5Digest* clone() const; + + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/provider/MD5withRSASignature.cxx b/beecrypt/c++/provider/MD5withRSASignature.cxx new file mode 100644 index 0000000..a3bf05f --- /dev/null +++ b/beecrypt/c++/provider/MD5withRSASignature.cxx @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/provider/MD5withRSASignature.h" + +#include "beecrypt/md5.h" + +using namespace beecrypt::provider; + +MD5withRSASignature::MD5withRSASignature() : PKCS1RSASignature(&md5) +{ +} + +MD5withRSASignature::~MD5withRSASignature() +{ +} diff --git a/beecrypt/c++/provider/MD5withRSASignature.h b/beecrypt/c++/provider/MD5withRSASignature.h new file mode 100644 index 0000000..18a2251 --- /dev/null +++ b/beecrypt/c++/provider/MD5withRSASignature.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file MD5withRSASignature.h + * \ingroup CXX_PROV_m + */ + +#ifndef _CLASS_MD5WITHRSASIGNATURE_H +#define _CLASS_MD5WITHRSASIGNATURE_H + +#ifdef __cplusplus + +#include "beecrypt/c++/provider/PKCS1RSASignature.h" + +namespace beecrypt { + namespace provider { + class MD5withRSASignature : public PKCS1RSASignature + { + public: + MD5withRSASignature(); + ~MD5withRSASignature(); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/provider/Makefile.am b/beecrypt/c++/provider/Makefile.am new file mode 100644 index 0000000..49a7c2a --- /dev/null +++ b/beecrypt/c++/provider/Makefile.am @@ -0,0 +1,83 @@ +INCLUDES = -I$(top_srcdir)/.. + +LIBS = -licuuc -licuio + +AUTOMAKE_OPTIONS = gnu no-dependencies + +pkgaltlibdir=$(prefix)/lib@LIBALT@ +pkgaltlib_LTLIBRARIES = base.la + +base_la_SOURCES = \ +BeeCertificateFactory.cxx \ +BeeCryptProvider.cxx \ +BeeKeyFactory.cxx \ +BeeKeyStore.cxx \ +BeeSecureRandom.cxx \ +DHKeyFactory.cxx \ +DHKeyPairGenerator.cxx \ +DHParameterGenerator.cxx \ +DHParameters.cxx \ +DHPrivateKeyImpl.cxx \ +DHPublicKeyImpl.cxx \ +DSAKeyFactory.cxx \ +DSAKeyPairGenerator.cxx \ +DSAParameterGenerator.cxx \ +DSAParameters.cxx \ +DSAPrivateKeyImpl.cxx \ +DSAPublicKeyImpl.cxx \ +HMACMD5.cxx \ +HMACSHA1.cxx \ +HMACSHA256.cxx \ +KeyProtector.cxx \ +MD5Digest.cxx \ +MD5withRSASignature.cxx \ +PKCS1RSASignature.cxx \ +PKCS12KeyFactory.cxx \ +RSAKeyFactory.cxx \ +RSAKeyPairGenerator.cxx \ +RSAPrivateCrtKeyImpl.cxx \ +RSAPrivateKeyImpl.cxx \ +RSAPublicKeyImpl.cxx \ +SHA1Digest.cxx \ +SHA1withDSASignature.cxx \ +SHA1withRSASignature.cxx \ +SHA256withRSASignature.cxx + +base_la_LDFLAGS = -module +base_la_LIBADD = $(top_builddir)/c++/libbeecrypt_cxx.la + +noinst_HEADERS = \ +BeeCertificateFactory.h \ +BeeCryptProvider.h \ +BeeKeyFactory.h \ +BeeKeyStore.h \ +BeeSecureRandom.h \ +DHKeyFactory.h \ +DHKeyPairGenerator.h \ +DHParameterGenerator.h \ +DHParameters.h \ +DHPrivateKeyImpl.h \ +DHPublicKeyImpl.h \ +DSAKeyFactory.h \ +DSAKeyPairGenerator.h \ +DSAParameterGenerator.h \ +DSAParameters.h \ +DSAPrivateKeyImpl.h \ +DSAPublicKeyImpl.h \ +HMACMD5.h \ +HMACSHA1.h \ +HMACSHA256.h \ +KeyProtector.h \ +MD5Digest.h \ +MD5withRSASignature.h \ +PKCS1RSASignature.h \ +PKCS12KeyFactory.h \ +RSAKeyFactory.h \ +RSAKeyPairGenerator.h \ +RSAPrivateCrtKeyImpl.h \ +RSAPrivateKeyImpl.h \ +RSAPublicKeyImpl.h \ +SHA1Digest.h \ +SHA1withDSASignature.h \ +SHA1withRSASignature.h \ +SHA256withRSASignature.h diff --git a/beecrypt/c++/provider/Makefile.in b/beecrypt/c++/provider/Makefile.in new file mode 100644 index 0000000..2bd5c6b --- /dev/null +++ b/beecrypt/c++/provider/Makefile.in @@ -0,0 +1,570 @@ +# Makefile.in generated by automake 1.8.3 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + + +SOURCES = $(base_la_SOURCES) + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +top_builddir = ../.. +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +INSTALL = @INSTALL@ +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +host_triplet = @host@ +subdir = c++/provider +DIST_COMMON = $(noinst_HEADERS) $(srcdir)/Makefile.am \ + $(srcdir)/Makefile.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \ + $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +am__installdirs = "$(DESTDIR)$(pkgaltlibdir)" +pkgaltlibLTLIBRARIES_INSTALL = $(INSTALL) +LTLIBRARIES = $(pkgaltlib_LTLIBRARIES) +base_la_DEPENDENCIES = $(top_builddir)/c++/libbeecrypt_cxx.la +am_base_la_OBJECTS = BeeCertificateFactory.lo BeeCryptProvider.lo \ + BeeKeyFactory.lo BeeKeyStore.lo BeeSecureRandom.lo \ + DHKeyFactory.lo DHKeyPairGenerator.lo DHParameterGenerator.lo \ + DHParameters.lo DHPrivateKeyImpl.lo DHPublicKeyImpl.lo \ + DSAKeyFactory.lo DSAKeyPairGenerator.lo \ + DSAParameterGenerator.lo DSAParameters.lo DSAPrivateKeyImpl.lo \ + DSAPublicKeyImpl.lo HMACMD5.lo HMACSHA1.lo HMACSHA256.lo \ + KeyProtector.lo MD5Digest.lo MD5withRSASignature.lo \ + PKCS1RSASignature.lo PKCS12KeyFactory.lo RSAKeyFactory.lo \ + RSAKeyPairGenerator.lo RSAPrivateCrtKeyImpl.lo \ + RSAPrivateKeyImpl.lo RSAPublicKeyImpl.lo SHA1Digest.lo \ + SHA1withDSASignature.lo SHA1withRSASignature.lo \ + SHA256withRSASignature.lo +base_la_OBJECTS = $(am_base_la_OBJECTS) +DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir) +depcomp = +am__depfiles_maybe = +CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) +LTCXXCOMPILE = $(LIBTOOL) --mode=compile $(CXX) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CXXFLAGS) $(CXXFLAGS) +CXXLD = $(CXX) +CXXLINK = $(LIBTOOL) --mode=link $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) \ + $(AM_LDFLAGS) $(LDFLAGS) -o $@ +SOURCES = $(base_la_SOURCES) +DIST_SOURCES = $(base_la_SOURCES) +HEADERS = $(noinst_HEADERS) +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMDEP_FALSE = @AMDEP_FALSE@ +AMDEP_TRUE = @AMDEP_TRUE@ +AMTAR = @AMTAR@ +AR = @AR@ +AS = @AS@ +ASM_ALIGN = @ASM_ALIGN@ +ASM_ARCH = @ASM_ARCH@ +ASM_BIGENDIAN = @ASM_BIGENDIAN@ +ASM_CPU = @ASM_CPU@ +ASM_GLOBL = @ASM_GLOBL@ +ASM_GSYM_PREFIX = @ASM_GSYM_PREFIX@ +ASM_LSYM_PREFIX = @ASM_LSYM_PREFIX@ +ASM_OS = @ASM_OS@ +ASM_TEXTSEG = @ASM_TEXTSEG@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCAS = @CCAS@ +CCASFLAGS = @CCASFLAGS@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DLLTOOL = @DLLTOOL@ +ECHO = @ECHO@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +F77 = @F77@ +FFLAGS = @FFLAGS@ +INCLUDE_DLFCN_H = @INCLUDE_DLFCN_H@ +INCLUDE_INTTYPES_H = @INCLUDE_INTTYPES_H@ +INCLUDE_MALLOC_H = @INCLUDE_MALLOC_H@ +INCLUDE_PTHREAD_H = @INCLUDE_PTHREAD_H@ +INCLUDE_STDINT_H = @INCLUDE_STDINT_H@ +INCLUDE_STDIO_H = @INCLUDE_STDIO_H@ +INCLUDE_STDLIB_H = @INCLUDE_STDLIB_H@ +INCLUDE_STRING_H = @INCLUDE_STRING_H@ +INCLUDE_SYNCH_H = @INCLUDE_SYNCH_H@ +INCLUDE_THREAD_H = @INCLUDE_THREAD_H@ +INCLUDE_UNISTD_H = @INCLUDE_UNISTD_H@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +JAVAINC = @JAVAINC@ +LDFLAGS = @LDFLAGS@ +LIBALT = @LIBALT@ +LIBOBJS = @LIBOBJS@ +LIBS = -licuuc -licuio +LIBTOOL = @LIBTOOL@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +MAYBE_LTLIB = @MAYBE_LTLIB@ +MAYBE_SUB = @MAYBE_SUB@ +MP_WBITS = @MP_WBITS@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PYTHONINC = @PYTHONINC@ +PYTHONLIB = @PYTHONLIB@ +RANLIB = @RANLIB@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +TYPEDEF_BC_COND_T = @TYPEDEF_BC_COND_T@ +TYPEDEF_BC_MUTEX_T = @TYPEDEF_BC_MUTEX_T@ +TYPEDEF_BC_THREAD_T = @TYPEDEF_BC_THREAD_T@ +TYPEDEF_INT16_T = @TYPEDEF_INT16_T@ +TYPEDEF_INT32_T = @TYPEDEF_INT32_T@ +TYPEDEF_INT64_T = @TYPEDEF_INT64_T@ +TYPEDEF_INT8_T = @TYPEDEF_INT8_T@ +TYPEDEF_SIZE_T = @TYPEDEF_SIZE_T@ +TYPEDEF_UINT16_T = @TYPEDEF_UINT16_T@ +TYPEDEF_UINT32_T = @TYPEDEF_UINT32_T@ +TYPEDEF_UINT64_T = @TYPEDEF_UINT64_T@ +TYPEDEF_UINT8_T = @TYPEDEF_UINT8_T@ +VERSION = @VERSION@ +ac_ct_AR = @ac_ct_AR@ +ac_ct_AS = @ac_ct_AS@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DLLTOOL = @ac_ct_DLLTOOL@ +ac_ct_F77 = @ac_ct_F77@ +ac_ct_OBJDUMP = @ac_ct_OBJDUMP@ +ac_ct_RANLIB = @ac_ct_RANLIB@ +ac_ct_STRIP = @ac_ct_STRIP@ +ac_cv_have_gcj = @ac_cv_have_gcj@ +ac_cv_have_java = @ac_cv_have_java@ +ac_cv_have_javac = @ac_cv_have_javac@ +ac_cv_have_python = @ac_cv_have_python@ +am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ +am__fastdepCC_TRUE = @am__fastdepCC_TRUE@ +am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@ +am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +datadir = @datadir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +sysconfdir = @sysconfdir@ +target = @target@ +target_alias = @target_alias@ +target_cpu = @target_cpu@ +target_os = @target_os@ +target_vendor = @target_vendor@ +INCLUDES = -I$(top_srcdir)/.. +AUTOMAKE_OPTIONS = gnu no-dependencies +pkgaltlibdir = $(prefix)/lib@LIBALT@ +pkgaltlib_LTLIBRARIES = base.la +base_la_SOURCES = \ +BeeCertificateFactory.cxx \ +BeeCryptProvider.cxx \ +BeeKeyFactory.cxx \ +BeeKeyStore.cxx \ +BeeSecureRandom.cxx \ +DHKeyFactory.cxx \ +DHKeyPairGenerator.cxx \ +DHParameterGenerator.cxx \ +DHParameters.cxx \ +DHPrivateKeyImpl.cxx \ +DHPublicKeyImpl.cxx \ +DSAKeyFactory.cxx \ +DSAKeyPairGenerator.cxx \ +DSAParameterGenerator.cxx \ +DSAParameters.cxx \ +DSAPrivateKeyImpl.cxx \ +DSAPublicKeyImpl.cxx \ +HMACMD5.cxx \ +HMACSHA1.cxx \ +HMACSHA256.cxx \ +KeyProtector.cxx \ +MD5Digest.cxx \ +MD5withRSASignature.cxx \ +PKCS1RSASignature.cxx \ +PKCS12KeyFactory.cxx \ +RSAKeyFactory.cxx \ +RSAKeyPairGenerator.cxx \ +RSAPrivateCrtKeyImpl.cxx \ +RSAPrivateKeyImpl.cxx \ +RSAPublicKeyImpl.cxx \ +SHA1Digest.cxx \ +SHA1withDSASignature.cxx \ +SHA1withRSASignature.cxx \ +SHA256withRSASignature.cxx + +base_la_LDFLAGS = -module +base_la_LIBADD = $(top_builddir)/c++/libbeecrypt_cxx.la +noinst_HEADERS = \ +BeeCertificateFactory.h \ +BeeCryptProvider.h \ +BeeKeyFactory.h \ +BeeKeyStore.h \ +BeeSecureRandom.h \ +DHKeyFactory.h \ +DHKeyPairGenerator.h \ +DHParameterGenerator.h \ +DHParameters.h \ +DHPrivateKeyImpl.h \ +DHPublicKeyImpl.h \ +DSAKeyFactory.h \ +DSAKeyPairGenerator.h \ +DSAParameterGenerator.h \ +DSAParameters.h \ +DSAPrivateKeyImpl.h \ +DSAPublicKeyImpl.h \ +HMACMD5.h \ +HMACSHA1.h \ +HMACSHA256.h \ +KeyProtector.h \ +MD5Digest.h \ +MD5withRSASignature.h \ +PKCS1RSASignature.h \ +PKCS12KeyFactory.h \ +RSAKeyFactory.h \ +RSAKeyPairGenerator.h \ +RSAPrivateCrtKeyImpl.h \ +RSAPrivateKeyImpl.h \ +RSAPublicKeyImpl.h \ +SHA1Digest.h \ +SHA1withDSASignature.h \ +SHA1withRSASignature.h \ +SHA256withRSASignature.h + +all: all-am + +.SUFFIXES: +.SUFFIXES: .cxx .lo .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ + && exit 0; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu c++/provider/Makefile'; \ + cd $(top_srcdir) && \ + $(AUTOMAKE) --gnu c++/provider/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +install-pkgaltlibLTLIBRARIES: $(pkgaltlib_LTLIBRARIES) + @$(NORMAL_INSTALL) + test -z "$(pkgaltlibdir)" || $(mkdir_p) "$(DESTDIR)$(pkgaltlibdir)" + @list='$(pkgaltlib_LTLIBRARIES)'; for p in $$list; do \ + if test -f $$p; then \ + f="`echo $$p | sed -e 's|^.*/||'`"; \ + echo " $(LIBTOOL) --mode=install $(pkgaltlibLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) '$$p' '$(DESTDIR)$(pkgaltlibdir)/$$f'"; \ + $(LIBTOOL) --mode=install $(pkgaltlibLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) "$$p" "$(DESTDIR)$(pkgaltlibdir)/$$f"; \ + else :; fi; \ + done + +uninstall-pkgaltlibLTLIBRARIES: + @$(NORMAL_UNINSTALL) + @list='$(pkgaltlib_LTLIBRARIES)'; for p in $$list; do \ + p="`echo $$p | sed -e 's|^.*/||'`"; \ + echo " $(LIBTOOL) --mode=uninstall rm -f '$(DESTDIR)$(pkgaltlibdir)/$$p'"; \ + $(LIBTOOL) --mode=uninstall rm -f "$(DESTDIR)$(pkgaltlibdir)/$$p"; \ + done + +clean-pkgaltlibLTLIBRARIES: + -test -z "$(pkgaltlib_LTLIBRARIES)" || rm -f $(pkgaltlib_LTLIBRARIES) + @list='$(pkgaltlib_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" = "$$p" && dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +base.la: $(base_la_OBJECTS) $(base_la_DEPENDENCIES) + $(CXXLINK) -rpath $(pkgaltlibdir) $(base_la_LDFLAGS) $(base_la_OBJECTS) $(base_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +.cxx.o: + $(CXXCOMPILE) -c -o $@ $< + +.cxx.obj: + $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +.cxx.lo: + $(LTCXXCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +distclean-libtool: + -rm -f libtool +uninstall-info-am: + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(ETAGS_ARGS)$$tags$$unique" \ + || $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$tags $$unique +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(CTAGS_ARGS)$$tags$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$tags $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && cd $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) $$here + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \ + list='$(DISTFILES)'; for file in $$list; do \ + case $$file in \ + $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \ + $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \ + esac; \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test "$$dir" != "$$file" && test "$$dir" != "."; then \ + dir="/$$dir"; \ + $(mkdir_p) "$(distdir)$$dir"; \ + else \ + dir=''; \ + fi; \ + if test -d $$d/$$file; then \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + fi; \ + cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ + else \ + test -f $(distdir)/$$file \ + || cp -p $$d/$$file $(distdir)/$$file \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(LTLIBRARIES) $(HEADERS) +installdirs: + for dir in "$(DESTDIR)$(pkgaltlibdir)"; do \ + test -z "$$dir" || $(mkdir_p) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -rm -f $(CONFIG_CLEAN_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libtool clean-pkgaltlibLTLIBRARIES \ + mostlyclean-am + +distclean: distclean-am + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-libtool distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +info: info-am + +info-am: + +install-data-am: install-pkgaltlibLTLIBRARIES + +install-exec-am: + +install-info: install-info-am + +install-man: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-info-am uninstall-pkgaltlibLTLIBRARIES + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-libtool clean-pkgaltlibLTLIBRARIES ctags distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-tags distdir dvi dvi-am html html-am info info-am \ + install install-am install-data install-data-am install-exec \ + install-exec-am install-info install-info-am install-man \ + install-pkgaltlibLTLIBRARIES install-strip installcheck \ + installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags uninstall uninstall-am uninstall-info-am \ + uninstall-pkgaltlibLTLIBRARIES + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/beecrypt/c++/provider/PKCS12KeyFactory.cxx b/beecrypt/c++/provider/PKCS12KeyFactory.cxx new file mode 100644 index 0000000..e6844fc --- /dev/null +++ b/beecrypt/c++/provider/PKCS12KeyFactory.cxx @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/beeyond/PKCS12PBEKey.h" +using beecrypt::beeyond::PKCS12PBEKey; +#include "beecrypt/c++/crypto/spec/PBEKeySpec.h" +using beecrypt::crypto::spec::PBEKeySpec; +#include "beecrypt/c++/provider/PKCS12KeyFactory.h" + +using namespace beecrypt::provider; + +PKCS12KeyFactory::PKCS12KeyFactory() +{ +} + +PKCS12KeyFactory::~PKCS12KeyFactory() +{ +} + +SecretKey* PKCS12KeyFactory::engineGenerateSecret(const KeySpec& spec) throw (InvalidKeySpecException) +{ + const PBEKeySpec* pbe = dynamic_cast(&spec); + if (pbe) + { + return new PKCS12PBEKey(pbe->getPassword(), pbe->getSalt(), pbe->getIterationCount()); + } + throw InvalidKeySpecException("Expected a PBEKeySpec"); +} + +KeySpec* PKCS12KeyFactory::engineGetKeySpec(const SecretKey& key, const type_info& info) throw (InvalidKeySpecException) +{ + const PBEKey* pbe = dynamic_cast(&key); + if (pbe) + { + if (info == typeid(KeySpec) || info == typeid(PBEKeySpec)) + { + return new PBEKeySpec(&pbe->getPassword(), pbe->getSalt(), pbe->getIterationCount(), 0); + } + throw InvalidKeySpecException("Unsupported KeySpec type"); + } + throw InvalidKeySpecException("Unsupported SecretKey type"); +} + +SecretKey* PKCS12KeyFactory::engineTranslateKey(const SecretKey& key) throw (InvalidKeyException) +{ + const PBEKey* pbe = dynamic_cast(&key); + if (pbe) + { + return new PKCS12PBEKey(pbe->getPassword(), pbe->getSalt(), pbe->getIterationCount()); + } + throw InvalidKeyException("Unsupported SecretKey type"); +} diff --git a/beecrypt/c++/provider/PKCS12KeyFactory.h b/beecrypt/c++/provider/PKCS12KeyFactory.h new file mode 100644 index 0000000..4e3c95d --- /dev/null +++ b/beecrypt/c++/provider/PKCS12KeyFactory.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file PKCS12KeyFactory.h + * \ingroup CXX_PROV_m + */ + +#ifndef _CLASS_PKCS12KEYFACTORY_H +#define _CLASS_PKCS12KEYFACTORY_H + +#ifdef __cplusplus + +#include "beecrypt/c++/crypto/SecretKeyFactorySpi.h" +using beecrypt::crypto::SecretKeyFactorySpi; + +namespace beecrypt { + namespace provider { + class PKCS12KeyFactory : public SecretKeyFactorySpi + { + protected: + virtual SecretKey* engineGenerateSecret(const KeySpec&) throw (InvalidKeySpecException); + virtual KeySpec* engineGetKeySpec(const SecretKey&, const type_info&) throw (InvalidKeySpecException); + virtual SecretKey* engineTranslateKey(const SecretKey&) throw (InvalidKeyException); + + public: + PKCS12KeyFactory(); + virtual ~PKCS12KeyFactory(); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/provider/PKCS1RSASignature.cxx b/beecrypt/c++/provider/PKCS1RSASignature.cxx new file mode 100644 index 0000000..1ecda32 --- /dev/null +++ b/beecrypt/c++/provider/PKCS1RSASignature.cxx @@ -0,0 +1,196 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/lang/NullPointerException.h" +using beecrypt::lang::NullPointerException; +#include "beecrypt/c++/provider/PKCS1RSASignature.h" +#include "beecrypt/c++/security/interfaces/RSAPrivateKey.h" +using beecrypt::security::interfaces::RSAPrivateKey; +#include "beecrypt/c++/security/interfaces/RSAPrivateCrtKey.h" +using beecrypt::security::interfaces::RSAPrivateCrtKey; +#include "beecrypt/c++/security/interfaces/RSAPublicKey.h" +using beecrypt::security::interfaces::RSAPublicKey; + +#include "beecrypt/pkcs1.h" + +using namespace beecrypt::provider; + +PKCS1RSASignature::PKCS1RSASignature(const hashFunction* hf) : _hfc(hf) +{ +} + +PKCS1RSASignature::~PKCS1RSASignature() +{ +} + +AlgorithmParameters* PKCS1RSASignature::engineGetParameters() const +{ + return 0; +} + +void PKCS1RSASignature::engineSetParameter(const AlgorithmParameterSpec& spec) throw (InvalidAlgorithmParameterException) +{ + throw InvalidAlgorithmParameterException("unsupported for this algorithm"); +} + +void PKCS1RSASignature::engineInitSign(const PrivateKey& key, SecureRandom* random) throw (InvalidKeyException) +{ + const RSAPrivateKey* rsa = dynamic_cast(&key); + + if (rsa) + { + /* copy key information */ + _pair.n = rsa->getModulus(); + _pair.d = rsa->getPrivateExponent(); + + const RSAPrivateCrtKey* crt = dynamic_cast(rsa); + + if (crt) + { + _pair.p = crt->getPrimeP(); + _pair.q = crt->getPrimeQ(); + _pair.dp = crt->getPrimeExponentP(); + _pair.dq = crt->getPrimeExponentQ(); + _pair.qi = crt->getCrtCoefficient(); + _crt = true; + } + else + _crt = false; + + /* reset the hash function */ + hashFunctionContextReset(&_hfc); + + _srng = random; + } + else + throw InvalidKeyException("key must be a RSAPrivateKey"); +} + +void PKCS1RSASignature::engineInitVerify(const PublicKey& key) throw (InvalidKeyException) +{ + const RSAPublicKey* rsa = dynamic_cast(&key); + + if (rsa) + { + /* copy key information */ + _pair.n = rsa->getModulus(); + _pair.e = rsa->getPublicExponent(); + + /* reset the hash function */ + hashFunctionContextReset(&_hfc); + + _srng = 0; + } + else + throw InvalidKeyException("key must be a RSAPrivateKey"); +} + +void PKCS1RSASignature::engineUpdate(byte b) +{ + hashFunctionContextUpdate(&_hfc, &b, 1); +} + +void PKCS1RSASignature::engineUpdate(const byte* data, size_t offset, size_t len) +{ + hashFunctionContextUpdate(&_hfc, data+offset, len); +} + +bytearray* PKCS1RSASignature::engineSign() throw (SignatureException) +{ + size_t sigsize = (_pair.n.bitlength()+7) >> 3; + + bytearray* signature = new bytearray(sigsize); + + engineSign(signature->data(), 0, signature->size()); + + return signature; +} + +size_t PKCS1RSASignature::engineSign(byte* signature, size_t offset, size_t len) throw (ShortBufferException, SignatureException) +{ + if (!signature) + throw NullPointerException(); + + size_t sigsize = (_pair.n.bitlength()+7) >> 3; + + /* test if we have enough space in output buffer */ + if (sigsize > (len - offset)) + throw ShortBufferException(); + + /* okay, we can continue */ + mpnumber c, m; + bytearray em(sigsize); + + if (pkcs1_emsa_encode_digest(&_hfc, em.data(), sigsize)) + throw SignatureException("internal error in emsa_pkcs1_encode_digest"); + + mpnsetbin(&c, em.data(), sigsize); + + if (_crt) + { + if (rsapricrt(&_pair.n, &_pair.p, &_pair.q, &_pair.dp, &_pair.dq, &_pair.qi, &c, &m)) + throw SignatureException("internal error in rsapricrt function"); + } + else + { + if (rsapri(&_pair.n, &_pair.d, &c, &m)) + throw SignatureException("internal error in rsapri function"); + } + + if (i2osp(signature+offset, sigsize, m.data, m.size)) + throw SignatureException("internal error in i2osp"); + + return sigsize; +} + +size_t PKCS1RSASignature::engineSign(bytearray& signature) throw (SignatureException) +{ + size_t sigsize = (_pair.n.bitlength()+7) >> 3; + + signature.resize(sigsize); + + return engineSign(signature.data(), 0, signature.size()); +} + +bool PKCS1RSASignature::engineVerify(const byte* signature, size_t offset, size_t len) throw (SignatureException) +{ + if (!signature) + throw NullPointerException(); + + size_t sigsize = (_pair.n.bitlength()+7) >> 3; + + /* test if we have enough data in signature */ + if (sigsize > (len - offset)) + return false; + + /* okay, we can continue */ + mpnumber c, m; + bytearray em(sigsize); + + if (pkcs1_emsa_encode_digest(&_hfc, em.data(), sigsize)) + throw SignatureException("internal error in emsa_pkcs1_encode_digest"); + + mpnsetbin(&c, em.data(), sigsize); + mpnsetbin(&m, signature+offset, sigsize); + + return rsavrfy(&_pair.n, &_pair.e, &m, &c); +} diff --git a/beecrypt/c++/provider/PKCS1RSASignature.h b/beecrypt/c++/provider/PKCS1RSASignature.h new file mode 100644 index 0000000..a7fd8df --- /dev/null +++ b/beecrypt/c++/provider/PKCS1RSASignature.h @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file PKCS1RSASignature.h + * \ingroup CXX_PROV_m + */ + +#ifndef _CLASS_PKCS1RSASIGNATURE_H +#define _CLASS_PKCS1RSASIGNATURE_H + +#include "beecrypt/api.h" +#include "beecrypt/rsa.h" + +#ifdef __cplusplus + +#include "beecrypt/c++/security/SignatureSpi.h" +using beecrypt::security::SecureRandom; +using beecrypt::security::SignatureSpi; +using beecrypt::security::AlgorithmParameters; +using beecrypt::security::InvalidAlgorithmParameterException; +using beecrypt::security::InvalidKeyException; +using beecrypt::security::PrivateKey; +using beecrypt::security::PublicKey; +using beecrypt::security::ShortBufferException; +using beecrypt::security::SignatureException; +using beecrypt::security::spec::AlgorithmParameterSpec; + +namespace beecrypt { + namespace provider { + class PKCS1RSASignature : public SignatureSpi + { + private: + rsakp _pair; + bool _crt; + hashFunctionContext _hfc; + SecureRandom* _srng; + + protected: + PKCS1RSASignature(const hashFunction*); + + virtual AlgorithmParameters* engineGetParameters() const; + virtual void engineSetParameter(const AlgorithmParameterSpec&) throw (InvalidAlgorithmParameterException); + + virtual void engineInitSign(const PrivateKey&, SecureRandom*) throw (InvalidKeyException); + virtual void engineInitVerify(const PublicKey&) throw (InvalidKeyException); + + virtual bytearray* engineSign() throw (SignatureException); + virtual size_t engineSign(byte*, size_t, size_t) throw (ShortBufferException, SignatureException); + virtual size_t engineSign(bytearray&) throw (SignatureException); + virtual bool engineVerify(const byte*, size_t, size_t) throw (SignatureException); + + virtual void engineUpdate(byte); + virtual void engineUpdate(const byte*, size_t, size_t); + + public: + virtual ~PKCS1RSASignature(); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/provider/RSAKeyFactory.cxx b/beecrypt/c++/provider/RSAKeyFactory.cxx new file mode 100644 index 0000000..1bdb3fc --- /dev/null +++ b/beecrypt/c++/provider/RSAKeyFactory.cxx @@ -0,0 +1,196 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/provider/RSAKeyFactory.h" +#include "beecrypt/c++/provider/RSAPrivateKeyImpl.h" +#include "beecrypt/c++/provider/RSAPrivateCrtKeyImpl.h" +#include "beecrypt/c++/provider/RSAPublicKeyImpl.h" +#include "beecrypt/c++/security/KeyFactory.h" +using beecrypt::security::KeyFactory; +#include "beecrypt/c++/security/spec/EncodedKeySpec.h" +using beecrypt::security::spec::EncodedKeySpec; +#include "beecrypt/c++/security/spec/RSAPrivateKeySpec.h" +using beecrypt::security::spec::RSAPrivateKeySpec; +#include "beecrypt/c++/security/spec/RSAPrivateCrtKeySpec.h" +using beecrypt::security::spec::RSAPrivateCrtKeySpec; +#include "beecrypt/c++/security/spec/RSAPublicKeySpec.h" +using beecrypt::security::spec::RSAPublicKeySpec; + +using beecrypt::security::NoSuchAlgorithmException; + +using namespace beecrypt::provider; + +RSAKeyFactory::RSAKeyFactory() +{ +} + +RSAKeyFactory::~RSAKeyFactory() +{ +} + +PrivateKey* RSAKeyFactory::engineGeneratePrivate(const KeySpec& spec) throw (InvalidKeySpecException) +{ + const RSAPrivateKeySpec* rsa = dynamic_cast(&spec); + if (rsa) + { + const RSAPrivateCrtKeySpec* crt = dynamic_cast(rsa); + if (crt) + return new RSAPrivateCrtKeyImpl(crt->getModulus(), crt->getPublicExponent(), crt->getPrivateExponent(), crt->getPrimeP(), crt->getPrimeQ(), crt->getPrimeExponentP(), crt->getPrimeExponentQ(), crt->getCrtCoefficient()); + else + return new RSAPrivateKeyImpl(rsa->getModulus(), rsa->getPrivateExponent()); + } + + const EncodedKeySpec* enc = dynamic_cast(&spec); + if (enc) + { + try + { + KeyFactory* kf = KeyFactory::getInstance(enc->getFormat()); + try + { + PrivateKey* pri = kf->generatePrivate(*enc); + delete kf; + return pri; + } + catch (...) + { + delete kf; + throw; + } + } + catch (NoSuchAlgorithmException) + { + throw InvalidKeySpecException("Unsupported KeySpec encoding format"); + } + } + throw InvalidKeySpecException("Unsupported KeySpec type"); +} + +PublicKey* RSAKeyFactory::engineGeneratePublic(const KeySpec& spec) throw (InvalidKeySpecException) +{ + const RSAPublicKeySpec* rsa = dynamic_cast(&spec); + + if (rsa) + { + return new RSAPublicKeyImpl(rsa->getModulus(), rsa->getPublicExponent()); + } + + const EncodedKeySpec* enc = dynamic_cast(&spec); + if (enc) + { + try + { + KeyFactory* kf = KeyFactory::getInstance(enc->getFormat()); + try + { + PublicKey* pub = kf->generatePublic(*enc); + delete kf; + return pub; + } + catch (...) + { + delete kf; + throw; + } + } + catch (NoSuchAlgorithmException) + { + throw InvalidKeySpecException("Unsupported KeySpec encoding format"); + } + } + throw InvalidKeySpecException("Unsupported KeySpec type"); +} + +KeySpec* RSAKeyFactory::engineGetKeySpec(const Key& key, const type_info& info) throw (InvalidKeySpecException) +{ + const RSAPublicKey* pub = dynamic_cast(&key); + + if (pub) + { + if (info == typeid(KeySpec) || info == typeid(RSAPublicKeySpec)) + { + return new RSAPublicKeySpec(pub->getModulus(), pub->getPublicExponent()); + } + /* todo: + if (info == typeid(EncodedKeySpec)) + { + } + */ + + throw InvalidKeySpecException("Unsupported KeySpec type"); + } + + const RSAPrivateKey* pri = dynamic_cast(&key); + + if (pri) + { + const RSAPrivateCrtKey* crt = dynamic_cast(pri); + + if (crt) + { + if (info == typeid(KeySpec) || info == typeid(RSAPrivateCrtKeySpec)) + { + return new RSAPrivateCrtKeySpec(crt->getModulus(), crt->getPublicExponent(), crt->getPrivateExponent(), crt->getPrimeP(), crt->getPrimeQ(), crt->getPrimeExponentP(), crt->getPrimeExponentQ(), crt->getCrtCoefficient()); + } + /* todo: + if (info == typeid(EncodedKeySpec)) + { + } + */ + } + else + { + if (info == typeid(KeySpec) || info == typeid(RSAPrivateKeySpec)) + { + return new RSAPrivateKeySpec(pri->getModulus(), pri->getPrivateExponent()); + } + /* todo: + if (info == typeid(EncodedKeySpec)) + { + } + */ + } + + throw InvalidKeySpecException("Unsupported KeySpec type"); + } + + throw InvalidKeySpecException("Unsupported Key type"); +} + +Key* RSAKeyFactory::engineTranslateKey(const Key& key) throw (InvalidKeyException) +{ + const RSAPublicKey* pub = dynamic_cast(&key); + if (pub) + return new RSAPublicKeyImpl(*pub); + + const RSAPrivateKey* pri = dynamic_cast(&key); + if (pri) + { + const RSAPrivateCrtKey* crt = dynamic_cast(pri); + if (crt) + return new RSAPrivateCrtKeyImpl(*crt); + else + return new RSAPrivateKeyImpl(*pri); + } + + throw InvalidKeyException("Unsupported Key type"); +} diff --git a/beecrypt/c++/provider/RSAKeyFactory.h b/beecrypt/c++/provider/RSAKeyFactory.h new file mode 100644 index 0000000..d1d5ee3 --- /dev/null +++ b/beecrypt/c++/provider/RSAKeyFactory.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file RSAKeyFactory.h + * \ingroup CXX_PROV_m + */ + +#ifndef _CLASS_RSAKEYFACTORY_H +#define _CLASS_RSAKEYFACTORY_H + +#include "beecrypt/api.h" + +#ifdef __cplusplus + +#include "beecrypt/c++/security/KeyFactorySpi.h" +using beecrypt::security::InvalidKeyException; +using beecrypt::security::Key; +using beecrypt::security::KeyFactorySpi; +using beecrypt::security::PrivateKey; +using beecrypt::security::PublicKey; +using beecrypt::security::spec::InvalidKeySpecException; +using beecrypt::security::spec::KeySpec; + +namespace beecrypt { + namespace provider { + class RSAKeyFactory : public KeyFactorySpi + { + friend class BeeCryptProvider; + + protected: + virtual PrivateKey* engineGeneratePrivate(const KeySpec&) throw (InvalidKeySpecException); + virtual PublicKey* engineGeneratePublic(const KeySpec&) throw (InvalidKeySpecException); + + virtual KeySpec* engineGetKeySpec(const Key&, const type_info&) throw (InvalidKeySpecException); + + virtual Key* engineTranslateKey(const Key&) throw (InvalidKeyException); + + public: + RSAKeyFactory(); + virtual ~RSAKeyFactory(); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/provider/RSAKeyPairGenerator.cxx b/beecrypt/c++/provider/RSAKeyPairGenerator.cxx new file mode 100644 index 0000000..f63646a --- /dev/null +++ b/beecrypt/c++/provider/RSAKeyPairGenerator.cxx @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/adapter.h" +using beecrypt::randomGeneratorContextAdapter; +#include "beecrypt/c++/provider/BeeCryptProvider.h" +#include "beecrypt/c++/provider/RSAKeyPairGenerator.h" +#include "beecrypt/c++/provider/RSAPublicKeyImpl.h" +#include "beecrypt/c++/provider/RSAPrivateCrtKeyImpl.h" + +#include "beecrypt/rsakp.h" + +using namespace beecrypt::provider; + +RSAKeyPairGenerator::RSAKeyPairGenerator() +{ + _size = 0; + _spec = 0; + _srng = 0; +} + +RSAKeyPairGenerator::~RSAKeyPairGenerator() +{ + _size = 0; + if (_spec) + { + delete _spec; + _spec = 0; + } + _srng = 0; +} + +KeyPair* RSAKeyPairGenerator::genpair(randomGeneratorContext* rngc) +{ + rsakp _pair; + + if (rsakpMake(&_pair, rngc, _spec ? _spec->getKeysize() : (_size ? _size : 1024))) + throw "unexpected error in rsakpMake"; + + return new KeyPair(new RSAPublicKeyImpl(_pair.n, _pair.e), new RSAPrivateCrtKeyImpl(_pair.n, _pair.e, _pair.d, _pair.p, _pair.q, _pair.dp, _pair.dq, _pair.qi)); +} + +KeyPair* RSAKeyPairGenerator::engineGenerateKeyPair() +{ + if (_srng) + { + randomGeneratorContextAdapter rngc(_srng); + + return genpair(&rngc); + } + else + { + randomGeneratorContext rngc(randomGeneratorDefault()); + + return genpair(&rngc); + } +} + +void RSAKeyPairGenerator::engineInitialize(const AlgorithmParameterSpec& spec, SecureRandom* random) throw (InvalidAlgorithmParameterException) +{ + const RSAKeyGenParameterSpec* rsaspec = dynamic_cast(&spec); + + if (rsaspec) + { + if (_spec) + delete _spec; + + _spec = new RSAKeyGenParameterSpec(rsaspec->getKeysize(), rsaspec->getPublicExponent()); + } + else + throw InvalidAlgorithmParameterException("not an RSAKeyGenParameterSpec"); +} + +void RSAKeyPairGenerator::engineInitialize(size_t keysize, SecureRandom* random) throw (InvalidParameterException) +{ + if (keysize < 512) + throw InvalidParameterException("Modulus size must be at least 512 bits"); + + _size = keysize; + if (_spec) + { + delete _spec; + _spec = 0; + } + _srng = random; +} diff --git a/beecrypt/c++/provider/RSAKeyPairGenerator.h b/beecrypt/c++/provider/RSAKeyPairGenerator.h new file mode 100644 index 0000000..d54eb4f --- /dev/null +++ b/beecrypt/c++/provider/RSAKeyPairGenerator.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file RSAKeyPairGenerator.h + * \ingroup CXX_PROV_m + */ + +#ifndef _CLASS_RSAKEYPAIRGENERATOR_H +#define _CLASS_RSAKEYPAIRGENERATOR_H + +#ifdef __cplusplus + +#include "beecrypt/c++/security/KeyPairGeneratorSpi.h" +using beecrypt::security::KeyPairGeneratorSpi; +using beecrypt::security::KeyPair; +#include "beecrypt/c++/security/SecureRandom.h" +using beecrypt::security::SecureRandom; +#include "beecrypt/c++/security/spec/RSAKeyGenParameterSpec.h" +using beecrypt::security::spec::RSAKeyGenParameterSpec; + +using beecrypt::security::InvalidAlgorithmParameterException; +using beecrypt::security::InvalidParameterException; + +namespace beecrypt { + namespace provider { + class RSAKeyPairGenerator : public KeyPairGeneratorSpi + { + private: + size_t _size; + RSAKeyGenParameterSpec* _spec; + SecureRandom* _srng; + + KeyPair* genpair(randomGeneratorContext*); + + protected: + virtual KeyPair* engineGenerateKeyPair(); + + virtual void engineInitialize(const AlgorithmParameterSpec&, SecureRandom*) throw (InvalidAlgorithmParameterException); + virtual void engineInitialize(size_t, SecureRandom*) throw (InvalidParameterException); + + public: + RSAKeyPairGenerator(); + virtual ~RSAKeyPairGenerator(); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/provider/RSAPrivateCrtKeyImpl.cxx b/beecrypt/c++/provider/RSAPrivateCrtKeyImpl.cxx new file mode 100644 index 0000000..c773335 --- /dev/null +++ b/beecrypt/c++/provider/RSAPrivateCrtKeyImpl.cxx @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/provider/RSAPrivateCrtKeyImpl.h" +#include "beecrypt/c++/provider/BeeKeyFactory.h" + +using namespace beecrypt::provider; + +RSAPrivateCrtKeyImpl::RSAPrivateCrtKeyImpl(const RSAPrivateCrtKey& copy) +{ + _n = copy.getModulus(); + _e = copy.getPublicExponent(); + _d = copy.getPrivateExponent(); + _p = copy.getPrimeP(); + _q = copy.getPrimeQ(); + _dp = copy.getPrimeExponentP(); + _dq = copy.getPrimeExponentQ(); + _qi = copy.getCrtCoefficient(); + _enc = 0; +} + +RSAPrivateCrtKeyImpl::RSAPrivateCrtKeyImpl(const mpbarrett& n, const mpnumber& e, const mpnumber& d, const mpbarrett& p, const mpbarrett& q, const mpnumber& dp, const mpnumber& dq, const mpnumber& qi) +{ + _n = n; + _e = e; + _d = d; + _p = p; + _q = q; + _dp = dp; + _dq = dq; + _qi = qi; + _enc = 0; +} + +RSAPrivateCrtKeyImpl::~RSAPrivateCrtKeyImpl() +{ + _d.wipe(); + _p.wipe(); + _q.wipe(); + _dp.wipe(); + _dq.wipe(); + _qi.wipe(); + if (_enc) + delete _enc; +} + +RSAPrivateCrtKey* RSAPrivateCrtKeyImpl::clone() const +{ + return new RSAPrivateCrtKeyImpl(*this); +} + +const mpbarrett& RSAPrivateCrtKeyImpl::getModulus() const throw () +{ + return _n; +} + +const mpnumber& RSAPrivateCrtKeyImpl::getPrivateExponent() const throw () +{ + return _d; +} + +const mpnumber& RSAPrivateCrtKeyImpl::getPublicExponent() const throw () +{ + return _e; +} + +const mpbarrett& RSAPrivateCrtKeyImpl::getPrimeP() const throw () +{ + return _p; +} + +const mpbarrett& RSAPrivateCrtKeyImpl::getPrimeQ() const throw () +{ + return _q; +} + +const mpnumber& RSAPrivateCrtKeyImpl::getPrimeExponentP() const throw () +{ + return _dp; +} + +const mpnumber& RSAPrivateCrtKeyImpl::getPrimeExponentQ() const throw () +{ + return _dq; +} + +const mpnumber& RSAPrivateCrtKeyImpl::getCrtCoefficient() const throw () +{ + return _qi; +} + +const bytearray* RSAPrivateCrtKeyImpl::getEncoded() const +{ + if (!_enc) + _enc = BeeKeyFactory::encode(*this); + + return _enc; +} + +const String& RSAPrivateCrtKeyImpl::getAlgorithm() const throw () +{ + static const String ALGORITHM = UNICODE_STRING_SIMPLE("RSA"); + return ALGORITHM; +} + +const String* RSAPrivateCrtKeyImpl::getFormat() const throw () +{ + static const String FORMAT = UNICODE_STRING_SIMPLE("BEE"); + return &FORMAT; +} diff --git a/beecrypt/c++/provider/RSAPrivateCrtKeyImpl.h b/beecrypt/c++/provider/RSAPrivateCrtKeyImpl.h new file mode 100644 index 0000000..2f7affe --- /dev/null +++ b/beecrypt/c++/provider/RSAPrivateCrtKeyImpl.h @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file RSAPrivateCrtKeyImpl.h + * \ingroup CXX_PROV_m + */ + +#ifndef _CLASS_RSAPRIVATECRTKEYIMPL_H +#define _CLASS_RSAPRIVATECRTKEYIMPL_H + +#ifdef __cplusplus + +#include "beecrypt/c++/security/interfaces/RSAPrivateCrtKey.h" +using beecrypt::security::interfaces::RSAPrivateCrtKey; + +namespace beecrypt { + namespace provider { + class RSAPrivateCrtKeyImpl : public RSAPrivateCrtKey + { + private: + mpbarrett _n; + mpnumber _e; + mpnumber _d; + mpbarrett _p; + mpbarrett _q; + mpnumber _dp; + mpnumber _dq; + mpnumber _qi; + mutable bytearray* _enc; + + public: + RSAPrivateCrtKeyImpl(const RSAPrivateCrtKey&); + RSAPrivateCrtKeyImpl(const mpbarrett& modulus, const mpnumber& publicExponent, const mpnumber& privateExponent, const mpbarrett& primeP, const mpbarrett& primeQ, const mpnumber& primeExponentP, const mpnumber& primeExponentQ, const mpnumber& crtCoefficient); + virtual ~RSAPrivateCrtKeyImpl(); + + virtual RSAPrivateCrtKey* clone() const; + + virtual const mpbarrett& getModulus() const throw (); + virtual const mpnumber& getPrivateExponent() const throw (); + virtual const mpnumber& getPublicExponent() const throw (); + virtual const mpbarrett& getPrimeP() const throw (); + virtual const mpbarrett& getPrimeQ() const throw (); + virtual const mpnumber& getPrimeExponentP() const throw (); + virtual const mpnumber& getPrimeExponentQ() const throw (); + virtual const mpnumber& getCrtCoefficient() const throw (); + + virtual const bytearray* getEncoded() const; + virtual const String& getAlgorithm() const throw (); + virtual const String* getFormat() const throw (); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/provider/RSAPrivateKeyImpl.cxx b/beecrypt/c++/provider/RSAPrivateKeyImpl.cxx new file mode 100644 index 0000000..663983d --- /dev/null +++ b/beecrypt/c++/provider/RSAPrivateKeyImpl.cxx @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/provider/RSAPrivateKeyImpl.h" +#include "beecrypt/c++/provider/BeeKeyFactory.h" + +using namespace beecrypt::provider; + +RSAPrivateKeyImpl::RSAPrivateKeyImpl(const RSAPrivateKey& copy) +{ + _n = copy.getModulus(); + _d = copy.getPrivateExponent(); + _enc = 0; +} + +RSAPrivateKeyImpl::RSAPrivateKeyImpl(const mpbarrett& n, const mpnumber& d) +{ + _n = n; + _d = d; + _enc = 0; +} + +RSAPrivateKeyImpl::~RSAPrivateKeyImpl() +{ + _d.wipe(); + if (_enc) + delete _enc; +} + +RSAPrivateKey* RSAPrivateKeyImpl::clone() const +{ + return new RSAPrivateKeyImpl(*this); +} + +const mpbarrett& RSAPrivateKeyImpl::getModulus() const throw () +{ + return _n; +} + +const mpnumber& RSAPrivateKeyImpl::getPrivateExponent() const throw () +{ + return _d; +} + +const bytearray* RSAPrivateKeyImpl::getEncoded() const +{ + if (!_enc) + _enc = BeeKeyFactory::encode(*this); + + return _enc; +} + +const String& RSAPrivateKeyImpl::getAlgorithm() const throw () +{ + static const String ALGORITHM = UNICODE_STRING_SIMPLE("RSA"); + return ALGORITHM; +} + +const String* RSAPrivateKeyImpl::getFormat() const throw () +{ + static const String FORMAT = UNICODE_STRING_SIMPLE("BEE"); + return &FORMAT; +} diff --git a/beecrypt/c++/provider/RSAPrivateKeyImpl.h b/beecrypt/c++/provider/RSAPrivateKeyImpl.h new file mode 100644 index 0000000..5b44f73 --- /dev/null +++ b/beecrypt/c++/provider/RSAPrivateKeyImpl.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file RSAPrivateKeyImpl.h + * \ingroup CXX_PROV_m + */ + +#ifndef _CLASS_RSAPRIVATEKEYIMPL_H +#define _CLASS_RSAPRIVATEKEYIMPL_H + +#ifdef __cplusplus + +#include "beecrypt/c++/security/interfaces/RSAPrivateKey.h" +using beecrypt::security::interfaces::RSAPrivateKey; + +namespace beecrypt { + namespace provider { + class RSAPrivateKeyImpl : public RSAPrivateKey + { + protected: + mpbarrett _n; + mpnumber _d; + mutable bytearray* _enc; + + public: + RSAPrivateKeyImpl(const RSAPrivateKey&); + RSAPrivateKeyImpl(const mpbarrett&, const mpnumber&); + virtual ~RSAPrivateKeyImpl(); + + virtual RSAPrivateKey* clone() const; + + virtual const mpbarrett& getModulus() const throw (); + virtual const mpnumber& getPrivateExponent() const throw (); + + virtual const bytearray* getEncoded() const; + virtual const String& getAlgorithm() const throw (); + virtual const String* getFormat() const throw (); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/provider/RSAPublicKeyImpl.cxx b/beecrypt/c++/provider/RSAPublicKeyImpl.cxx new file mode 100644 index 0000000..b4ea543 --- /dev/null +++ b/beecrypt/c++/provider/RSAPublicKeyImpl.cxx @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/provider/RSAPublicKeyImpl.h" +#include "beecrypt/c++/provider/BeeKeyFactory.h" + +using namespace beecrypt::provider; + +RSAPublicKeyImpl::RSAPublicKeyImpl(const RSAPublicKey& copy) +{ + _n = copy.getModulus(); + _e = copy.getPublicExponent(); + _enc = 0; +} + +RSAPublicKeyImpl::RSAPublicKeyImpl(const mpbarrett& n, const mpnumber& e) +{ + _n = n; + _e = e; + _enc = 0; +} + +RSAPublicKeyImpl::~RSAPublicKeyImpl() +{ + if (_enc) + delete _enc; +} + +RSAPublicKey* RSAPublicKeyImpl::clone() const +{ + return new RSAPublicKeyImpl(*this); +} + +const mpbarrett& RSAPublicKeyImpl::getModulus() const throw () +{ + return _n; +} + +const mpnumber& RSAPublicKeyImpl::getPublicExponent() const throw () +{ + return _e; +} + +const bytearray* RSAPublicKeyImpl::getEncoded() const +{ + if (!_enc) + _enc = BeeKeyFactory::encode(*this); + + return _enc; +} + +const String& RSAPublicKeyImpl::getAlgorithm() const throw () +{ + static const String ALGORITHM = UNICODE_STRING_SIMPLE("RSA"); + return ALGORITHM; +} + +const String* RSAPublicKeyImpl::getFormat() const throw () +{ + static const String FORMAT = UNICODE_STRING_SIMPLE("BEE"); + return &FORMAT; +} diff --git a/beecrypt/c++/provider/RSAPublicKeyImpl.h b/beecrypt/c++/provider/RSAPublicKeyImpl.h new file mode 100644 index 0000000..641ec0c --- /dev/null +++ b/beecrypt/c++/provider/RSAPublicKeyImpl.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file RSAPublicKeyImpl.h + * \ingroup CXX_PROV_m + */ + +#ifndef _CLASS_RSAPUBLICKEYIMPL_H +#define _CLASS_RSAPUBLICKEYIMPL_H + +#ifdef __cplusplus + +#include "beecrypt/c++/security/interfaces/RSAPublicKey.h" +using beecrypt::security::interfaces::RSAPublicKey; + +namespace beecrypt { + namespace provider { + class RSAPublicKeyImpl : public RSAPublicKey + { + private: + mpbarrett _n; + mpnumber _e; + mutable bytearray* _enc; + + public: + RSAPublicKeyImpl(const RSAPublicKey&); + RSAPublicKeyImpl(const mpbarrett&, const mpnumber&); + virtual ~RSAPublicKeyImpl(); + + virtual RSAPublicKey* clone() const; + + virtual const mpbarrett& getModulus() const throw (); + virtual const mpnumber& getPublicExponent() const throw (); + + virtual const bytearray* getEncoded() const; + virtual const String& getAlgorithm() const throw (); + virtual const String* getFormat() const throw (); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/provider/SHA1Digest.cxx b/beecrypt/c++/provider/SHA1Digest.cxx new file mode 100644 index 0000000..bf6a070 --- /dev/null +++ b/beecrypt/c++/provider/SHA1Digest.cxx @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/lang/NullPointerException.h" +using beecrypt::lang::NullPointerException; +#include "beecrypt/c++/provider/SHA1Digest.h" + +using namespace beecrypt::provider; + +SHA1Digest::SHA1Digest() : _digest(20) +{ + sha1Reset(&_param); +} + +SHA1Digest::~SHA1Digest() +{ +} + +SHA1Digest* SHA1Digest::clone() const +{ + SHA1Digest* result = new SHA1Digest(); + + memcpy(&result->_param, &_param, sizeof(sha1Param)); + + return result; +} + +const bytearray& SHA1Digest::engineDigest() +{ + sha1Digest(&_param, _digest.data()); + + return _digest; +} + +size_t SHA1Digest::engineDigest(byte* data, size_t offset, size_t length) throw (ShortBufferException) +{ + if (!data) + throw NullPointerException(); + + if (length < 20) + throw ShortBufferException(); + + sha1Digest(&_param, data); + + return 20; +} + +size_t SHA1Digest::engineGetDigestLength() +{ + return 20; +} + +void SHA1Digest::engineReset() +{ + sha1Reset(&_param); +} + +void SHA1Digest::engineUpdate(byte b) +{ + sha1Update(&_param, &b, 1); +} + +void SHA1Digest::engineUpdate(const byte* data, size_t offset, size_t length) +{ + sha1Update(&_param, data+offset, length); +} diff --git a/beecrypt/c++/provider/SHA1Digest.h b/beecrypt/c++/provider/SHA1Digest.h new file mode 100644 index 0000000..aec2fb3 --- /dev/null +++ b/beecrypt/c++/provider/SHA1Digest.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file SHA1Digest.h + * \ingroup CXX_PROV_m + */ + +#ifndef _CLASS_SHA1DIGEST_H +#define _CLASS_SHA1DIGEST_H + +#include "beecrypt/beecrypt.h" +#include "beecrypt/sha1.h" + +#ifdef __cplusplus + +#include "beecrypt/c++/security/MessageDigestSpi.h" +using beecrypt::security::MessageDigestSpi; + +namespace beecrypt { + namespace provider { + class SHA1Digest : public MessageDigestSpi + { + private: + sha1Param _param; + bytearray _digest; + + protected: + virtual const bytearray& engineDigest(); + virtual size_t engineDigest(byte*, size_t, size_t) throw (ShortBufferException); + virtual size_t engineGetDigestLength(); + virtual void engineReset(); + virtual void engineUpdate(byte); + virtual void engineUpdate(const byte*, size_t, size_t); + + public: + SHA1Digest(); + virtual ~SHA1Digest(); + + virtual SHA1Digest* clone() const; + + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/provider/SHA1withDSASignature.cxx b/beecrypt/c++/provider/SHA1withDSASignature.cxx new file mode 100644 index 0000000..6c5ca6d --- /dev/null +++ b/beecrypt/c++/provider/SHA1withDSASignature.cxx @@ -0,0 +1,411 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/adapter.h" +#include "beecrypt/c++/lang/NullPointerException.h" +using beecrypt::lang::NullPointerException; +#include "beecrypt/c++/provider/SHA1withDSASignature.h" +#include "beecrypt/c++/security/interfaces/DSAPrivateKey.h" +using beecrypt::security::interfaces::DSAPrivateKey; +#include "beecrypt/c++/security/interfaces/DSAPublicKey.h" +using beecrypt::security::interfaces::DSAPublicKey; + +namespace { + const byte TAG_SEQUENCE = 0x30; + const byte TAG_INTEGER = 0x02; + + typedef int asn1error; + + const asn1error DER_NOT_ENOUGH_DATA = -1; + const asn1error DER_IMPLICIT_TAG_LENGTH = -2; + const asn1error DER_TAG_TOO_LONG = -3; + const asn1error DER_FORMAT_ERROR = -4; + const asn1error DER_CONVERSION_ERROR = -5; + + /* compute the size of a DER length encoding */ + size_t asn1_der_length(size_t length) throw () + { + if (length < 0x80) + return 1; + if (length < 0x100) + return 2; + if (length < 0x10000) + return 3; + if (length < 0x1000000) + return 4; + else + return 5; + } + + size_t asn1_der_length_of(const mpnumber& n) throw () + { + size_t sigbits = mpbits(n.size, n.data); + + return ((sigbits + 7) >> 3) + (((sigbits & 7) == 0) ? 1 : 0); + } + + size_t asn1_der_length_of_rssig(const mpnumber& r, const mpnumber& s) throw () + { + size_t intlen, seqlen = 0; + + intlen = asn1_der_length_of(r); + + seqlen += 1 + asn1_der_length(intlen) + intlen; + + intlen = asn1_der_length_of(s); + + seqlen += 1 + asn1_der_length(intlen) + intlen; + + return 1 + asn1_der_length(seqlen) + seqlen; + } + + size_t asn1_der_encode_length(byte* data, size_t length) throw () + { + if (length < 0x80) + { + data[0] = (byte) length; + return 1; + } + else if (length < 0x100) + { + data[0] = (byte) 0x81; + data[1] = (byte) length; + return 2; + } + else if (length < 0x10000) + { + data[0] = (byte) 0x82; + data[1] = (byte) (length >> 8); + data[2] = (byte) (length ); + return 3; + } + else if (length < 0x1000000) + { + data[0] = (byte) 0x83; + data[1] = (byte) (length >> 16); + data[2] = (byte) (length >> 8); + data[3] = (byte) (length ); + return 4; + } + else + { + data[0] = (byte) 0x84; + data[1] = (byte) (length >> 24); + data[2] = (byte) (length >> 16); + data[3] = (byte) (length >> 8); + data[4] = (byte) (length ); + return 5; + } + } + + size_t asn1_der_decode_length(const byte* data, size_t size, size_t* length) throw (asn1error) + { + size_t length_bytes; + byte tmp; + + if (size == 0) + throw DER_NOT_ENOUGH_DATA; + + tmp = *(data++); + + if (tmp < 0x80) + { + *length = tmp; + length_bytes = 0; + } + else + { + byte length_bytes = tmp & 0x7f; + + if (length_bytes == 0) + throw DER_IMPLICIT_TAG_LENGTH; + + if (length_bytes >= size) + throw DER_NOT_ENOUGH_DATA; + + if (length_bytes > sizeof(size_t)) + throw DER_TAG_TOO_LONG; + + size_t temp = 0; + + for (byte i = 0; i < length_bytes; i++) + { + tmp = *(data++); + temp <<= 8; + temp += tmp; + } + + *length = temp; + } + return 1 + length_bytes; + } + + size_t asn1_der_encode(byte* data, const mpnumber& n) throw () + { + size_t offset = 1, length = asn1_der_length_of(n); + + data[0] = TAG_INTEGER; + + offset += asn1_der_encode_length(data+offset, length); + + i2osp(data+offset, length, n.data, n.size); + + offset += length; + + return offset; + } + + size_t asn1_der_decode(const byte* data, size_t size, mpnumber& n) throw (asn1error) + { + size_t length, offset = 1; + + if (size < 2) + throw DER_NOT_ENOUGH_DATA; + + if (data[0] != TAG_INTEGER) + throw DER_FORMAT_ERROR; + + offset += asn1_der_decode_length(data+offset, size-offset, &length); + + if (length > (size-offset)) + throw DER_NOT_ENOUGH_DATA; + + if (mpnsetbin(&n, data+offset, length)) + throw DER_CONVERSION_ERROR; + + offset += length; + + return offset; + } + + size_t asn1_der_encode_rssig(byte* data, const mpnumber& r, const mpnumber& s) throw () + { + size_t intlen, seqlen = 0; + + intlen = asn1_der_length_of(r); + seqlen += 1 + asn1_der_length(intlen) + intlen; + intlen = asn1_der_length_of(s); + seqlen += 1 + asn1_der_length(intlen) + intlen; + + *(data++) = TAG_SEQUENCE; + + data += asn1_der_encode_length(data, seqlen); + data += asn1_der_encode(data, r); + data += asn1_der_encode(data, s); + + return 1 + asn1_der_length(seqlen) + seqlen; + } + + size_t asn1_der_decode_rssig(const byte* data, size_t size, mpnumber& r, mpnumber& s) throw (asn1error) + { + size_t tmp, length, offset = 1; + + if (size < 2) + throw DER_NOT_ENOUGH_DATA; + + if (data[0] != TAG_SEQUENCE) + throw DER_FORMAT_ERROR; + + offset += asn1_der_decode_length(data+offset, size-offset, &length); + + if (length > (size-offset)) + throw DER_NOT_ENOUGH_DATA; + + tmp = asn1_der_decode(data+offset, length, r); + + offset += tmp; + length -= tmp; + + tmp = asn1_der_decode(data+offset, length, s); + + offset += tmp; + length -= tmp; + + if (length > 0) + throw DER_FORMAT_ERROR; + + return offset; + } +} + +using namespace beecrypt::provider; + +SHA1withDSASignature::SHA1withDSASignature() +{ +} + +SHA1withDSASignature::~SHA1withDSASignature() +{ +} + +AlgorithmParameters* SHA1withDSASignature::engineGetParameters() const +{ + return 0; +} + +void SHA1withDSASignature::engineSetParameter(const AlgorithmParameterSpec& spec) throw (InvalidAlgorithmParameterException) +{ + throw InvalidAlgorithmParameterException("not supported for this algorithm"); +} + +void SHA1withDSASignature::engineInitSign(const PrivateKey& key, SecureRandom* random) throw (InvalidKeyException) +{ + const DSAPrivateKey* dsa = dynamic_cast(&key); + + if (dsa) + { + /* copy key information */ + _params.p = dsa->getParams().getP(); + _params.q = dsa->getParams().getQ(); + _params.g = dsa->getParams().getG(); + _x = dsa->getX(); + + /* reset the hash function */ + sha1Reset(&_sp); + + _srng = random; + } + else + throw InvalidKeyException("key must be a DSAPrivateKey"); +} + +void SHA1withDSASignature::engineInitVerify(const PublicKey& key) throw (InvalidKeyException) +{ + const DSAPublicKey* dsa = dynamic_cast(&key); + + if (dsa) + { + /* copy key information */ + _params.p = dsa->getParams().getP(); + _params.q = dsa->getParams().getQ(); + _params.g = dsa->getParams().getG(); + _y = dsa->getY(); + + /* reset the hash function */ + sha1Reset(&_sp); + + _srng = 0; + } + else + throw InvalidKeyException("key must be a DSAPrivateKey"); +} + +void SHA1withDSASignature::engineUpdate(byte b) +{ + sha1Update(&_sp, &b, 1); +} + +void SHA1withDSASignature::engineUpdate(const byte* data, size_t offset, size_t len) +{ + sha1Update(&_sp, data+offset, len); +} + +void SHA1withDSASignature::rawsign(mpnumber& r, mpnumber& s) throw (SignatureException) +{ + mpnumber hm; + byte digest[20]; + + sha1Digest(&_sp, digest); + mpnsetbin(&hm, digest, 20); + + if (_srng) + { + randomGeneratorContextAdapter rngc(_srng); + if (dsasign(&_params.p, &_params.q, &_params.g, &rngc, &hm, &_x, &r, &s)) + throw SignatureException("internal error in dsasign function"); + } + else + { + randomGeneratorContext rngc(randomGeneratorDefault()); + if (dsasign(&_params.p, &_params.q, &_params.g, &rngc, &hm, &_x, &r, &s)) + throw SignatureException("internal error in dsasign function"); + } +} + +bool SHA1withDSASignature::rawvrfy(const mpnumber& r, const mpnumber& s) throw () +{ + mpnumber hm; + byte digest[20]; + + sha1Digest(&_sp, digest); + mpnsetbin(&hm, digest, 20); + + return dsavrfy(&_params.p, &_params.q, &_params.g, &hm, &_y, &r, &s); +} + +bytearray* SHA1withDSASignature::engineSign() throw (SignatureException) +{ + mpnumber r, s; + + rawsign(r, s); + + bytearray* signature = new bytearray(asn1_der_length_of_rssig(r, s)); + + asn1_der_encode_rssig(signature->data(), r, s); + + return signature; +} + +size_t SHA1withDSASignature::engineSign(byte* signature, size_t offset, size_t len) throw (ShortBufferException, SignatureException) +{ + if (!signature) + throw NullPointerException(); + + mpnumber r, s; + + rawsign(r, s); + + if (asn1_der_length_of_rssig(r, s) > (len - offset)) + throw ShortBufferException(); + + return asn1_der_encode_rssig(signature+offset, r, s); +} + +size_t SHA1withDSASignature::engineSign(bytearray& signature) throw (SignatureException) +{ + mpnumber r, s; + + rawsign(r, s); + + signature.resize(asn1_der_length_of_rssig(r, s)); + + return asn1_der_encode_rssig(signature.data(), r, s); +} + +bool SHA1withDSASignature::engineVerify(const byte* signature, size_t offset, size_t len) throw (SignatureException) +{ + if (!signature) + throw NullPointerException(); + + mpnumber r, s; + + try + { + asn1_der_decode_rssig(signature+offset, len-offset, r, s); + } + catch (asn1error ae) + { + throw SignatureException("invalid signature"); + } + + return rawvrfy(r, s); +} diff --git a/beecrypt/c++/provider/SHA1withDSASignature.h b/beecrypt/c++/provider/SHA1withDSASignature.h new file mode 100644 index 0000000..f62b27f --- /dev/null +++ b/beecrypt/c++/provider/SHA1withDSASignature.h @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file SHA1withDSASignature.h + * \ingroup CXX_PROV_m + */ + +#ifndef _CLASS_SHA1WITHDSASIGNATURE_H +#define _CLASS_SHA1WITHDSASIGNATURE_H + +#include "beecrypt/api.h" +#include "beecrypt/dsa.h" +#include "beecrypt/sha1.h" + +#ifdef __cplusplus + +#include "beecrypt/c++/security/SignatureSpi.h" +using beecrypt::security::SecureRandom; +using beecrypt::security::SignatureSpi; +using beecrypt::security::AlgorithmParameters; +using beecrypt::security::InvalidAlgorithmParameterException; +using beecrypt::security::InvalidKeyException; +using beecrypt::security::PrivateKey; +using beecrypt::security::PublicKey; +using beecrypt::security::ShortBufferException; +using beecrypt::security::SignatureException; +using beecrypt::security::spec::AlgorithmParameterSpec; + +namespace beecrypt { + namespace provider { + class SHA1withDSASignature : public SignatureSpi + { + friend class BeeCryptProvider; + + private: + dsaparam _params; + mpnumber _x; + mpnumber _y; + sha1Param _sp; + SecureRandom* _srng; + + void rawsign(mpnumber &r, mpnumber&s) throw (SignatureException); + bool rawvrfy(const mpnumber &r, const mpnumber&s) throw (); + + protected: + virtual AlgorithmParameters* engineGetParameters() const; + virtual void engineSetParameter(const AlgorithmParameterSpec&) throw (InvalidAlgorithmParameterException); + + virtual void engineInitSign(const PrivateKey&, SecureRandom*) throw (InvalidKeyException); + virtual void engineInitVerify(const PublicKey&) throw (InvalidKeyException); + + virtual bytearray* engineSign() throw (SignatureException); + virtual size_t engineSign(byte*, size_t, size_t) throw (ShortBufferException, SignatureException); + virtual size_t engineSign(bytearray&) throw (SignatureException); + virtual bool engineVerify(const byte*, size_t, size_t) throw (SignatureException); + + virtual void engineUpdate(byte); + virtual void engineUpdate(const byte*, size_t, size_t); + + public: + SHA1withDSASignature(); + virtual ~SHA1withDSASignature(); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/provider/SHA1withRSASignature.cxx b/beecrypt/c++/provider/SHA1withRSASignature.cxx new file mode 100644 index 0000000..7d1b41b --- /dev/null +++ b/beecrypt/c++/provider/SHA1withRSASignature.cxx @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/provider/SHA1withRSASignature.h" +#include "beecrypt/sha1.h" + +using namespace beecrypt::provider; + +SHA1withRSASignature::SHA1withRSASignature() : PKCS1RSASignature(&sha1) +{ +} + +SHA1withRSASignature::~SHA1withRSASignature() +{ +} diff --git a/beecrypt/c++/provider/SHA1withRSASignature.h b/beecrypt/c++/provider/SHA1withRSASignature.h new file mode 100644 index 0000000..f929c4e --- /dev/null +++ b/beecrypt/c++/provider/SHA1withRSASignature.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file SHA1withRSASignature.h + * \ingroup CXX_PROV_m + */ + +#ifndef _CLASS_SHA1WITHRSASIGNATURE_H +#define _CLASS_SHA1WITHRSASIGNATURE_H + +#ifdef __cplusplus + +#include "beecrypt/c++/provider/PKCS1RSASignature.h" + +namespace beecrypt { + namespace provider { + class SHA1withRSASignature : public PKCS1RSASignature + { + public: + SHA1withRSASignature(); + ~SHA1withRSASignature(); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/provider/SHA256withRSASignature.cxx b/beecrypt/c++/provider/SHA256withRSASignature.cxx new file mode 100644 index 0000000..12f4878 --- /dev/null +++ b/beecrypt/c++/provider/SHA256withRSASignature.cxx @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/provider/SHA256withRSASignature.h" + +#include "beecrypt/sha256.h" + +using namespace beecrypt::provider; + +SHA256withRSASignature::SHA256withRSASignature() : PKCS1RSASignature(&sha256) +{ +} + +SHA256withRSASignature::~SHA256withRSASignature() +{ +} diff --git a/beecrypt/c++/provider/SHA256withRSASignature.h b/beecrypt/c++/provider/SHA256withRSASignature.h new file mode 100644 index 0000000..252c55b --- /dev/null +++ b/beecrypt/c++/provider/SHA256withRSASignature.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file SHA256withRSASignature.h + * \ingroup CXX_PROV_m + */ + +#ifndef _CLASS_SHA256WITHRSASIGNATURE_H +#define _CLASS_SHA256WITHRSASIGNATURE_H + +#ifdef __cplusplus + +#include "beecrypt/c++/provider/PKCS1RSASignature.h" + +namespace beecrypt { + namespace provider { + class SHA256withRSASignature : public PKCS1RSASignature + { + public: + SHA256withRSASignature(); + ~SHA256withRSASignature(); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/resource.cxx b/beecrypt/c++/resource.cxx new file mode 100644 index 0000000..d459717 --- /dev/null +++ b/beecrypt/c++/resource.cxx @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#include "beecrypt/c++/resource.h" + +#if WIN32 +const char* BEECRYPT_CONF_FILE = "beecrypt.conf"; +#else +const char* BEECRYPT_CONF_FILE = "/etc/beecrypt.conf"; +#endif diff --git a/beecrypt/c++/resource.h b/beecrypt/c++/resource.h new file mode 100644 index 0000000..e3f62c3 --- /dev/null +++ b/beecrypt/c++/resource.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file resource.h + * \author Bob Deblier + * \ingroup CXX_m + */ + +#ifndef _BEECRYPT_RESOURCE_H +#define _BEECRYPT_RESOURCE_H + +#include "beecrypt/api.h" + +extern const char* BEECRYPT_CONF_FILE; + +#endif diff --git a/beecrypt/c++/security/AlgorithmParameterGenerator.cxx b/beecrypt/c++/security/AlgorithmParameterGenerator.cxx new file mode 100644 index 0000000..ab004f2 --- /dev/null +++ b/beecrypt/c++/security/AlgorithmParameterGenerator.cxx @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/security/AlgorithmParameterGenerator.h" +#include "beecrypt/c++/security/AlgorithmParameterGeneratorSpi.h" +#include "beecrypt/c++/security/AlgorithmParameters.h" +#include "beecrypt/c++/security/Provider.h" +#include "beecrypt/c++/security/Security.h" +#include "beecrypt/c++/security/spec/AlgorithmParameterSpec.h" + +using namespace beecrypt::security; + +AlgorithmParameterGenerator::AlgorithmParameterGenerator(AlgorithmParameterGeneratorSpi* spi, const String& algorithm, const Provider& provider) +{ + _aspi = spi; + _algo = algorithm; + _prov = &provider; +} + +AlgorithmParameterGenerator::~AlgorithmParameterGenerator() +{ + delete _aspi; +} + +AlgorithmParameterGenerator* AlgorithmParameterGenerator::getInstance(const String& algorithm) throw (NoSuchAlgorithmException) +{ + Security::spi* tmp = Security::getSpi(algorithm, "AlgorithmParameterGenerator"); + + AlgorithmParameterGenerator* result = new AlgorithmParameterGenerator((AlgorithmParameterGeneratorSpi*) tmp->cspi, tmp->name, tmp->prov); + + delete tmp; + + return result; +} + +AlgorithmParameterGenerator* AlgorithmParameterGenerator::getInstance(const String& algorithm, const String& provider) throw (NoSuchAlgorithmException, NoSuchProviderException) +{ + Security::spi* tmp = Security::getSpi(algorithm, "AlgorithmParameterGenerator", provider); + + AlgorithmParameterGenerator* result = new AlgorithmParameterGenerator((AlgorithmParameterGeneratorSpi*) tmp->cspi, tmp->name, tmp->prov); + + delete tmp; + + return result; +} + +AlgorithmParameterGenerator* AlgorithmParameterGenerator::getInstance(const String& algorithm, const Provider& provider) throw (NoSuchAlgorithmException) +{ + Security::spi* tmp = Security::getSpi(algorithm, "AlgorithmParameterGenerator", provider); + + AlgorithmParameterGenerator* result = new AlgorithmParameterGenerator((AlgorithmParameterGeneratorSpi*) tmp->cspi, tmp->name, tmp->prov); + + delete tmp; + + return result; +} + +AlgorithmParameters* AlgorithmParameterGenerator::generateParameters() throw (InvalidAlgorithmParameterException) +{ + return _aspi->engineGenerateParameters(); +} + +void AlgorithmParameterGenerator::init(const AlgorithmParameterSpec& genParamSpec) throw (InvalidAlgorithmParameterException) +{ + _aspi->engineInit(genParamSpec, 0); +} + +void AlgorithmParameterGenerator::init(const AlgorithmParameterSpec& genParamSpec, SecureRandom* random) throw (InvalidAlgorithmParameterException) +{ + _aspi->engineInit(genParamSpec, random); +} + +void AlgorithmParameterGenerator::init(size_t size) throw (InvalidParameterException) +{ + _aspi->engineInit(size, 0); +} + +void AlgorithmParameterGenerator::init(size_t size, SecureRandom* random) throw (InvalidParameterException) +{ + _aspi->engineInit(size, random); +} + +const String& AlgorithmParameterGenerator::getAlgorithm() const throw () +{ + return _algo; +} + +const Provider& AlgorithmParameterGenerator::getProvider() const throw () +{ + return *_prov; +} diff --git a/beecrypt/c++/security/AlgorithmParameterGenerator.h b/beecrypt/c++/security/AlgorithmParameterGenerator.h new file mode 100644 index 0000000..61ae19f --- /dev/null +++ b/beecrypt/c++/security/AlgorithmParameterGenerator.h @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file AlgorithmParameterGenerator.h + * \author Bob Deblier + * \ingroup CXX_SECURITY_m + */ + +#ifndef _CLASS_ALGORITHMPARAMETERGENERATOR_H +#define _CLASS_ALGORITHMPARAMETERGENERATOR_H + +// #include "beecrypt/api.h" + +#ifdef __cplusplus + +#include "beecrypt/c++/security/AlgorithmParameterGeneratorSpi.h" +using beecrypt::security::AlgorithmParameterGeneratorSpi; +#include "beecrypt/c++/security/Provider.h" +using beecrypt::security::Provider; +#include "beecrypt/c++/security/NoSuchAlgorithmException.h" +using beecrypt::security::NoSuchAlgorithmException; +#include "beecrypt/c++/security/NoSuchProviderException.h" +using beecrypt::security::NoSuchProviderException; + +namespace beecrypt { + namespace security { + class BEECRYPTCXXAPI AlgorithmParameterGenerator + { + public: + static AlgorithmParameterGenerator* getInstance(const String&) throw (NoSuchAlgorithmException); + static AlgorithmParameterGenerator* getInstance(const String&, const String&) throw (NoSuchAlgorithmException, NoSuchProviderException); + static AlgorithmParameterGenerator* getInstance(const String&, const Provider&) throw (NoSuchAlgorithmException); + + private: + AlgorithmParameterGeneratorSpi* _aspi; + String _algo; + const Provider* _prov; + + protected: + AlgorithmParameterGenerator(AlgorithmParameterGeneratorSpi*, const String&, const Provider&); + + public: + ~AlgorithmParameterGenerator(); + + AlgorithmParameters* generateParameters() throw (InvalidAlgorithmParameterException); + + void init(const AlgorithmParameterSpec&) throw (InvalidAlgorithmParameterException); + void init(const AlgorithmParameterSpec&, SecureRandom*) throw (InvalidAlgorithmParameterException); + void init(size_t) throw (InvalidParameterException); + void init(size_t, SecureRandom*) throw (InvalidParameterException); + + const String& getAlgorithm() const throw (); + const Provider& getProvider() const throw (); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/AlgorithmParameterGeneratorSpi.h b/beecrypt/c++/security/AlgorithmParameterGeneratorSpi.h new file mode 100644 index 0000000..17a60e4 --- /dev/null +++ b/beecrypt/c++/security/AlgorithmParameterGeneratorSpi.h @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file AlgorithmParameterGeneratorSpi.h + * \ingroup CXX_SECURITY_m + */ + +#ifndef _CLASS_ALGORITHMPARAMETERGENERATORSPI_H +#define _CLASS_ALGORITHMPARAMETERGENERATORSPI_H + +#include "beecrypt/api.h" + +#ifdef __cplusplus + +#include "beecrypt/c++/security/AlgorithmParameters.h" +using beecrypt::security::AlgorithmParameters; +#include "beecrypt/c++/security/SecureRandom.h" +using beecrypt::security::SecureRandom; +#include "beecrypt/c++/security/InvalidAlgorithmParameterException.h" +using beecrypt::security::InvalidAlgorithmParameterException; +#include "beecrypt/c++/security/InvalidParameterException.h" +using beecrypt::security::InvalidParameterException; +#include "beecrypt/c++/security/spec/AlgorithmParameterSpec.h" +using beecrypt::security::spec::AlgorithmParameterSpec; + +#include +using std::type_info; + +namespace beecrypt { + namespace security { + class BEECRYPTCXXAPI AlgorithmParameterGeneratorSpi + { + friend class BEECRYPTCXXAPI AlgorithmParameterGenerator; + + protected: + virtual AlgorithmParameters* engineGenerateParameters() = 0; + virtual void engineInit(const AlgorithmParameterSpec&, SecureRandom*) throw (InvalidAlgorithmParameterException) = 0; + virtual void engineInit(size_t, SecureRandom*) throw (InvalidParameterException) = 0; + + public: + virtual ~AlgorithmParameterGeneratorSpi() {}; + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/AlgorithmParameters.cxx b/beecrypt/c++/security/AlgorithmParameters.cxx new file mode 100644 index 0000000..e61e872 --- /dev/null +++ b/beecrypt/c++/security/AlgorithmParameters.cxx @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/security/AlgorithmParameters.h" +#include "beecrypt/c++/security/AlgorithmParametersSpi.h" +#include "beecrypt/c++/security/Provider.h" +#include "beecrypt/c++/security/Security.h" +#include "beecrypt/c++/security/spec/AlgorithmParameterSpec.h" +using beecrypt::security::spec::AlgorithmParameterSpec; + +using namespace beecrypt::security; + +AlgorithmParameters::AlgorithmParameters(AlgorithmParametersSpi* spi, const String& algorithm, const Provider& provider) +{ + _aspi = spi; + _algo = algorithm; + _prov = &provider; +} + +AlgorithmParameters::~AlgorithmParameters() +{ + delete _aspi; +} + +AlgorithmParameters* AlgorithmParameters::getInstance(const String& algorithm) throw (NoSuchAlgorithmException) +{ + Security::spi* tmp = Security::getSpi(algorithm, "AlgorithmParameters"); + + AlgorithmParameters* result = new AlgorithmParameters((AlgorithmParametersSpi*) tmp->cspi, tmp->name, tmp->prov); + + delete tmp; + + return result; +} + +AlgorithmParameters* AlgorithmParameters::getInstance(const String& algorithm, const String& provider) throw (NoSuchAlgorithmException, NoSuchProviderException) +{ + Security::spi* tmp = Security::getSpi(algorithm, "AlgorithmParameters", provider); + + AlgorithmParameters* result = new AlgorithmParameters((AlgorithmParametersSpi*) tmp->cspi, tmp->name, tmp->prov); + + delete tmp; + + return result; +} + +AlgorithmParameters* AlgorithmParameters::getInstance(const String& algorithm, const Provider& provider) throw (NoSuchAlgorithmException) +{ + Security::spi* tmp = Security::getSpi(algorithm, "AlgorithmParameters", provider); + + AlgorithmParameters* result = new AlgorithmParameters((AlgorithmParametersSpi*) tmp->cspi, tmp->name, tmp->prov); + + delete tmp; + + return result; +} + +AlgorithmParameterSpec* AlgorithmParameters::getParameterSpec(const type_info& info) throw (InvalidParameterSpecException) +{ + return _aspi->engineGetParameterSpec(info); +} + +void AlgorithmParameters::init(const AlgorithmParameterSpec& spec) throw (InvalidParameterSpecException) +{ + _aspi->engineInit(spec); +} + +void AlgorithmParameters::init(const byte* data, size_t size) +{ + _aspi->engineInit(data, size); +} + +void AlgorithmParameters::init(const byte* data, size_t size, const String& format) +{ + _aspi->engineInit(data, size, format); +} + +const String& AlgorithmParameters::getAlgorithm() const throw () +{ + return _algo; +} + +const Provider& AlgorithmParameters::getProvider() const throw () +{ + return *_prov; +} diff --git a/beecrypt/c++/security/AlgorithmParameters.h b/beecrypt/c++/security/AlgorithmParameters.h new file mode 100644 index 0000000..13300c8 --- /dev/null +++ b/beecrypt/c++/security/AlgorithmParameters.h @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file AlgorithmParameters.h + * \ingroup CXX_SECURITY_m + */ + +#ifndef _CLASS_ALGORITHMPARAMETERS_H +#define _CLASS_ALGORITHMPARAMETERS_H + +// #include "beecrypt/api.h" + +#ifdef __cplusplus + +#include "beecrypt/c++/security/AlgorithmParametersSpi.h" +using beecrypt::security::AlgorithmParametersSpi; +#include "beecrypt/c++/security/Provider.h" +using beecrypt::security::Provider; +#include "beecrypt/c++/security/NoSuchAlgorithmException.h" +using beecrypt::security::NoSuchAlgorithmException; +#include "beecrypt/c++/security/NoSuchProviderException.h" +using beecrypt::security::NoSuchProviderException; + +#include +using std::type_info; + +namespace beecrypt { + namespace security { + class BEECRYPTCXXAPI AlgorithmParameters + { + public: + static AlgorithmParameters* getInstance(const String&) throw (NoSuchAlgorithmException); + static AlgorithmParameters* getInstance(const String&, const String&) throw (NoSuchAlgorithmException, NoSuchProviderException); + static AlgorithmParameters* getInstance(const String&, const Provider&) throw (NoSuchAlgorithmException); + + private: + AlgorithmParametersSpi* _aspi; + String _algo; + const Provider* _prov; + + protected: + AlgorithmParameters(AlgorithmParametersSpi*, const String&, const Provider&); + + public: + ~AlgorithmParameters(); + + AlgorithmParameterSpec* getParameterSpec(const type_info&) throw (InvalidParameterSpecException); + + void init(const AlgorithmParameterSpec&) throw (InvalidParameterSpecException); + void init(const byte*, size_t); + void init(const byte*, size_t, const String&); + + const String& getAlgorithm() const throw (); + const Provider& getProvider() const throw (); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/AlgorithmParametersSpi.h b/beecrypt/c++/security/AlgorithmParametersSpi.h new file mode 100644 index 0000000..8374108 --- /dev/null +++ b/beecrypt/c++/security/AlgorithmParametersSpi.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file AlgorithmParametersSpi.h + * \ingroup CXX_SECURITY_m + */ + +#ifndef _CLASS_ALGORITHMPARAMETERSSPI_H +#define _CLASS_ALGORITHMPARAMETERSSPI_H + +#include "beecrypt/api.h" + +#ifdef __cplusplus + +#include "beecrypt/c++/security/spec/AlgorithmParameterSpec.h" +using beecrypt::security::spec::AlgorithmParameterSpec; +#include "beecrypt/c++/security/spec/InvalidParameterSpecException.h" +using beecrypt::security::spec::InvalidParameterSpecException; + +#include +using std::type_info; + +namespace beecrypt { + namespace security { + class BEECRYPTCXXAPI AlgorithmParametersSpi + { + friend class BEECRYPTCXXAPI AlgorithmParameters; + + protected: + virtual AlgorithmParameterSpec* engineGetParameterSpec(const type_info&) = 0; + + virtual void engineInit(const AlgorithmParameterSpec&) throw (InvalidParameterSpecException) = 0; + virtual void engineInit(const byte*, size_t) = 0; + virtual void engineInit(const byte*, size_t, const String&) = 0; + + public: + virtual ~AlgorithmParametersSpi() {}; + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/DigestInputStream.cxx b/beecrypt/c++/security/DigestInputStream.cxx new file mode 100644 index 0000000..5b73259 --- /dev/null +++ b/beecrypt/c++/security/DigestInputStream.cxx @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/lang/NullPointerException.h" +using beecrypt::lang::NullPointerException; +#include "beecrypt/c++/security/DigestInputStream.h" + +using namespace beecrypt::security; + +DigestInputStream::DigestInputStream(InputStream& in, MessageDigest& m) : FilterInputStream(in), digest(m) +{ + _on = true; +} + +DigestInputStream::~DigestInputStream() +{ +} + +int DigestInputStream::read() throw (IOException) +{ + int rc = in.read(); + if (rc >= 0 && _on) + digest.update((byte) rc); + return rc; +} + +int DigestInputStream::read(byte *data, size_t offset, size_t length) throw (IOException) +{ + if (!data) + throw NullPointerException(); + + int rc = in.read(data, offset, length); + if (rc >= 0 && _on) + digest.update(data, offset, rc); + return rc; +} + +void DigestInputStream::on(bool on) +{ + _on = on; +} + +MessageDigest& DigestInputStream::getMessageDigest() +{ + return digest; +} + +void DigestInputStream::setMessageDigest(MessageDigest& m) +{ + digest = m; +} diff --git a/beecrypt/c++/security/DigestInputStream.h b/beecrypt/c++/security/DigestInputStream.h new file mode 100644 index 0000000..52ed2ac --- /dev/null +++ b/beecrypt/c++/security/DigestInputStream.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file DigestInputStream.h + * \ingroup CXX_SECURITY_m + */ + +#ifndef _CLASS_DIGESTINPUTSTREAM_H +#define _CLASS_DIGESTINPUTSTREAM_H + +#ifdef __cplusplus + +#include "beecrypt/c++/io/FilterInputStream.h" +using beecrypt::io::FilterInputStream; +#include "beecrypt/c++/security/MessageDigest.h" +using beecrypt::security::MessageDigest; + +namespace beecrypt { + namespace security { + class BEECRYPTCXXAPI DigestInputStream : public FilterInputStream + { + private: + bool _on; + + protected: + MessageDigest& digest; + + public: + DigestInputStream(InputStream&, MessageDigest&); + virtual ~DigestInputStream(); + + virtual int read() throw (IOException); + virtual int read(byte* data, size_t offset, size_t length) throw (IOException); + + void on(bool); + + MessageDigest& getMessageDigest(); + void setMessageDigest(MessageDigest&); + }; + } +} + +#endif + +#endif + diff --git a/beecrypt/c++/security/DigestOutputStream.cxx b/beecrypt/c++/security/DigestOutputStream.cxx new file mode 100644 index 0000000..6899695 --- /dev/null +++ b/beecrypt/c++/security/DigestOutputStream.cxx @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/lang/NullPointerException.h" +using beecrypt::lang::NullPointerException; +#include "beecrypt/c++/security/DigestOutputStream.h" + +using namespace beecrypt::security; + +DigestOutputStream::DigestOutputStream(OutputStream& out, MessageDigest& m) : FilterOutputStream(out), digest(m) +{ + _on = true; +} + +DigestOutputStream::~DigestOutputStream() +{ +} + +void DigestOutputStream::write(byte b) throw (IOException) +{ + out.write(b); + if (_on) + digest.update(b); +} + +void DigestOutputStream::write(const byte *data, size_t offset, size_t length) throw (IOException) +{ + if (!data) + throw NullPointerException(); + + out.write(data, offset, length); + if (_on) + digest.update(data, offset, length); +} + +void DigestOutputStream::on(bool on) +{ + _on = on; +} + +MessageDigest& DigestOutputStream::getMessageDigest() +{ + return digest; +} + +void DigestOutputStream::setMessageDigest(MessageDigest& m) +{ + digest = m; +} diff --git a/beecrypt/c++/security/DigestOutputStream.h b/beecrypt/c++/security/DigestOutputStream.h new file mode 100644 index 0000000..b37686f --- /dev/null +++ b/beecrypt/c++/security/DigestOutputStream.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file DigestOutputStream.h + * \ingroup CXX_SECURITY_m + */ + +#ifndef _CLASS_DIGESTOUTPUTSTREAM_H +#define _CLASS_DIGESTOUTPUTSTREAM_H + +#ifdef __cplusplus + +#include "beecrypt/c++/io/FilterOutputStream.h" +using beecrypt::io::FilterOutputStream; +#include "beecrypt/c++/security/MessageDigest.h" +using beecrypt::security::MessageDigest; + +namespace beecrypt { + namespace security { + class BEECRYPTCXXAPI DigestOutputStream : public FilterOutputStream + { + private: + bool _on; + + protected: + MessageDigest& digest; + + public: + DigestOutputStream(OutputStream&, MessageDigest&); + virtual ~DigestOutputStream(); + + virtual void write(byte) throw (IOException); + virtual void write(const byte* data, size_t offset, size_t length) throw (IOException); + + void on(bool); + + MessageDigest& getMessageDigest(); + void setMessageDigest(MessageDigest&); + }; + } +} + +#endif + +#endif + diff --git a/beecrypt/c++/security/GeneralSecurityException.cxx b/beecrypt/c++/security/GeneralSecurityException.cxx new file mode 100644 index 0000000..d482812 --- /dev/null +++ b/beecrypt/c++/security/GeneralSecurityException.cxx @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/security/GeneralSecurityException.h" + +using namespace beecrypt::security; + +GeneralSecurityException::GeneralSecurityException() throw () +{ +} + +GeneralSecurityException::GeneralSecurityException(const String& message) throw () : Exception(message) +{ +} diff --git a/beecrypt/c++/security/GeneralSecurityException.h b/beecrypt/c++/security/GeneralSecurityException.h new file mode 100644 index 0000000..c20c117 --- /dev/null +++ b/beecrypt/c++/security/GeneralSecurityException.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file GeneralSecurityException.h + * \ingroup CXX_SECURITY_m + */ + +#ifndef _CLASS_GENERALSECURITYEXCEPTION_H +#define _CLASS_GENERALSECURITYEXCEPTION_H + +#ifdef __cplusplus + +#include "beecrypt/c++/lang/Exception.h" +using beecrypt::lang::Exception; + +namespace beecrypt { + namespace security { + class BEECRYPTCXXAPI GeneralSecurityException : public Exception + { + public: + GeneralSecurityException() throw (); + GeneralSecurityException(const String&) throw (); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/InvalidAlgorithmParameterException.cxx b/beecrypt/c++/security/InvalidAlgorithmParameterException.cxx new file mode 100644 index 0000000..1ec0639 --- /dev/null +++ b/beecrypt/c++/security/InvalidAlgorithmParameterException.cxx @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/security/InvalidAlgorithmParameterException.h" + +using namespace beecrypt::security; + +InvalidAlgorithmParameterException::InvalidAlgorithmParameterException() throw () +{ +} + +InvalidAlgorithmParameterException::InvalidAlgorithmParameterException(const String& message) throw () : GeneralSecurityException(message) +{ +} diff --git a/beecrypt/c++/security/InvalidAlgorithmParameterException.h b/beecrypt/c++/security/InvalidAlgorithmParameterException.h new file mode 100644 index 0000000..5af09b5 --- /dev/null +++ b/beecrypt/c++/security/InvalidAlgorithmParameterException.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file InvalidAlgorithmParameterException.h + * \ingroup CXX_SECURITY_m + */ + +#ifndef _CLASS_INVALIDALGORITHMPARAMETEREXCEPTION_H +#define _CLASS_INVALIDALGORITHMPARAMETEREXCEPTION_H + +#ifdef __cplusplus + +#include "beecrypt/c++/security/GeneralSecurityException.h" +using beecrypt::security::GeneralSecurityException; + +namespace beecrypt { + namespace security { + class BEECRYPTCXXAPI InvalidAlgorithmParameterException : public GeneralSecurityException + { + public: + InvalidAlgorithmParameterException() throw (); + InvalidAlgorithmParameterException(const String&) throw (); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/InvalidKeyException.cxx b/beecrypt/c++/security/InvalidKeyException.cxx new file mode 100644 index 0000000..6f5bad2 --- /dev/null +++ b/beecrypt/c++/security/InvalidKeyException.cxx @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/security/InvalidKeyException.h" + +using namespace beecrypt::security; + +InvalidKeyException::InvalidKeyException() throw () +{ +} + +InvalidKeyException::InvalidKeyException(const String& message) throw () : KeyException(message) +{ +} diff --git a/beecrypt/c++/security/InvalidKeyException.h b/beecrypt/c++/security/InvalidKeyException.h new file mode 100644 index 0000000..2aa58ed --- /dev/null +++ b/beecrypt/c++/security/InvalidKeyException.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file InvalidKeyException.h + * \ingroup CXX_SECURITY_m + */ + +#ifndef _CLASS_INVALIDKEYEXCEPTION_H +#define _CLASS_INVALIDKEYEXCEPTION_H + +#ifdef __cplusplus + +#include "beecrypt/c++/security/KeyException.h" +using beecrypt::security::KeyException; + +namespace beecrypt { + namespace security { + class BEECRYPTCXXAPI InvalidKeyException : public KeyException + { + public: + InvalidKeyException() throw (); + InvalidKeyException(const String&) throw (); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/InvalidParameterException.cxx b/beecrypt/c++/security/InvalidParameterException.cxx new file mode 100644 index 0000000..0494334 --- /dev/null +++ b/beecrypt/c++/security/InvalidParameterException.cxx @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/security/InvalidParameterException.h" + +using namespace beecrypt::security; + +InvalidParameterException::InvalidParameterException() throw () +{ +} + +InvalidParameterException::InvalidParameterException(const String& message) throw () : IllegalArgumentException(message) +{ +} diff --git a/beecrypt/c++/security/InvalidParameterException.h b/beecrypt/c++/security/InvalidParameterException.h new file mode 100644 index 0000000..1a96a89 --- /dev/null +++ b/beecrypt/c++/security/InvalidParameterException.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file InvalidParameterException.h + * \ingroup CXX_SECURITY_m + */ + +#ifndef _CLASS_INVALIDPARAMETEREXCEPTION_H +#define _CLASS_INVALIDPARAMETEREXCEPTION_H + +#ifdef __cplusplus + +#include "beecrypt/c++/lang/IllegalArgumentException.h" +using beecrypt::lang::IllegalArgumentException; + +namespace beecrypt { + namespace security { + class BEECRYPTCXXAPI InvalidParameterException : public IllegalArgumentException + { + public: + InvalidParameterException() throw (); + InvalidParameterException(const String&) throw (); + }; + } +} +#endif + +#endif diff --git a/beecrypt/c++/security/Key.h b/beecrypt/c++/security/Key.h new file mode 100644 index 0000000..4ca88b1 --- /dev/null +++ b/beecrypt/c++/security/Key.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file Key.h + * \ingroup CXX_SECURITY_m + */ + +#ifndef _INTERFACE_KEY_H +#define _INTERFACE_KEY_H + +#ifdef __cplusplus + +#include "beecrypt/c++/array.h" +using beecrypt::bytearray; +#include "beecrypt/c++/lang/String.h" +using beecrypt::lang::String; + +namespace beecrypt { + namespace security { + /*!\brief The top-level interface for all keys. + * \ingroup CXX_IF_m + */ + class BEECRYPTCXXAPI Key + { + public: + virtual ~Key() {}; + + virtual Key* clone() const = 0; + + virtual const bytearray* getEncoded() const = 0; + + virtual const String& getAlgorithm() const throw () = 0; + virtual const String* getFormat() const throw () = 0; + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/KeyException.cxx b/beecrypt/c++/security/KeyException.cxx new file mode 100644 index 0000000..b42da20 --- /dev/null +++ b/beecrypt/c++/security/KeyException.cxx @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/security/KeyException.h" + +using namespace beecrypt::security; + +KeyException::KeyException() throw () +{ +} + +KeyException::KeyException(const String& message) throw () : GeneralSecurityException(message) +{ +} diff --git a/beecrypt/c++/security/KeyException.h b/beecrypt/c++/security/KeyException.h new file mode 100644 index 0000000..4b02faf --- /dev/null +++ b/beecrypt/c++/security/KeyException.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file KeyException.h + * \ingroup CXX_SECURITY_m + */ + +#ifndef _CLASS_KEYEXCEPTION_H +#define _CLASS_KEYEXCEPTION_H + +#ifdef __cplusplus + +#include "beecrypt/c++/security/GeneralSecurityException.h" +using beecrypt::security::GeneralSecurityException; + +namespace beecrypt { + namespace security { + class BEECRYPTCXXAPI KeyException : public GeneralSecurityException + { + public: + KeyException() throw (); + KeyException(const String&) throw (); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/KeyFactory.cxx b/beecrypt/c++/security/KeyFactory.cxx new file mode 100644 index 0000000..aaf910d --- /dev/null +++ b/beecrypt/c++/security/KeyFactory.cxx @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/security/KeyFactory.h" +#include "beecrypt/c++/security/Security.h" + +using namespace beecrypt::security; + +KeyFactory::KeyFactory(KeyFactorySpi* spi, const String& algorithm, const Provider& provider) +{ + _kspi = spi; + _algo = algorithm; + _prov = &provider; +} + +KeyFactory::~KeyFactory() +{ + delete _kspi; +} + +KeyFactory* KeyFactory::getInstance(const String& algorithm) throw (NoSuchAlgorithmException) +{ + Security::spi* tmp = Security::getSpi(algorithm, "KeyFactory"); + + KeyFactory* result = new KeyFactory((KeyFactorySpi*) tmp->cspi, tmp->name, tmp->prov); + + delete tmp; + + return result; +} + +KeyFactory* KeyFactory::getInstance(const String& algorithm, const String& provider) throw (NoSuchAlgorithmException, NoSuchProviderException) +{ + Security::spi* tmp = Security::getSpi(algorithm, "KeyFactory", provider); + + KeyFactory* result = new KeyFactory((KeyFactorySpi*) tmp->cspi, tmp->name, tmp->prov); + + delete tmp; + + return result; +} + +KeyFactory* KeyFactory::getInstance(const String& algorithm, const Provider& provider) throw (NoSuchAlgorithmException) +{ + Security::spi* tmp = Security::getSpi(algorithm, "KeyFactory", provider); + + KeyFactory* result = new KeyFactory((KeyFactorySpi*) tmp->cspi, tmp->name, tmp->prov); + + delete tmp; + + return result; +} + +PrivateKey* KeyFactory::generatePrivate(const KeySpec& spec) throw (InvalidKeySpecException) +{ + return _kspi->engineGeneratePrivate(spec); +} + +PublicKey* KeyFactory::generatePublic(const KeySpec& spec) throw (InvalidKeySpecException) +{ + return _kspi->engineGeneratePublic(spec); +} + +KeySpec* KeyFactory::getKeySpec(const Key& key, const type_info& info) throw (InvalidKeySpecException) +{ + return _kspi->engineGetKeySpec(key, info); +} + +Key* KeyFactory::translateKey(const Key& key) throw (InvalidKeyException) +{ + return _kspi->engineTranslateKey(key); +} + +const String& KeyFactory::getAlgorithm() const throw () +{ + return _algo; +} + +const Provider& KeyFactory::getProvider() const throw () +{ + return *_prov; +} diff --git a/beecrypt/c++/security/KeyFactory.h b/beecrypt/c++/security/KeyFactory.h new file mode 100644 index 0000000..fd992dd --- /dev/null +++ b/beecrypt/c++/security/KeyFactory.h @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file KeyFactory.h + * \ingroup CXX_SECURITY_m + */ + +#ifndef _CLASS_KEYFACTORY_H +#define _CLASS_KEYFACTORY_H + +#include "beecrypt/api.h" + +#ifdef __cplusplus + +#include "beecrypt/c++/security/KeyFactorySpi.h" +using beecrypt::security::KeyFactorySpi; +#include "beecrypt/c++/security/Provider.h" +using beecrypt::security::Provider; +#include "beecrypt/c++/security/NoSuchAlgorithmException.h" +using beecrypt::security::NoSuchAlgorithmException; +#include "beecrypt/c++/security/NoSuchProviderException.h" +using beecrypt::security::NoSuchProviderException; + +#include +using std::type_info; + +namespace beecrypt { + namespace security { + class BEECRYPTCXXAPI KeyFactory + { + public: + static KeyFactory* getInstance(const String&) throw (NoSuchAlgorithmException); + static KeyFactory* getInstance(const String&, const String&) throw (NoSuchAlgorithmException, NoSuchProviderException); + static KeyFactory* getInstance(const String&, const Provider&) throw (NoSuchAlgorithmException); + + private: + KeyFactorySpi* _kspi; + String _algo; + const Provider* _prov; + + protected: + KeyFactory(KeyFactorySpi*, const String&, const Provider&); + + public: + ~KeyFactory(); + + PrivateKey* generatePrivate(const KeySpec&) throw (InvalidKeySpecException); + PublicKey* generatePublic(const KeySpec&) throw (InvalidKeySpecException); + + KeySpec* getKeySpec(const Key& key, const type_info&) throw (InvalidKeySpecException); + + Key* translateKey(const Key&) throw (InvalidKeyException); + + const String& getAlgorithm() const throw (); + const Provider& getProvider() const throw (); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/KeyFactorySpi.h b/beecrypt/c++/security/KeyFactorySpi.h new file mode 100644 index 0000000..caca4b1 --- /dev/null +++ b/beecrypt/c++/security/KeyFactorySpi.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file KeyFactorySpi.h + * \ingroup CXX_SECURITY_m + */ + +#ifndef _CLASS_KEYFACTORYSPI_H +#define _CLASS_KEYFACTORYSPI_H + +#include "beecrypt/api.h" + +#ifdef __cplusplus + +#include "beecrypt/c++/security/PrivateKey.h" +using beecrypt::security::PrivateKey; +#include "beecrypt/c++/security/PublicKey.h" +using beecrypt::security::PublicKey; +#include "beecrypt/c++/security/InvalidKeyException.h" +#include "beecrypt/c++/security/spec/KeySpec.h" +using beecrypt::security::spec::KeySpec; +#include "beecrypt/c++/security/spec/InvalidKeySpecException.h" +using beecrypt::security::spec::InvalidKeySpecException; + +#include +using std::type_info; + +namespace beecrypt { + namespace security { + class BEECRYPTCXXAPI KeyFactorySpi + { + friend class KeyFactory; + + protected: + virtual PrivateKey* engineGeneratePrivate(const KeySpec&) throw (InvalidKeySpecException) = 0; + virtual PublicKey* engineGeneratePublic(const KeySpec&) throw (InvalidKeySpecException) = 0; + + virtual KeySpec* engineGetKeySpec(const Key&, const type_info&) throw (InvalidKeySpecException) = 0; + + virtual Key* engineTranslateKey(const Key&) throw (InvalidKeyException) = 0; + + public: + virtual ~KeyFactorySpi() {}; + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/KeyPair.cxx b/beecrypt/c++/security/KeyPair.cxx new file mode 100644 index 0000000..659e29a --- /dev/null +++ b/beecrypt/c++/security/KeyPair.cxx @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/security/KeyPair.h" + +using namespace beecrypt::security; + +KeyPair::KeyPair(const PublicKey& pub, const PrivateKey& pri) : pub(pub.clone()), pri(pri.clone()) +{ +} + +KeyPair::KeyPair(PublicKey* pub, PrivateKey* pri) : pub(pub), pri(pri) +{ +} + +KeyPair::~KeyPair() +{ + delete pub; + delete pri; +} + +const PublicKey& KeyPair::getPublic() const throw () +{ + return *pub; +} + +const PrivateKey& KeyPair::getPrivate() const throw () +{ + return *pri; +} diff --git a/beecrypt/c++/security/KeyPair.h b/beecrypt/c++/security/KeyPair.h new file mode 100644 index 0000000..280dc20 --- /dev/null +++ b/beecrypt/c++/security/KeyPair.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file KeyPair.h + * \ingroup CXX_SECURITY_m + */ + +#ifndef _CLASS_KEYPAIR_H +#define _CLASS_KEYPAIR_H + +#ifdef __cplusplus + +#include "beecrypt/c++/security/PrivateKey.h" +using beecrypt::security::PrivateKey; +#include "beecrypt/c++/security/PublicKey.h" +using beecrypt::security::PublicKey; + +namespace beecrypt { + namespace security { + class BEECRYPTCXXAPI KeyPair + { + friend class KeyPairGenerator; + + private: + PublicKey* pub; + PrivateKey* pri; + + public: + KeyPair(const PublicKey&, const PrivateKey&); + KeyPair(PublicKey*, PrivateKey*); + ~KeyPair(); + + const PublicKey& getPublic() const throw (); + const PrivateKey& getPrivate() const throw (); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/KeyPairGenerator.cxx b/beecrypt/c++/security/KeyPairGenerator.cxx new file mode 100644 index 0000000..45dbf85 --- /dev/null +++ b/beecrypt/c++/security/KeyPairGenerator.cxx @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/security/KeyPairGenerator.h" +#include "beecrypt/c++/security/Security.h" + +using namespace beecrypt::security; + +KeyPairGenerator::KeyPairGenerator(KeyPairGeneratorSpi* spi, const String& algorithm, const Provider& provider) +{ + _kspi = spi; + _algo = algorithm; + _prov = &provider; +} + +KeyPairGenerator::~KeyPairGenerator() +{ + delete _kspi; +} + +KeyPairGenerator* KeyPairGenerator::getInstance(const String& algorithm) throw (NoSuchAlgorithmException) +{ + Security::spi* tmp = Security::getSpi(algorithm, "KeyPairGenerator"); + + KeyPairGenerator* result = new KeyPairGenerator((KeyPairGeneratorSpi*) tmp->cspi, tmp->name, tmp->prov); + + delete tmp; + + return result; +} + +KeyPairGenerator* KeyPairGenerator::getInstance(const String& algorithm, const String& provider) throw (NoSuchAlgorithmException, NoSuchProviderException) +{ + Security::spi* tmp = Security::getSpi(algorithm, "KeyPairGenerator", provider); + + KeyPairGenerator* result = new KeyPairGenerator((KeyPairGeneratorSpi*) tmp->cspi, tmp->name, tmp->prov); + + delete tmp; + + return result; +} + +KeyPairGenerator* KeyPairGenerator::getInstance(const String& algorithm, const Provider& provider) throw (NoSuchAlgorithmException) +{ + Security::spi* tmp = Security::getSpi(algorithm, "KeyPairGenerator", provider); + + KeyPairGenerator* result = new KeyPairGenerator((KeyPairGeneratorSpi*) tmp->cspi, tmp->name, tmp->prov); + + delete tmp; + + return result; +} + +KeyPair* KeyPairGenerator::generateKeyPair() +{ + return _kspi->engineGenerateKeyPair(); +} + +void KeyPairGenerator::initialize(const AlgorithmParameterSpec& spec) throw (InvalidAlgorithmParameterException) +{ + _kspi->engineInitialize(spec, 0); +} + +void KeyPairGenerator::initialize(const AlgorithmParameterSpec& spec, SecureRandom* random) throw (InvalidAlgorithmParameterException) +{ + _kspi->engineInitialize(spec, random); +} + +void KeyPairGenerator::initialize(size_t keysize) throw (InvalidParameterException) +{ + _kspi->engineInitialize(keysize, 0); +} + +void KeyPairGenerator::initialize(size_t keysize, SecureRandom* random) throw (InvalidParameterException) +{ + _kspi->engineInitialize(keysize, random); +} + +const String& KeyPairGenerator::getAlgorithm() const throw () +{ + return _algo; +} + +const Provider& KeyPairGenerator::getProvider() const throw () +{ + return *_prov; +} diff --git a/beecrypt/c++/security/KeyPairGenerator.h b/beecrypt/c++/security/KeyPairGenerator.h new file mode 100644 index 0000000..50d3e4e --- /dev/null +++ b/beecrypt/c++/security/KeyPairGenerator.h @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file KeyPairGenerator.h + * \ingroup CXX_SECURITY_m + */ + +#ifndef _CLASS_KEYPAIRGENERATOR_H +#define _CLASS_KEYPAIRGENERATOR_H + +// #include "beecrypt/api.h" + +#ifdef __cplusplus + +#include "beecrypt/c++/security/KeyPairGeneratorSpi.h" +using beecrypt::security::KeyPairGeneratorSpi; +#include "beecrypt/c++/security/Provider.h" +using beecrypt::security::Provider; +#include "beecrypt/c++/security/NoSuchAlgorithmException.h" +using beecrypt::security::NoSuchAlgorithmException; +#include "beecrypt/c++/security/NoSuchProviderException.h" +using beecrypt::security::NoSuchProviderException; + +namespace beecrypt { + namespace security { + class BEECRYPTCXXAPI KeyPairGenerator + { + public: + static KeyPairGenerator* getInstance(const String&) throw (NoSuchAlgorithmException); + static KeyPairGenerator* getInstance(const String&, const String&) throw (NoSuchAlgorithmException, NoSuchProviderException); + static KeyPairGenerator* getInstance(const String&, const Provider&) throw (NoSuchAlgorithmException); + + private: + KeyPairGeneratorSpi* _kspi; + String _algo; + const Provider* _prov; + + protected: + KeyPairGenerator(KeyPairGeneratorSpi*, const String&, const Provider&); + + public: + ~KeyPairGenerator(); + + KeyPair* generateKeyPair(); + + void initialize(const AlgorithmParameterSpec&) throw (InvalidAlgorithmParameterException); + void initialize(const AlgorithmParameterSpec&, SecureRandom*) throw (InvalidAlgorithmParameterException); + void initialize(size_t) throw(InvalidParameterException); + void initialize(size_t, SecureRandom*) throw (InvalidParameterException); + + const String& getAlgorithm() const throw (); + const Provider& getProvider() const throw (); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/KeyPairGeneratorSpi.h b/beecrypt/c++/security/KeyPairGeneratorSpi.h new file mode 100644 index 0000000..b67074e --- /dev/null +++ b/beecrypt/c++/security/KeyPairGeneratorSpi.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file KeyPairGeneratorSpi.h + * \ingroup CXX_SECURITY_m + */ + +#ifndef _CLASS_KEYPAIRGENERATORSPI_H +#define _CLASS_KEYPAIRGENERATORSPI_H + +#include "beecrypt/api.h" + +#ifdef __cplusplus + +#include "beecrypt/c++/security/KeyPair.h" +using beecrypt::security::KeyPair; +#include "beecrypt/c++/security/SecureRandom.h" +using beecrypt::security::SecureRandom; +#include "beecrypt/c++/security/InvalidAlgorithmParameterException.h" +using beecrypt::security::InvalidAlgorithmParameterException; +#include "beecrypt/c++/security/InvalidParameterException.h" +using beecrypt::security::InvalidParameterException; +#include "beecrypt/c++/security/spec/AlgorithmParameterSpec.h" +using beecrypt::security::spec::AlgorithmParameterSpec; + +namespace beecrypt { + namespace security { + class BEECRYPTCXXAPI KeyPairGeneratorSpi + { + friend class KeyPairGenerator; + + protected: + virtual KeyPair* engineGenerateKeyPair() = 0; + + virtual void engineInitialize(const AlgorithmParameterSpec&, SecureRandom*) throw (InvalidAlgorithmParameterException) = 0; + virtual void engineInitialize(size_t, SecureRandom*) throw (InvalidParameterException) = 0; + + public: + virtual ~KeyPairGeneratorSpi() {}; + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/KeyStore.cxx b/beecrypt/c++/security/KeyStore.cxx new file mode 100644 index 0000000..715f34f --- /dev/null +++ b/beecrypt/c++/security/KeyStore.cxx @@ -0,0 +1,188 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/security/KeyStore.h" +#include "beecrypt/c++/security/Security.h" + +using namespace beecrypt::security; + +KeyStore::KeyStore(KeyStoreSpi* spi, const String& type, const Provider& provider) +{ + _kspi = spi; + _type = type; + _prov = &provider; + _init = false; +} + +KeyStore::~KeyStore() +{ + delete _kspi; +} + +KeyStore* KeyStore::getInstance(const String& type) throw (KeyStoreException) +{ + try + { + Security::spi* tmp = Security::getSpi(type, "KeyStore"); + + KeyStore* result = new KeyStore((KeyStoreSpi*) tmp->cspi, tmp->name, tmp->prov); + + delete tmp; + + return result; + } + catch (NoSuchAlgorithmException& ex) + { + throw KeyStoreException(ex.getMessage()); + } +} + +KeyStore* KeyStore::getInstance(const String& type, const String& provider) throw (KeyStoreException, NoSuchProviderException) +{ + try + { + Security::spi* tmp = Security::getSpi(type, "KeyStore", provider); + + KeyStore* result = new KeyStore((KeyStoreSpi*) tmp->cspi, tmp->name, tmp->prov); + + delete tmp; + + return result; + } + catch (NoSuchAlgorithmException& ex) + { + throw KeyStoreException(ex.getMessage()); + } +} + +KeyStore* KeyStore::getInstance(const String& type, const Provider& provider) throw (KeyStoreException) +{ + try + { + Security::spi* tmp = Security::getSpi(type, "KeyStore", provider); + + KeyStore* result = new KeyStore((KeyStoreSpi*) tmp->cspi, tmp->name, tmp->prov); + + delete tmp; + + return result; + } + catch (NoSuchAlgorithmException& ex) + { + throw KeyStoreException(ex.getMessage()); + } +} + +const String& KeyStore::getDefaultType() +{ + return Security::getKeyStoreDefault(); +} + +Key* KeyStore::getKey(const String& alias, const array& password) throw (KeyStoreException, NoSuchAlgorithmException, UnrecoverableKeyException) +{ + return _kspi->engineGetKey(alias, password); +} + +void KeyStore::setKeyEntry(const String& alias, const bytearray& key, const vector& chain) throw (KeyStoreException) +{ + _kspi->engineSetKeyEntry(alias, key, chain); +} + +void KeyStore::setKeyEntry(const String& alias, const Key& key, const array& password, const vector& chain) throw (KeyStoreException) +{ + _kspi->engineSetKeyEntry(alias, key, password, chain); +} + +Enumeration* KeyStore::aliases() +{ + if (!_init) + throw KeyStoreException("Uninitialized keystore"); + + return _kspi->engineAliases(); +} + +bool KeyStore::containsAlias(const String& alias) throw (KeyStoreException) +{ + if (!_init) + throw KeyStoreException("Uninitialized keystore"); + + return _kspi->engineContainsAlias(alias); +} + +const Certificate* KeyStore::getCertificate(const String& alias) throw (KeyStoreException) +{ + if (!_init) + throw KeyStoreException("Uninitialized keystore"); + + return _kspi->engineGetCertificate(alias); +} + +bool KeyStore::isCertificateEntry(const String& alias) throw (KeyStoreException) +{ + if (!_init) + throw KeyStoreException("Uninitialized keystore"); + + return _kspi->engineIsCertificateEntry(alias); +} + +bool KeyStore::isKeyEntry(const String& alias) throw (KeyStoreException) +{ + if (!_init) + throw KeyStoreException("Uninitialized keystore"); + + return _kspi->engineIsKeyEntry(alias); +} + +void KeyStore::load(InputStream* in, const array* password) throw (IOException, NoSuchAlgorithmException, CertificateException) +{ + _kspi->engineLoad(in, password); + + _init = true; +} + +size_t KeyStore::size() const throw (KeyStoreException) +{ + if (!_init) + throw KeyStoreException("Uninitialized keystore"); + + return _kspi->engineSize(); +} + +void KeyStore::store(OutputStream& out, const array* password) throw (IOException, KeyStoreException, NoSuchAlgorithmException, CertificateException) +{ + if (!_init) + throw KeyStoreException("Uninitialized keystore"); + + _kspi->engineStore(out, password); +} + +const String& KeyStore::getType() const throw () +{ + return _type; +} + +const Provider& KeyStore::getProvider() const throw () +{ + return *_prov; +} diff --git a/beecrypt/c++/security/KeyStore.h b/beecrypt/c++/security/KeyStore.h new file mode 100644 index 0000000..c1dc291 --- /dev/null +++ b/beecrypt/c++/security/KeyStore.h @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file KeyStore.h + * \ingroup CXX_SECURITY_m + */ + +#ifndef _CLASS_KEYSTORE_H +#define _CLASS_KEYSTORE_H + +#include "beecrypt/api.h" + +#ifdef __cplusplus + +#include "beecrypt/c++/io/InputStream.h" +using beecrypt::io::InputStream; +#include "beecrypt/c++/io/OutputStream.h" +using beecrypt::io::OutputStream; +#include "beecrypt/c++/security/KeyStoreSpi.h" +using beecrypt::security::KeyStoreSpi; +#include "beecrypt/c++/security/KeyStoreException.h" +using beecrypt::security::KeyStoreException; +#include "beecrypt/c++/security/Provider.h" +using beecrypt::security::Provider; +#include "beecrypt/c++/security/NoSuchProviderException.h" +using beecrypt::security::NoSuchProviderException; + +namespace beecrypt { + namespace security { + class BEECRYPTCXXAPI KeyStore + { + public: + static KeyStore* getInstance(const String&) throw (KeyStoreException); + static KeyStore* getInstance(const String&, const String&) throw (KeyStoreException, NoSuchProviderException); + static KeyStore* getInstance(const String&, const Provider&) throw (KeyStoreException); + + static const String& getDefaultType(); + + private: + KeyStoreSpi* _kspi; + String _type; + const Provider* _prov; + bool _init; + + protected: + KeyStore(KeyStoreSpi*, const String&, const Provider&); + + public: + ~KeyStore(); + + Enumeration* aliases(); + bool containsAlias(const String&) throw (KeyStoreException); + + const Certificate* getCertificate(const String&) throw (KeyStoreException); + const String& getCertificateAlias(const Certificate&) throw (KeyStoreException); + const vector* getCertificateChain(const String&) throw (KeyStoreException); + bool isCertificateEntry(const String& alias) throw (KeyStoreException); + void setCertificateEntry(const String& alias, const Certificate& cert) throw (KeyStoreException); + + void deleteEntry(const String&) throw (KeyStoreException); + + Key* getKey(const String& alias, const array& password) throw (KeyStoreException, NoSuchAlgorithmException, UnrecoverableKeyException); + bool isKeyEntry(const String& alias) throw (KeyStoreException); + void setKeyEntry(const String& alias, const bytearray& key, const vector&) throw (KeyStoreException); + void setKeyEntry(const String& alias, const Key& key, const array& password, const vector&) throw (KeyStoreException); + + size_t size() const throw (KeyStoreException); + + void load(InputStream* in, const array* password) throw (IOException, NoSuchAlgorithmException, CertificateException); + void store(OutputStream& out, const array* password) throw (KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException); + + const String& getType() const throw (); + const Provider& getProvider() const throw (); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/KeyStoreException.cxx b/beecrypt/c++/security/KeyStoreException.cxx new file mode 100644 index 0000000..22b53c0 --- /dev/null +++ b/beecrypt/c++/security/KeyStoreException.cxx @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/security/KeyStoreException.h" + +using namespace beecrypt::security; + +KeyStoreException::KeyStoreException() throw () +{ +} + +KeyStoreException::KeyStoreException(const String& message) throw () : GeneralSecurityException(message) +{ +} diff --git a/beecrypt/c++/security/KeyStoreException.h b/beecrypt/c++/security/KeyStoreException.h new file mode 100644 index 0000000..ec522d7 --- /dev/null +++ b/beecrypt/c++/security/KeyStoreException.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file KeyStoreException.h + * \ingroup CXX_SECURITY_m + */ + +#ifndef _CLASS_KEYSTOREEXCEPTION_H +#define _CLASS_KEYSTOREEXCEPTION_H + +#ifdef __cplusplus + +#include "beecrypt/c++/security/GeneralSecurityException.h" +using beecrypt::security::GeneralSecurityException; + +namespace beecrypt { + namespace security { + class BEECRYPTCXXAPI KeyStoreException : public GeneralSecurityException + { + public: + KeyStoreException() throw (); + KeyStoreException(const String&) throw (); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/KeyStoreSpi.h b/beecrypt/c++/security/KeyStoreSpi.h new file mode 100644 index 0000000..32a09e0 --- /dev/null +++ b/beecrypt/c++/security/KeyStoreSpi.h @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file KeyStoreSpi.h + * \ingroup CXX_SECURITY_m + */ + +#ifndef _CLASS_KEYSTORESPI_H +#define _CLASS_KEYSTORESPI_H + +#include "beecrypt/api.h" + +#ifdef __cplusplus + +#include "beecrypt/c++/io/InputStream.h" +using beecrypt::io::InputStream; +#include "beecrypt/c++/io/OutputStream.h" +using beecrypt::io::OutputStream; +#include "beecrypt/c++/security/KeyStoreException.h" +using beecrypt::security::KeyStoreException; +#include "beecrypt/c++/security/NoSuchAlgorithmException.h" +using beecrypt::security::NoSuchAlgorithmException; +#include "beecrypt/c++/security/NoSuchProviderException.h" +using beecrypt::security::NoSuchProviderException; +#include "beecrypt/c++/security/UnrecoverableKeyException.h" +using beecrypt::security::UnrecoverableKeyException; +#include "beecrypt/c++/security/cert/Certificate.h" +using beecrypt::security::cert::Certificate; +#include "beecrypt/c++/security/cert/CertificateException.h" +using beecrypt::security::cert::CertificateException; +#include "beecrypt/c++/util/Date.h" +using beecrypt::util::Date; +#include "beecrypt/c++/util/Enumeration.h" +using beecrypt::util::Enumeration; + +#include +using std::type_info; +#include +using std::vector; + +namespace beecrypt { + namespace security { + class BEECRYPTCXXAPI KeyStoreSpi + { + friend class KeyStore; + + protected: + virtual Enumeration* engineAliases() = 0; + virtual bool engineContainsAlias(const String&) = 0; + + virtual void engineDeleteEntry(const String&) throw (KeyStoreException) = 0; + virtual const Date* engineGetCreationDate(const String&) = 0; + + virtual const Certificate* engineGetCertificate(const String&) = 0; + virtual const String* engineGetCertificateAlias(const Certificate&) = 0; + virtual const vector* engineGetCertificateChain(const String&) = 0; + virtual bool engineIsCertificateEntry(const String& alias) = 0; + virtual void engineSetCertificateEntry(const String& alias, const Certificate& cert) throw (KeyStoreException) = 0; + + virtual Key* engineGetKey(const String& alias, const array& password) throw (NoSuchAlgorithmException, UnrecoverableKeyException) = 0; + virtual bool engineIsKeyEntry(const String& alias) = 0; + virtual void engineSetKeyEntry(const String& alias, const bytearray& key, const vector&) throw (KeyStoreException) = 0; + virtual void engineSetKeyEntry(const String& alias, const Key& key, const array& password, const vector&) throw (KeyStoreException) = 0; + + virtual size_t engineSize() const = 0; + + virtual void engineLoad(InputStream* in, const array* password) throw (IOException, CertificateException, NoSuchAlgorithmException) = 0; + virtual void engineStore(OutputStream& out, const array* password) throw (IOException, CertificateException, NoSuchAlgorithmException) = 0; + + public: + virtual ~KeyStoreSpi() {}; + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/Makefile.am b/beecrypt/c++/security/Makefile.am new file mode 100644 index 0000000..ebf413c --- /dev/null +++ b/beecrypt/c++/security/Makefile.am @@ -0,0 +1,73 @@ +INCLUDES = -I$(top_srcdir)/.. + +AUTOMAKE_OPTIONS = gnu no-dependencies + +SUBDIRS = cert interfaces spec + +noinst_LTLIBRARIES = libcxxsecurity.la + +cxxsecuritydir=$(pkgincludedir)/c++/security + +libcxxsecurity_la_SOURCES =\ +AlgorithmParameterGenerator.cxx \ +AlgorithmParameters.cxx \ +DigestInputStream.cxx \ +DigestOutputStream.cxx \ +GeneralSecurityException.cxx \ +InvalidAlgorithmParameterException.cxx \ +InvalidKeyException.cxx \ +InvalidParameterException.cxx \ +KeyException.cxx \ +KeyFactory.cxx \ +KeyPair.cxx \ +KeyPairGenerator.cxx \ +KeyStore.cxx \ +KeyStoreException.cxx \ +MessageDigest.cxx \ +NoSuchAlgorithmException.cxx \ +NoSuchProviderException.cxx \ +Provider.cxx \ +SecureRandom.cxx \ +Security.cxx \ +ShortBufferException.cxx \ +Signature.cxx \ +SignatureException.cxx \ +UnrecoverableKeyException.cxx +libcxxsecurity_la_LIBADD = cert/libcxxsecuritycert.la spec/libcxxsecurityspec.la + +cxxsecurity_HEADERS =\ +AlgorithmParameterGenerator.h \ +AlgorithmParameterGeneratorSpi.h \ +AlgorithmParameters.h \ +AlgorithmParametersSpi.h \ +DigestInputStream.h \ +DigestOutputStream.h \ +GeneralSecurityException.h \ +InvalidAlgorithmParameterException.h \ +InvalidKeyException.h \ +InvalidParameterException.h \ +KeyFactory.h \ +KeyFactorySpi.h \ +Key.h \ +KeyException.h \ +KeyPairGenerator.h \ +KeyPairGeneratorSpi.h \ +KeyPair.h \ +KeyStoreException.h \ +KeyStore.h \ +KeyStoreSpi.h \ +MessageDigest.h \ +MessageDigestSpi.h \ +NoSuchAlgorithmException.h \ +NoSuchProviderException.h \ +PrivateKey.h \ +Provider.h \ +PublicKey.h \ +SecureRandom.h \ +SecureRandomSpi.h \ +Security.h \ +ShortBufferException.h \ +Signature.h \ +SignatureException.h \ +SignatureSpi.h \ +UnrecoverableKeyException.h diff --git a/beecrypt/c++/security/Makefile.in b/beecrypt/c++/security/Makefile.in new file mode 100644 index 0000000..dbdd4b2 --- /dev/null +++ b/beecrypt/c++/security/Makefile.in @@ -0,0 +1,655 @@ +# Makefile.in generated by automake 1.8.3 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + + +SOURCES = $(libcxxsecurity_la_SOURCES) + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +top_builddir = ../.. +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +INSTALL = @INSTALL@ +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +host_triplet = @host@ +subdir = c++/security +DIST_COMMON = $(cxxsecurity_HEADERS) $(srcdir)/Makefile.am \ + $(srcdir)/Makefile.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \ + $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +LTLIBRARIES = $(noinst_LTLIBRARIES) +libcxxsecurity_la_DEPENDENCIES = cert/libcxxsecuritycert.la \ + spec/libcxxsecurityspec.la +am_libcxxsecurity_la_OBJECTS = AlgorithmParameterGenerator.lo \ + AlgorithmParameters.lo DigestInputStream.lo \ + DigestOutputStream.lo GeneralSecurityException.lo \ + InvalidAlgorithmParameterException.lo InvalidKeyException.lo \ + InvalidParameterException.lo KeyException.lo KeyFactory.lo \ + KeyPair.lo KeyPairGenerator.lo KeyStore.lo \ + KeyStoreException.lo MessageDigest.lo \ + NoSuchAlgorithmException.lo NoSuchProviderException.lo \ + Provider.lo SecureRandom.lo Security.lo \ + ShortBufferException.lo Signature.lo SignatureException.lo \ + UnrecoverableKeyException.lo +libcxxsecurity_la_OBJECTS = $(am_libcxxsecurity_la_OBJECTS) +DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir) +depcomp = +am__depfiles_maybe = +CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) +LTCXXCOMPILE = $(LIBTOOL) --mode=compile $(CXX) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CXXFLAGS) $(CXXFLAGS) +CXXLD = $(CXX) +CXXLINK = $(LIBTOOL) --mode=link $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) \ + $(AM_LDFLAGS) $(LDFLAGS) -o $@ +SOURCES = $(libcxxsecurity_la_SOURCES) +DIST_SOURCES = $(libcxxsecurity_la_SOURCES) +RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \ + html-recursive info-recursive install-data-recursive \ + install-exec-recursive install-info-recursive \ + install-recursive installcheck-recursive installdirs-recursive \ + pdf-recursive ps-recursive uninstall-info-recursive \ + uninstall-recursive +am__installdirs = "$(DESTDIR)$(cxxsecuritydir)" +cxxsecurityHEADERS_INSTALL = $(INSTALL_HEADER) +HEADERS = $(cxxsecurity_HEADERS) +ETAGS = etags +CTAGS = ctags +DIST_SUBDIRS = $(SUBDIRS) +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMDEP_FALSE = @AMDEP_FALSE@ +AMDEP_TRUE = @AMDEP_TRUE@ +AMTAR = @AMTAR@ +AR = @AR@ +AS = @AS@ +ASM_ALIGN = @ASM_ALIGN@ +ASM_ARCH = @ASM_ARCH@ +ASM_BIGENDIAN = @ASM_BIGENDIAN@ +ASM_CPU = @ASM_CPU@ +ASM_GLOBL = @ASM_GLOBL@ +ASM_GSYM_PREFIX = @ASM_GSYM_PREFIX@ +ASM_LSYM_PREFIX = @ASM_LSYM_PREFIX@ +ASM_OS = @ASM_OS@ +ASM_TEXTSEG = @ASM_TEXTSEG@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCAS = @CCAS@ +CCASFLAGS = @CCASFLAGS@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DLLTOOL = @DLLTOOL@ +ECHO = @ECHO@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +F77 = @F77@ +FFLAGS = @FFLAGS@ +INCLUDE_DLFCN_H = @INCLUDE_DLFCN_H@ +INCLUDE_INTTYPES_H = @INCLUDE_INTTYPES_H@ +INCLUDE_MALLOC_H = @INCLUDE_MALLOC_H@ +INCLUDE_PTHREAD_H = @INCLUDE_PTHREAD_H@ +INCLUDE_STDINT_H = @INCLUDE_STDINT_H@ +INCLUDE_STDIO_H = @INCLUDE_STDIO_H@ +INCLUDE_STDLIB_H = @INCLUDE_STDLIB_H@ +INCLUDE_STRING_H = @INCLUDE_STRING_H@ +INCLUDE_SYNCH_H = @INCLUDE_SYNCH_H@ +INCLUDE_THREAD_H = @INCLUDE_THREAD_H@ +INCLUDE_UNISTD_H = @INCLUDE_UNISTD_H@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +JAVAINC = @JAVAINC@ +LDFLAGS = @LDFLAGS@ +LIBALT = @LIBALT@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +MAYBE_LTLIB = @MAYBE_LTLIB@ +MAYBE_SUB = @MAYBE_SUB@ +MP_WBITS = @MP_WBITS@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PYTHONINC = @PYTHONINC@ +PYTHONLIB = @PYTHONLIB@ +RANLIB = @RANLIB@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +TYPEDEF_BC_COND_T = @TYPEDEF_BC_COND_T@ +TYPEDEF_BC_MUTEX_T = @TYPEDEF_BC_MUTEX_T@ +TYPEDEF_BC_THREAD_T = @TYPEDEF_BC_THREAD_T@ +TYPEDEF_INT16_T = @TYPEDEF_INT16_T@ +TYPEDEF_INT32_T = @TYPEDEF_INT32_T@ +TYPEDEF_INT64_T = @TYPEDEF_INT64_T@ +TYPEDEF_INT8_T = @TYPEDEF_INT8_T@ +TYPEDEF_SIZE_T = @TYPEDEF_SIZE_T@ +TYPEDEF_UINT16_T = @TYPEDEF_UINT16_T@ +TYPEDEF_UINT32_T = @TYPEDEF_UINT32_T@ +TYPEDEF_UINT64_T = @TYPEDEF_UINT64_T@ +TYPEDEF_UINT8_T = @TYPEDEF_UINT8_T@ +VERSION = @VERSION@ +ac_ct_AR = @ac_ct_AR@ +ac_ct_AS = @ac_ct_AS@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DLLTOOL = @ac_ct_DLLTOOL@ +ac_ct_F77 = @ac_ct_F77@ +ac_ct_OBJDUMP = @ac_ct_OBJDUMP@ +ac_ct_RANLIB = @ac_ct_RANLIB@ +ac_ct_STRIP = @ac_ct_STRIP@ +ac_cv_have_gcj = @ac_cv_have_gcj@ +ac_cv_have_java = @ac_cv_have_java@ +ac_cv_have_javac = @ac_cv_have_javac@ +ac_cv_have_python = @ac_cv_have_python@ +am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ +am__fastdepCC_TRUE = @am__fastdepCC_TRUE@ +am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@ +am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +datadir = @datadir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +sysconfdir = @sysconfdir@ +target = @target@ +target_alias = @target_alias@ +target_cpu = @target_cpu@ +target_os = @target_os@ +target_vendor = @target_vendor@ +INCLUDES = -I$(top_srcdir)/.. +AUTOMAKE_OPTIONS = gnu no-dependencies +SUBDIRS = cert interfaces spec +noinst_LTLIBRARIES = libcxxsecurity.la +cxxsecuritydir = $(pkgincludedir)/c++/security +libcxxsecurity_la_SOURCES = \ +AlgorithmParameterGenerator.cxx \ +AlgorithmParameters.cxx \ +DigestInputStream.cxx \ +DigestOutputStream.cxx \ +GeneralSecurityException.cxx \ +InvalidAlgorithmParameterException.cxx \ +InvalidKeyException.cxx \ +InvalidParameterException.cxx \ +KeyException.cxx \ +KeyFactory.cxx \ +KeyPair.cxx \ +KeyPairGenerator.cxx \ +KeyStore.cxx \ +KeyStoreException.cxx \ +MessageDigest.cxx \ +NoSuchAlgorithmException.cxx \ +NoSuchProviderException.cxx \ +Provider.cxx \ +SecureRandom.cxx \ +Security.cxx \ +ShortBufferException.cxx \ +Signature.cxx \ +SignatureException.cxx \ +UnrecoverableKeyException.cxx + +libcxxsecurity_la_LIBADD = cert/libcxxsecuritycert.la spec/libcxxsecurityspec.la +cxxsecurity_HEADERS = \ +AlgorithmParameterGenerator.h \ +AlgorithmParameterGeneratorSpi.h \ +AlgorithmParameters.h \ +AlgorithmParametersSpi.h \ +DigestInputStream.h \ +DigestOutputStream.h \ +GeneralSecurityException.h \ +InvalidAlgorithmParameterException.h \ +InvalidKeyException.h \ +InvalidParameterException.h \ +KeyFactory.h \ +KeyFactorySpi.h \ +Key.h \ +KeyException.h \ +KeyPairGenerator.h \ +KeyPairGeneratorSpi.h \ +KeyPair.h \ +KeyStoreException.h \ +KeyStore.h \ +KeyStoreSpi.h \ +MessageDigest.h \ +MessageDigestSpi.h \ +NoSuchAlgorithmException.h \ +NoSuchProviderException.h \ +PrivateKey.h \ +Provider.h \ +PublicKey.h \ +SecureRandom.h \ +SecureRandomSpi.h \ +Security.h \ +ShortBufferException.h \ +Signature.h \ +SignatureException.h \ +SignatureSpi.h \ +UnrecoverableKeyException.h + +all: all-recursive + +.SUFFIXES: +.SUFFIXES: .cxx .lo .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ + && exit 0; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu c++/security/Makefile'; \ + cd $(top_srcdir) && \ + $(AUTOMAKE) --gnu c++/security/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +clean-noinstLTLIBRARIES: + -test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES) + @list='$(noinst_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" = "$$p" && dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +libcxxsecurity.la: $(libcxxsecurity_la_OBJECTS) $(libcxxsecurity_la_DEPENDENCIES) + $(CXXLINK) $(libcxxsecurity_la_LDFLAGS) $(libcxxsecurity_la_OBJECTS) $(libcxxsecurity_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +.cxx.o: + $(CXXCOMPILE) -c -o $@ $< + +.cxx.obj: + $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +.cxx.lo: + $(LTCXXCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +distclean-libtool: + -rm -f libtool +uninstall-info-am: +install-cxxsecurityHEADERS: $(cxxsecurity_HEADERS) + @$(NORMAL_INSTALL) + test -z "$(cxxsecuritydir)" || $(mkdir_p) "$(DESTDIR)$(cxxsecuritydir)" + @list='$(cxxsecurity_HEADERS)'; for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + f="`echo $$p | sed -e 's|^.*/||'`"; \ + echo " $(cxxsecurityHEADERS_INSTALL) '$$d$$p' '$(DESTDIR)$(cxxsecuritydir)/$$f'"; \ + $(cxxsecurityHEADERS_INSTALL) "$$d$$p" "$(DESTDIR)$(cxxsecuritydir)/$$f"; \ + done + +uninstall-cxxsecurityHEADERS: + @$(NORMAL_UNINSTALL) + @list='$(cxxsecurity_HEADERS)'; for p in $$list; do \ + f="`echo $$p | sed -e 's|^.*/||'`"; \ + echo " rm -f '$(DESTDIR)$(cxxsecuritydir)/$$f'"; \ + rm -f "$(DESTDIR)$(cxxsecuritydir)/$$f"; \ + done + +# This directory's subdirectories are mostly independent; you can cd +# into them and run `make' without going through this Makefile. +# To change the values of `make' variables: instead of editing Makefiles, +# (1) if the variable is set in `config.status', edit `config.status' +# (which will cause the Makefiles to be regenerated when you run `make'); +# (2) otherwise, pass the desired values on the `make' command line. +$(RECURSIVE_TARGETS): + @set fnord $$MAKEFLAGS; amf=$$2; \ + dot_seen=no; \ + target=`echo $@ | sed s/-recursive//`; \ + list='$(SUBDIRS)'; for subdir in $$list; do \ + echo "Making $$target in $$subdir"; \ + if test "$$subdir" = "."; then \ + dot_seen=yes; \ + local_target="$$target-am"; \ + else \ + local_target="$$target"; \ + fi; \ + (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ + || case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \ + done; \ + if test "$$dot_seen" = "no"; then \ + $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \ + fi; test -z "$$fail" + +mostlyclean-recursive clean-recursive distclean-recursive \ +maintainer-clean-recursive: + @set fnord $$MAKEFLAGS; amf=$$2; \ + dot_seen=no; \ + case "$@" in \ + distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \ + *) list='$(SUBDIRS)' ;; \ + esac; \ + rev=''; for subdir in $$list; do \ + if test "$$subdir" = "."; then :; else \ + rev="$$subdir $$rev"; \ + fi; \ + done; \ + rev="$$rev ."; \ + target=`echo $@ | sed s/-recursive//`; \ + for subdir in $$rev; do \ + echo "Making $$target in $$subdir"; \ + if test "$$subdir" = "."; then \ + local_target="$$target-am"; \ + else \ + local_target="$$target"; \ + fi; \ + (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ + || case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \ + done && test -z "$$fail" +tags-recursive: + list='$(SUBDIRS)'; for subdir in $$list; do \ + test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \ + done +ctags-recursive: + list='$(SUBDIRS)'; for subdir in $$list; do \ + test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) ctags); \ + done + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: tags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + if (etags --etags-include --version) >/dev/null 2>&1; then \ + include_option=--etags-include; \ + else \ + include_option=--include; \ + fi; \ + list='$(SUBDIRS)'; for subdir in $$list; do \ + if test "$$subdir" = .; then :; else \ + test -f $$subdir/TAGS && \ + tags="$$tags $$include_option=$$here/$$subdir/TAGS"; \ + fi; \ + done; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(ETAGS_ARGS)$$tags$$unique" \ + || $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$tags $$unique +ctags: CTAGS +CTAGS: ctags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(CTAGS_ARGS)$$tags$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$tags $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && cd $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) $$here + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \ + list='$(DISTFILES)'; for file in $$list; do \ + case $$file in \ + $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \ + $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \ + esac; \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test "$$dir" != "$$file" && test "$$dir" != "."; then \ + dir="/$$dir"; \ + $(mkdir_p) "$(distdir)$$dir"; \ + else \ + dir=''; \ + fi; \ + if test -d $$d/$$file; then \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + fi; \ + cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ + else \ + test -f $(distdir)/$$file \ + || cp -p $$d/$$file $(distdir)/$$file \ + || exit 1; \ + fi; \ + done + list='$(SUBDIRS)'; for subdir in $$list; do \ + if test "$$subdir" = .; then :; else \ + test -d "$(distdir)/$$subdir" \ + || mkdir "$(distdir)/$$subdir" \ + || exit 1; \ + (cd $$subdir && \ + $(MAKE) $(AM_MAKEFLAGS) \ + top_distdir="../$(top_distdir)" \ + distdir="../$(distdir)/$$subdir" \ + distdir) \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-recursive +all-am: Makefile $(LTLIBRARIES) $(HEADERS) +installdirs: installdirs-recursive +installdirs-am: + for dir in "$(DESTDIR)$(cxxsecuritydir)"; do \ + test -z "$$dir" || $(mkdir_p) "$$dir"; \ + done +install: install-recursive +install-exec: install-exec-recursive +install-data: install-data-recursive +uninstall: uninstall-recursive + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-recursive +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -rm -f $(CONFIG_CLEAN_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-recursive + +clean-am: clean-generic clean-libtool clean-noinstLTLIBRARIES \ + mostlyclean-am + +distclean: distclean-recursive + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-libtool distclean-tags + +dvi: dvi-recursive + +dvi-am: + +html: html-recursive + +info: info-recursive + +info-am: + +install-data-am: install-cxxsecurityHEADERS + +install-exec-am: + +install-info: install-info-recursive + +install-man: + +installcheck-am: + +maintainer-clean: maintainer-clean-recursive + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-recursive + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-recursive + +pdf-am: + +ps: ps-recursive + +ps-am: + +uninstall-am: uninstall-cxxsecurityHEADERS uninstall-info-am + +uninstall-info: uninstall-info-recursive + +.PHONY: $(RECURSIVE_TARGETS) CTAGS GTAGS all all-am check check-am \ + clean clean-generic clean-libtool clean-noinstLTLIBRARIES \ + clean-recursive ctags ctags-recursive distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-recursive distclean-tags distdir dvi dvi-am html \ + html-am info info-am install install-am \ + install-cxxsecurityHEADERS install-data install-data-am \ + install-exec install-exec-am install-info install-info-am \ + install-man install-strip installcheck installcheck-am \ + installdirs installdirs-am maintainer-clean \ + maintainer-clean-generic maintainer-clean-recursive \ + mostlyclean mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool mostlyclean-recursive pdf pdf-am ps ps-am \ + tags tags-recursive uninstall uninstall-am \ + uninstall-cxxsecurityHEADERS uninstall-info-am + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/beecrypt/c++/security/MessageDigest.cxx b/beecrypt/c++/security/MessageDigest.cxx new file mode 100644 index 0000000..dbd5348 --- /dev/null +++ b/beecrypt/c++/security/MessageDigest.cxx @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/security/MessageDigest.h" +#include "beecrypt/c++/security/Security.h" + +using namespace beecrypt::security; + +MessageDigest::MessageDigest(MessageDigestSpi* spi, const String& algorithm, const Provider& provider) +{ + _mspi = spi; + _algo = algorithm; + _prov = &provider; +} + +MessageDigest::~MessageDigest() +{ + delete _mspi; +} + +MessageDigest* MessageDigest::getInstance(const String& algorithm) throw (NoSuchAlgorithmException) +{ + Security::spi* tmp = Security::getSpi(algorithm, "MessageDigest"); + + MessageDigest* result = new MessageDigest((MessageDigestSpi*) tmp->cspi, tmp->name, tmp->prov); + + delete tmp; + + return result; +} + +MessageDigest* MessageDigest::getInstance(const String& algorithm, const String& provider) throw (NoSuchAlgorithmException, NoSuchProviderException) +{ + Security::spi* tmp = Security::getSpi(algorithm, "MessageDigest", provider); + + MessageDigest* result = new MessageDigest((MessageDigestSpi*) tmp->cspi, tmp->name, tmp->prov); + + delete tmp; + + return result; +} + +MessageDigest* MessageDigest::getInstance(const String& algorithm, const Provider& provider) throw (NoSuchAlgorithmException) +{ + Security::spi* tmp = Security::getSpi(algorithm, "MessageDigest", provider); + + MessageDigest* result = new MessageDigest((MessageDigestSpi*) tmp->cspi, tmp->name, tmp->prov); + + delete tmp; + + return result; +} + +MessageDigest* MessageDigest::clone() const +{ + MessageDigestSpi* _mspc = _mspi->clone(); + + if (_mspc) + return new MessageDigest(_mspc, _algo, *_prov); + else + return 0; +} + +const bytearray& MessageDigest::digest() +{ + return _mspi->engineDigest(); +} + +const bytearray& MessageDigest::digest(const bytearray& b) +{ + _mspi->engineUpdate(b.data(), 0, b.size()); + return _mspi->engineDigest(); +} + +size_t MessageDigest::digest(byte* data, size_t offset, size_t length) throw (ShortBufferException) +{ + return _mspi->engineDigest(data, offset, length); +} + +size_t MessageDigest::getDigestLength() +{ + return _mspi->engineGetDigestLength(); +} + +void MessageDigest::reset() +{ + _mspi->engineReset(); +} + +void MessageDigest::update(byte b) +{ + _mspi->engineUpdate(b); +} + +void MessageDigest::update(const bytearray& b) +{ + _mspi->engineUpdate(b.data(), 0, b.size()); +} + +void MessageDigest::update(const byte* data, size_t offset, size_t length) +{ + _mspi->engineUpdate(data, offset, length); +} + +const String& MessageDigest::getAlgorithm() const throw () +{ + return _algo; +} + +const Provider& MessageDigest::getProvider() const throw () +{ + return *_prov; +} diff --git a/beecrypt/c++/security/MessageDigest.h b/beecrypt/c++/security/MessageDigest.h new file mode 100644 index 0000000..12ca2b8 --- /dev/null +++ b/beecrypt/c++/security/MessageDigest.h @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file MessageDigest.h + * \ingroup CXX_SECURITY_m + */ + +#ifndef _CLASS_MESSAGEDIGEST_H +#define _CLASS_MESSAGEDIGEST_H + +#include "beecrypt/api.h" + +#ifdef __cplusplus + +#include "beecrypt/c++/security/MessageDigestSpi.h" +using beecrypt::security::MessageDigestSpi; +#include "beecrypt/c++/security/Provider.h" +using beecrypt::security::Provider; +#include "beecrypt/c++/security/NoSuchAlgorithmException.h" +using beecrypt::security::NoSuchAlgorithmException; +#include "beecrypt/c++/security/NoSuchProviderException.h" +using beecrypt::security::NoSuchProviderException; + +namespace beecrypt { + namespace security { + class BEECRYPTCXXAPI MessageDigest + { + public: + static MessageDigest* getInstance(const String&) throw (NoSuchAlgorithmException); + static MessageDigest* getInstance(const String&, const String&) throw (NoSuchAlgorithmException, NoSuchProviderException); + static MessageDigest* getInstance(const String&, const Provider&) throw (NoSuchAlgorithmException); + + private: + MessageDigestSpi* _mspi; + String _algo; + const Provider* _prov; + + protected: + MessageDigest(MessageDigestSpi*, const String&, const Provider&); + + public: + ~MessageDigest(); + + MessageDigest* clone() const; + + const bytearray& digest(); + const bytearray& digest(const bytearray&); + size_t digest(byte* data, size_t offset, size_t length) throw (ShortBufferException); + size_t getDigestLength(); + void reset(); + void update(byte); + void update(const byte* data, size_t offset, size_t length); + void update(const bytearray& b); + + const String& getAlgorithm() const throw (); + const Provider& getProvider() const throw (); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/MessageDigestSpi.h b/beecrypt/c++/security/MessageDigestSpi.h new file mode 100644 index 0000000..db2cc86 --- /dev/null +++ b/beecrypt/c++/security/MessageDigestSpi.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file MessageDigestSpi.h + * \ingroup CXX_SECURITY_m + */ + +#ifndef _CLASS_MESSAGEDIGESTSPI_H +#define _CLASS_MESSAGEDIGESTSPI_H + +#include "beecrypt/api.h" + +#ifdef __cplusplus + +#include "beecrypt/c++/array.h" +using beecrypt::bytearray; +#include "beecrypt/c++/security/ShortBufferException.h" +using beecrypt::security::ShortBufferException; + +namespace beecrypt { + namespace security { + class BEECRYPTCXXAPI MessageDigestSpi + { + friend class MessageDigest; + + protected: + virtual const bytearray& engineDigest() = 0; + virtual size_t engineDigest(byte*, size_t, size_t) throw (ShortBufferException) = 0; + virtual size_t engineGetDigestLength() = 0; + virtual void engineReset() = 0; + virtual void engineUpdate(byte) = 0; + virtual void engineUpdate(const byte*, size_t, size_t) = 0; + + public: + virtual ~MessageDigestSpi() {}; + + virtual MessageDigestSpi* clone() const = 0; + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/NoSuchAlgorithmException.cxx b/beecrypt/c++/security/NoSuchAlgorithmException.cxx new file mode 100644 index 0000000..69408e3 --- /dev/null +++ b/beecrypt/c++/security/NoSuchAlgorithmException.cxx @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/security/NoSuchAlgorithmException.h" + +using namespace beecrypt::security; + +NoSuchAlgorithmException::NoSuchAlgorithmException() throw () +{ +} + +NoSuchAlgorithmException::NoSuchAlgorithmException(const String& message) throw () : GeneralSecurityException(message) +{ +} diff --git a/beecrypt/c++/security/NoSuchAlgorithmException.h b/beecrypt/c++/security/NoSuchAlgorithmException.h new file mode 100644 index 0000000..3d97b2f --- /dev/null +++ b/beecrypt/c++/security/NoSuchAlgorithmException.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file NoSuchAlgorithmException.h + * \ingroup CXX_SECURITY_m + */ + +#ifndef _CLASS_NOSUCHALGORITHMEXCEPTION_H +#define _CLASS_NOSUCHALGORITHMEXCEPTION_H + +#ifdef __cplusplus + +#include "beecrypt/c++/security/GeneralSecurityException.h" +using beecrypt::security::GeneralSecurityException; + +namespace beecrypt { + namespace security { + class BEECRYPTCXXAPI NoSuchAlgorithmException : public GeneralSecurityException + { + public: + NoSuchAlgorithmException() throw (); + NoSuchAlgorithmException(const String&) throw (); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/NoSuchProviderException.cxx b/beecrypt/c++/security/NoSuchProviderException.cxx new file mode 100644 index 0000000..101f077 --- /dev/null +++ b/beecrypt/c++/security/NoSuchProviderException.cxx @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/security/NoSuchProviderException.h" + +using namespace beecrypt::security; + +NoSuchProviderException::NoSuchProviderException() throw () +{ +} + +NoSuchProviderException::NoSuchProviderException(const String& message) throw () : GeneralSecurityException(message) +{ +} diff --git a/beecrypt/c++/security/NoSuchProviderException.h b/beecrypt/c++/security/NoSuchProviderException.h new file mode 100644 index 0000000..f69b5e4 --- /dev/null +++ b/beecrypt/c++/security/NoSuchProviderException.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file NoSuchProviderException.h + * \ingroup CXX_SECURITY_m + */ + +#ifndef _CLASS_NOSUCHPROVIDEREXCEPTION_H +#define _CLASS_NOSUCHPROVIDEREXCEPTION_H + +#ifdef __cplusplus + +#include "beecrypt/c++/security/GeneralSecurityException.h" +using beecrypt::security::GeneralSecurityException; + +namespace beecrypt { + namespace security { + class BEECRYPTCXXAPI NoSuchProviderException : public GeneralSecurityException + { + public: + NoSuchProviderException() throw (); + NoSuchProviderException(const String&) throw (); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/PrivateKey.h b/beecrypt/c++/security/PrivateKey.h new file mode 100644 index 0000000..eff83c2 --- /dev/null +++ b/beecrypt/c++/security/PrivateKey.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file PrivateKey.h + * \ingroup CXX_SECURITY_m + */ + +#ifndef _INTERFACE_PRIVATEKEY_H +#define _INTERFACE_PRIVATEKEY_H + +#ifdef __cplusplus + +#include "beecrypt/c++/security/Key.h" +using beecrypt::security::Key; + +namespace beecrypt { + namespace security { + /*!\brief PrivateKey interface + * \ingroup CXX_IF_m + */ + class PrivateKey : public Key + { + public: + virtual PrivateKey* clone() const = 0; + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/Provider.cxx b/beecrypt/c++/security/Provider.cxx new file mode 100644 index 0000000..efb19e4 --- /dev/null +++ b/beecrypt/c++/security/Provider.cxx @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/security/Provider.h" + +using namespace beecrypt::security; + +Provider::Provider(const String& name, double version, const String& info) +{ + _name = name; + _info = info; + _vers = version; + + _lock.init(); + + UErrorCode status = U_ZERO_ERROR; + + _conv = ucnv_open(NULL, &status); + if (U_FAILURE(status)) + throw "failed to create default unicode converter"; + + #if WIN32 + _dlhandle = NULL; + #else + _dlhandle = RTLD_DEFAULT; + #endif +} + +Provider::~Provider() +{ + _lock.destroy(); + + ucnv_close(_conv); +} + +Provider::instantiator Provider::getInstantiator(const String& key) const +{ + instantiator_map::const_iterator it = _imap.find(key); + + if (it != _imap.end()) + return it->second; + else + return 0; +} + +void Provider::put(const String& key, const String& value) +{ + _lock.lock(); + + // add it in the properties + setProperty(key, value); + + // add it in the instantiator map only if there is no space in the value (i.e. it's a property instead of a class) + if (value.indexOf((UChar) 0x20) == -1) + { + char symname[1024]; + + UErrorCode status = U_ZERO_ERROR; + + ucnv_fromUChars(_conv, symname, 1024, value.getBuffer(), value.length(), &status); + + if (status != U_ZERO_ERROR) + { + _lock.unlock(); + throw "error in ucnv_fromUChars"; + } + + instantiator i; + + #if WIN32 + if (!_dlhandle) + _dlhandle = GetModuleHandle(NULL); + i = (instantiator) GetProcAddress((HMODULE) _dlhandle, symname); + #elif HAVE_DLFCN_H + i = (instantiator) dlsym(_dlhandle, symname); + #else + # error + #endif + + _imap[key] = i; + } + else + _imap[key] = 0; + + _lock.unlock(); +} + +const String& Provider::getInfo() const throw () +{ + return _info; +} + +const String& Provider::getName() const throw () +{ + return _name; +} + +double Provider::getVersion() const throw () +{ + return _vers; +} diff --git a/beecrypt/c++/security/Provider.h b/beecrypt/c++/security/Provider.h new file mode 100644 index 0000000..572a0b0 --- /dev/null +++ b/beecrypt/c++/security/Provider.h @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file Provider.h + * \ingroup CXX_SECURITY_m + */ + +#ifndef _CLASS_PROVIDER_H +#define _CLASS_PROVIDER_H + +#ifdef __cplusplus + +#include "beecrypt/c++/mutex.h" +using beecrypt::mutex; +#include "beecrypt/c++/lang/String.h" +using beecrypt::lang::String; +#include "beecrypt/c++/util/Properties.h" +using beecrypt::util::Properties; + +#include +#include +using std::map; + +namespace beecrypt { + namespace security { + class BEECRYPTCXXAPI Provider : public Properties + { + friend class Security; + + private: + String _name; + String _info; + double _vers; + + mutex _lock; + UConverter* _conv; + + typedef void* (*instantiator)(); + typedef map instantiator_map; + + instantiator_map _imap; + + instantiator getInstantiator(const String& name) const; + + protected: + #if WIN32 + HANDLE _dlhandle; + #else + void* _dlhandle; + #endif + + Provider(const String& name, double version, const String& info); + + public: + virtual ~Provider(); + + void put(const String& key, const String& value); + + const String& getName() const throw (); + const String& getInfo() const throw (); + double getVersion() const throw (); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/PublicKey.h b/beecrypt/c++/security/PublicKey.h new file mode 100644 index 0000000..9336292 --- /dev/null +++ b/beecrypt/c++/security/PublicKey.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file PublicKey.h + * \ingroup CXX_SECURITY_m + */ + +#ifndef _INTERFACE_PUBLICKEY_H +#define _INTERFACE_PUBLICKEY_H + +#ifdef __cplusplus + +#include "beecrypt/c++/security/Key.h" +using beecrypt::security::Key; + +namespace beecrypt { + namespace security { + /*!\brief Public key interface. + * \ingroup CXX_IF_m + */ + class PublicKey : public Key + { + public: + virtual PublicKey* clone() const = 0; + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/SecureRandom.cxx b/beecrypt/c++/security/SecureRandom.cxx new file mode 100644 index 0000000..b25d0e9 --- /dev/null +++ b/beecrypt/c++/security/SecureRandom.cxx @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/security/SecureRandom.h" +#include "beecrypt/c++/security/SecureRandomSpi.h" +#include "beecrypt/c++/security/Security.h" + +using namespace beecrypt::security; + +SecureRandom* SecureRandom::getInstance(const String& algorithm) throw (NoSuchAlgorithmException) +{ + Security::spi* tmp = Security::getSpi(algorithm, "SecureRandom"); + + SecureRandom* result = new SecureRandom((SecureRandomSpi*) tmp->cspi, tmp->name, tmp->prov); + + delete tmp; + + return result; +} + +SecureRandom* SecureRandom::getInstance(const String& type, const String& provider) throw (NoSuchAlgorithmException, NoSuchProviderException) +{ + Security::spi* tmp = Security::getSpi(type, "SecureRandom", provider); + + SecureRandom* result = new SecureRandom((SecureRandomSpi*) tmp->cspi, tmp->name, tmp->prov); + + delete tmp; + + return result; +} + +SecureRandom* SecureRandom::getInstance(const String& type, const Provider& provider) throw (NoSuchAlgorithmException) +{ + Security::spi* tmp = Security::getSpi(type, "SecureRandom", provider); + + SecureRandom* result = new SecureRandom((SecureRandomSpi*) tmp->cspi, tmp->name, tmp->prov); + + delete tmp; + + return result; +} + +void SecureRandom::getSeed(byte* data, size_t size) +{ + entropyGatherNext(data, size); +} + +SecureRandom::SecureRandom() +{ + Security::spi* tmp = Security::getFirstSpi("SecureRandom"); + + _rspi = (SecureRandomSpi*) tmp->cspi; + _type = tmp->name; + _prov = &tmp->prov; + + delete tmp; +} + +SecureRandom::SecureRandom(SecureRandomSpi* rspi, const String& type, const Provider& provider) : _prov(&provider) +{ + _rspi = rspi; + _type = type; + _prov = &provider; +} + +SecureRandom::~SecureRandom() +{ + delete _rspi; +} + +void SecureRandom::generateSeed(byte* data, size_t size) +{ + _rspi->engineGenerateSeed(data, size); +} + +void SecureRandom::setSeed(const byte* data, size_t size) +{ + _rspi->engineSetSeed(data, size); +} + +void SecureRandom::nextBytes(byte* data, size_t size) +{ + _rspi->engineNextBytes(data, size); +} + +const String& SecureRandom::getType() const throw () +{ + return _type; +} + +const Provider& SecureRandom::getProvider() const throw () +{ + return *_prov; +} diff --git a/beecrypt/c++/security/SecureRandom.h b/beecrypt/c++/security/SecureRandom.h new file mode 100644 index 0000000..0baa6e1 --- /dev/null +++ b/beecrypt/c++/security/SecureRandom.h @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file SecureRandom.h + * \ingroup CXX_SECURITY_m + */ + +#ifndef _CLASS_SECURERANDOM_H +#define _CLASS_SECURERANDOM_H + +#include "beecrypt/beecrypt.h" + +#ifdef __cplusplus + +#include "beecrypt/c++/security/SecureRandomSpi.h" +using beecrypt::security::SecureRandomSpi; +#include "beecrypt/c++/security/Provider.h" +using beecrypt::security::Provider; +#include "beecrypt/c++/security/NoSuchAlgorithmException.h" +using beecrypt::security::NoSuchAlgorithmException; +#include "beecrypt/c++/security/NoSuchProviderException.h" +using beecrypt::security::NoSuchProviderException; + +namespace beecrypt { + namespace security { + class BEECRYPTCXXAPI SecureRandom + { + public: + static SecureRandom* getInstance(const String&) throw (NoSuchAlgorithmException); + static SecureRandom* getInstance(const String&, const String&) throw (NoSuchAlgorithmException, NoSuchProviderException); + static SecureRandom* getInstance(const String&, const Provider&) throw (NoSuchAlgorithmException); + + static void getSeed(byte*, size_t); + + private: + SecureRandomSpi* _rspi; + String _type; + const Provider* _prov; + + protected: + SecureRandom(SecureRandomSpi*, const String&, const Provider&); + + public: + SecureRandom(); + ~SecureRandom(); + + void generateSeed(byte*, size_t); + void nextBytes(byte*, size_t); + void setSeed(const byte*, size_t); + + const String& getType() const throw (); + const Provider& getProvider() const throw (); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/SecureRandomSpi.h b/beecrypt/c++/security/SecureRandomSpi.h new file mode 100644 index 0000000..1c4b910 --- /dev/null +++ b/beecrypt/c++/security/SecureRandomSpi.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file SecureRandomSpi.h + * \ingroup CXX_SECURITY_m + */ + +#ifndef _CLASS_SECURERANDOMSPI_H +#define _CLASS_SECURERANDOMSPI_H + +#include "beecrypt/api.h" + +#ifdef __cplusplus + +namespace beecrypt { + namespace security { + class BEECRYPTCXXAPI SecureRandomSpi + { + friend class SecureRandom; + + protected: + virtual void engineGenerateSeed(byte*, size_t) = 0; + virtual void engineNextBytes(byte*, size_t) = 0; + virtual void engineSetSeed(const byte*, size_t) = 0; + + public: + virtual ~SecureRandomSpi() {}; + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/Security.cxx b/beecrypt/c++/security/Security.cxx new file mode 100644 index 0000000..f2b75d0 --- /dev/null +++ b/beecrypt/c++/security/Security.cxx @@ -0,0 +1,404 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/resource.h" +#include "beecrypt/c++/security/Security.h" +#include "beecrypt/c++/io/FileInputStream.h" +using beecrypt::io::FileInputStream; + +#include +#include + +using namespace beecrypt::security; + +namespace { + const String KEYSTORE_DEFAULT_TYPE = UNICODE_STRING_SIMPLE("BEE"); +} + +bool Security::_init = false; +mutex Security::_lock; +Properties Security::_props; +Security::provider_vector Security::_providers; + +/* Have to use lazy initialization here; static initialization doesn't work. + * Initialization adds a provider, apparently in another copy of Security, + * instead of where we would expect it. + * + * Don't dlclose the libraries or uninstall the providers. They'll + * disappear when the program closes. Since this happens only once per + * application which uses this library, that's acceptable. + * + * What we eventually need to do is the following: + * - treat the beecrypt.conf file as a collection of Properties, loaded from + * file with loadProperties. + * - get appropriate properties to do the initialization + */ + +void Security::initialize() +{ + _lock.init(); + _lock.lock(); + _init = true; + _lock.unlock(); + + /* get the configuration file here and load providers */ + const char* path = getenv("BEECRYPT_CONF_FILE"); + + FILE* props; + + if (path) + props = fopen(path, "r"); + else + props = fopen(BEECRYPT_CONF_FILE, "r"); + + if (!props) + { + std::cerr << "couldn't open beecrypt configuration file" << std::endl; + } + else + { + FileInputStream fis(props); + + try + { + // load properties from fis + _props.load(fis); + + for (int32_t index = 1; true; index++) + { + char num[32]; + + sprintf(num, "provider.%d", index); + + String key(num); + + const String* value = _props.getProperty(key); + + if (value) + { + int32_t reqlen = value->extract(0, value->length(), (char*) 0, (const char*) 0); + + char* shared_library = new char[reqlen+1]; + + value->extract(0, value->length(), shared_library, (const char*) 0); + + #if WIN32 + HANDLE handle = LoadLibraryEx(shared_library, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); + #elif HAVE_DLFCN_H + void *handle = dlopen(shared_library, RTLD_NOW); + #else + # error + #endif + + if (handle) + { + #if WIN32 + const Provider& (*inst)(void*) = (const Provider& (*)(void*)) GetProcAddress((HMODULE) handle, "provider_const_ref"); + #elif HAVE_PTHREAD_H + const Provider& (*inst)(void*) = (const Provider& (*)(void*)) dlsym(handle, "provider_const_ref"); + #else + # error + #endif + + if (inst) + { + addProvider(inst(handle)); + } + else + { + std::cerr << "library doesn't contain symbol provider_const_ref" << std::endl; + #if HAVE_DLFCN_H + std::cerr << "dlerror: " << dlerror() << std::endl; + #endif + } + } + else + { + std::cerr << "unable to open shared library " << shared_library << std::endl; + #if HAVE_DLFCN_H + std::cerr << "dlerror: " << dlerror() << std::endl; + #endif + } + + delete[] shared_library; + } + else + break; + } + } + catch (IOException) + { + } + } +} + +Security::spi::spi(void* cspi, const String& name, const Provider& prov) : cspi(cspi), name(name), prov(prov) +{ +} + +Security::spi* Security::getSpi(const String& name, const String& type) throw (NoSuchAlgorithmException) +{ + if (!_init) + initialize(); + + String afind = type + "." + name; + String alias = "Alg.Alias." + type + "." + name; + + _lock.lock(); + for (size_t i = 0; i < _providers.size(); i++) + { + Provider::instantiator inst = 0; + + const Provider* p = _providers[i]; + + if (p->getProperty(afind)) + { + inst = p->getInstantiator(afind); + } + else + { + const String* alias_of = p->getProperty(alias); + + if (alias_of) + inst = p->getInstantiator(*alias_of); + } + + if (inst) + { + register spi* result = new spi(inst(), name, *p); + _lock.unlock(); + return result; + } + } + + _lock.unlock(); + + throw NoSuchAlgorithmException(name + " " + type + " not available"); +} + +Security::spi* Security::getSpi(const String& name, const String& type, const String& provider) throw (NoSuchAlgorithmException, NoSuchProviderException) +{ + if (!_init) + initialize(); + + String afind = type + "." + name; + String alias = "Alg.Alias." + type + "." + name; + + _lock.lock(); + for (size_t i = 0; i < _providers.size(); i++) + { + const Provider* p = _providers[i]; + + if (p->getName() == provider) + { + Provider::instantiator inst = 0; + + const Provider* p = _providers[i]; + + if (p->getProperty(afind)) + { + inst = p->getInstantiator(afind); + } + else + { + const String* alias_of = p->getProperty(alias); + + if (alias_of) + inst = p->getInstantiator(*alias_of); + } + + if (inst) + { + register spi* result = new spi(inst(), name, *p); + _lock.unlock(); + return result; + } + + _lock.unlock(); + + throw NoSuchAlgorithmException(name + " " + type + " not available"); + } + } + + _lock.unlock(); + + throw NoSuchProviderException(provider + " Provider not available"); +} + +Security::spi* Security::getSpi(const String& name, const String& type, const Provider& provider) throw (NoSuchAlgorithmException) +{ + if (!_init) + initialize(); + + String afind = type + "." + name; + String alias = "Alg.Alias." + type + "." + name; + + Provider::instantiator inst = 0; + + if (provider.getProperty(afind)) + { + inst = provider.getInstantiator(afind); + } + else + { + const String* alias_of = provider.getProperty(alias); + + if (alias_of) + inst = provider.getInstantiator(*alias_of); + } + + if (inst) + return new spi(inst(), name, provider); + + throw NoSuchAlgorithmException(name + " " + type + " not available"); +} + +Security::spi* Security::getFirstSpi(const String& type) +{ + if (!_init) + initialize(); + + String afind = type + "."; + + for (size_t i = 0; i < _providers.size(); i++) + { + const Provider* p = _providers[i]; + + Enumeration* e = p->propertyNames(); + + while (e->hasMoreElements()) + { + const String* s = (const String*) e->nextElement(); + + if (s->startsWith(afind)) + { + String name; + + name.setTo(*s, afind.length()); + + Provider::instantiator inst = p->getInstantiator(*s); + + if (inst) + { + delete e; + + return new spi(inst(), name, *p); + } + } + } + + delete e; + } + return 0; +} + +const String& Security::getKeyStoreDefault() +{ + return *_props.getProperty("keystore.default", KEYSTORE_DEFAULT_TYPE); +} + +int Security::addProvider(const Provider& provider) +{ + if (!_init) + initialize(); + + if (getProvider(provider.getName())) + return -1; + + _lock.lock(); + + size_t rc = (int) _providers.size(); + + _providers.push_back(&provider); + + _lock.unlock(); + + return rc; +} + +int Security::insertProviderAt(const Provider& provider, size_t position) +{ + if (!_init) + initialize(); + + if (getProvider(provider.getName())) + return -1; + + _lock.lock(); + + size_t size = _providers.size(); + + if (position > size || position <= 0) + position = size+1; + + _providers.insert(_providers.begin()+position-1, &provider); + + _lock.unlock(); + + return (int) position; +} + +void Security::removeProvider(const String& name) +{ + if (!_init) + initialize(); + + _lock.lock(); + for (provider_vector_iterator it = _providers.begin(); it != _providers.end(); it++) + { + const Provider* p = *it; + + if (p->getName() == name) + { + _providers.erase(it); + _lock.unlock(); + return; + } + } + _lock.unlock(); +} + +const Security::provider_vector& Security::getProviders() +{ + if (!_init) + initialize(); + + return _providers; +} + +const Provider* Security::getProvider(const String& name) +{ + if (!_init) + initialize(); + + for (size_t i = 0; i < _providers.size(); i++) + { + const Provider* tmp = _providers[i]; + + if (tmp->getName() == name) + return _providers[i]; + } + + return 0; +} diff --git a/beecrypt/c++/security/Security.h b/beecrypt/c++/security/Security.h new file mode 100644 index 0000000..2623a85 --- /dev/null +++ b/beecrypt/c++/security/Security.h @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file Security.h + * \ingroup CXX_SECURITY_m + */ + +#ifndef _CLASS_SECURITY_H +#define _CLASS_SECURITY_H + +#ifdef __cplusplus + +#include "beecrypt/c++/mutex.h" +using beecrypt::mutex; +#include "beecrypt/c++/util/Properties.h" +using beecrypt::util::Properties; +#include "beecrypt/c++/security/Provider.h" +using beecrypt::security::Provider; +#include "beecrypt/c++/security/NoSuchAlgorithmException.h" +using beecrypt::security::NoSuchAlgorithmException; +#include "beecrypt/c++/security/NoSuchProviderException.h" +using beecrypt::security::NoSuchProviderException; +#include "beecrypt/c++/security/cert/CertificateFactory.h" +using beecrypt::security::cert::CertificateFactory; +#include "beecrypt/c++/crypto/Mac.h" +using beecrypt::crypto::Mac; +#include "beecrypt/c++/crypto/SecretKeyFactory.h" +using beecrypt::crypto::SecretKeyFactory; + +#include +using std::vector; + +namespace beecrypt { + namespace security { + class BEECRYPTCXXAPI Security + { + friend class AlgorithmParameterGenerator; + friend class AlgorithmParameters; + friend class CertificateFactory; + friend class KeyFactory; + friend class KeyPairGenerator; + friend class KeyStore; + friend class Mac; + friend class MessageDigest; + friend class SecretKeyFactory; + friend class SecureRandom; + friend class Signature; + + public: + typedef vector provider_vector; + typedef provider_vector::iterator provider_vector_iterator; + + private: + struct spi + { + void* cspi; + String name; + const Provider& prov; + + spi(void* cspi, const String&, const Provider&); + }; + + static spi* getSpi(const String& name, const String& type) throw (NoSuchAlgorithmException); + static spi* getSpi(const String& algo, const String& type, const String& provider) throw (NoSuchAlgorithmException, NoSuchProviderException); + static spi* getSpi(const String& algo, const String& type, const Provider&) throw (NoSuchAlgorithmException); + static spi* getFirstSpi(const String& type); + + static const String& getKeyStoreDefault(); + + static bool _init; + static Properties _props; + static mutex _lock; + static provider_vector _providers; + + static void initialize(); + + public: + static int addProvider(const Provider& provider); + static int insertProviderAt(const Provider& provider, size_t position); + static void removeProvider(const String& name); + static const Provider* getProvider(const String& name); + static const provider_vector& getProviders(); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/ShortBufferException.cxx b/beecrypt/c++/security/ShortBufferException.cxx new file mode 100644 index 0000000..f07197e --- /dev/null +++ b/beecrypt/c++/security/ShortBufferException.cxx @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/security/ShortBufferException.h" + +using namespace beecrypt::security; + +ShortBufferException::ShortBufferException() throw () +{ +} + +ShortBufferException::ShortBufferException(const String& message) throw () : GeneralSecurityException(message) +{ +} diff --git a/beecrypt/c++/security/ShortBufferException.h b/beecrypt/c++/security/ShortBufferException.h new file mode 100644 index 0000000..4ee0d38 --- /dev/null +++ b/beecrypt/c++/security/ShortBufferException.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file ShortBufferException.h + * \ingroup CXX_SECURITY_m + */ + +#ifndef _CLASS_SHORTBUFFEREXCEPTION_H +#define _CLASS_SHORTBUFFEREXCEPTION_H + +#ifdef __cplusplus + +#include "beecrypt/c++/security/GeneralSecurityException.h" +using beecrypt::security::GeneralSecurityException; + +namespace beecrypt { + namespace security { + class BEECRYPTCXXAPI ShortBufferException : public GeneralSecurityException + { + public: + ShortBufferException() throw (); + ShortBufferException(const String&) throw (); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/Signature.cxx b/beecrypt/c++/security/Signature.cxx new file mode 100644 index 0000000..5cdb1f6 --- /dev/null +++ b/beecrypt/c++/security/Signature.cxx @@ -0,0 +1,172 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/security/Signature.h" +#include "beecrypt/c++/security/Security.h" + +using namespace beecrypt::security; + +Signature::Signature(SignatureSpi* spi, const String& algorithm, const Provider& provider) +{ + _sspi = spi; + _algo = algorithm; + _prov = &provider; +} + +Signature::~Signature() +{ + delete _sspi; +} + +Signature* Signature::getInstance(const String& algorithm) throw (NoSuchAlgorithmException) +{ + Security::spi* tmp = Security::getSpi(algorithm, "Signature"); + + Signature* result = new Signature((SignatureSpi*) tmp->cspi, tmp->name, tmp->prov); + + delete tmp; + + return result; +} + +Signature* Signature::getInstance(const String& algorithm, const String& provider) throw (NoSuchAlgorithmException, NoSuchProviderException) +{ + Security::spi* tmp = Security::getSpi(algorithm, "Signature", provider); + + Signature* result = new Signature((SignatureSpi*) tmp->cspi, tmp->name, tmp->prov); + + delete tmp; + + return result; +} + +Signature* Signature::getInstance(const String& algorithm, const Provider& provider) throw (NoSuchAlgorithmException) +{ + Security::spi* tmp = Security::getSpi(algorithm, "Signature", provider); + + Signature* result = new Signature((SignatureSpi*) tmp->cspi, tmp->name, tmp->prov); + + delete tmp; + + return result; +} + +AlgorithmParameters* Signature::getParameters() const +{ + return _sspi->engineGetParameters(); +} + +void Signature::setParameter(const AlgorithmParameterSpec& spec) throw (InvalidAlgorithmParameterException) +{ + _sspi->engineSetParameter(spec); +} + +void Signature::initSign(const PrivateKey& key) throw (InvalidKeyException) +{ + _sspi->engineInitSign(key, (SecureRandom*) 0); + + state = SIGN; +} + +void Signature::initSign(const PrivateKey& key, SecureRandom* random) throw (InvalidKeyException) +{ + _sspi->engineInitSign(key, random); + + state = SIGN; +} + +void Signature::initVerify(const PublicKey& key) throw (InvalidKeyException) +{ + _sspi->engineInitVerify(key); + + state = VERIFY; +} + +bytearray* Signature::sign() throw (IllegalStateException, SignatureException) +{ + if (state != SIGN) + throw IllegalStateException("object not initialized for signing"); + + return _sspi->engineSign(); +} + +size_t Signature::sign(byte* outbuf, size_t offset, size_t len) throw (ShortBufferException, IllegalStateException, SignatureException) +{ + if (state != SIGN) + throw IllegalStateException("object not initialized for signing"); + + return _sspi->engineSign(outbuf, offset, len); +} + +size_t Signature::sign(bytearray& out) throw (IllegalStateException, SignatureException) +{ + if (state != SIGN) + throw IllegalStateException("object not initialized for signing"); + + return _sspi->engineSign(out); +} + +bool Signature::verify(const bytearray& signature) throw (IllegalStateException, SignatureException) +{ + return verify(signature.data(), 0, signature.size()); +} + +bool Signature::verify(const byte* signature, size_t offset, size_t len) throw (IllegalStateException, SignatureException) +{ + if (state != VERIFY) + throw IllegalStateException("object not initialized for verification"); + + return _sspi->engineVerify(signature, offset, len); +} + +void Signature::update(byte b) throw (IllegalStateException) +{ + if (state == UNINITIALIZED) + throw IllegalStateException("object not initialized for signing or verification"); + + _sspi->engineUpdate(b); +} + +void Signature::update(const byte* data, size_t offset, size_t len) throw (IllegalStateException) +{ + if (state == UNINITIALIZED) + throw IllegalStateException("object not initialized for signing or verification"); + + _sspi->engineUpdate(data, offset, len); +} + +void Signature::update(const bytearray& b) throw (IllegalStateException) +{ + update(b.data(), 0, b.size()); +} + +const String& Signature::getAlgorithm() const throw () +{ + return _algo; +} + +const Provider& Signature::getProvider() const throw () +{ + return *_prov; +} diff --git a/beecrypt/c++/security/Signature.h b/beecrypt/c++/security/Signature.h new file mode 100644 index 0000000..3a0e29c --- /dev/null +++ b/beecrypt/c++/security/Signature.h @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file Signature.h + * \ingroup CXX_SECURITY_m + */ + +#ifndef _CLASS_SIGNATURE_H +#define _CLASS_SIGNATURE_H + +#include "beecrypt/api.h" + +#ifdef __cplusplus + +#include "beecrypt/c++/security/SignatureSpi.h" +using beecrypt::security::SignatureSpi; +#include "beecrypt/c++/security/NoSuchAlgorithmException.h" +using beecrypt::security::NoSuchAlgorithmException; +#include "beecrypt/c++/security/NoSuchProviderException.h" +using beecrypt::security::NoSuchProviderException; + +namespace beecrypt { + namespace security { + class BEECRYPTCXXAPI Signature + { + protected: + static const int UNINITIALIZED = 0; + static const int VERIFY = 1; + static const int SIGN = 2; + + public: + static Signature* getInstance(const String&) throw (NoSuchAlgorithmException); + static Signature* getInstance(const String&, const String&) throw (NoSuchAlgorithmException, NoSuchProviderException); + static Signature* getInstance(const String&, const Provider&) throw (NoSuchAlgorithmException); + + protected: + int state; + + private: + SignatureSpi* _sspi; + String _algo; + const Provider* _prov; + + protected: + Signature(SignatureSpi*, const String&, const Provider&); + + public: + ~Signature(); + + AlgorithmParameters* getParameters() const; + void setParameter(const AlgorithmParameterSpec&) throw (InvalidAlgorithmParameterException); + + void initSign(const PrivateKey&) throw (InvalidKeyException); + void initSign(const PrivateKey&, SecureRandom*) throw (InvalidKeyException); + + void initVerify(const PublicKey&) throw (InvalidKeyException); + + bytearray* sign() throw (IllegalStateException, SignatureException); + size_t sign(byte*, size_t, size_t) throw (ShortBufferException, IllegalStateException, SignatureException); + size_t sign(bytearray&) throw (IllegalStateException, SignatureException); + bool verify(const bytearray&) throw (IllegalStateException, SignatureException); + bool verify(const byte*, size_t, size_t) throw (IllegalStateException, SignatureException); + + void update(byte) throw (IllegalStateException); + void update(const byte*, size_t, size_t) throw (IllegalStateException); + void update(const bytearray&) throw (IllegalStateException); + + const String& getAlgorithm() const throw (); + const Provider& getProvider() const throw (); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/SignatureException.cxx b/beecrypt/c++/security/SignatureException.cxx new file mode 100644 index 0000000..4cc3296 --- /dev/null +++ b/beecrypt/c++/security/SignatureException.cxx @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/security/SignatureException.h" + +using namespace beecrypt::security; + +SignatureException::SignatureException() throw () +{ +} + +SignatureException::SignatureException(const String& message) throw () : GeneralSecurityException(message) +{ +} diff --git a/beecrypt/c++/security/SignatureException.h b/beecrypt/c++/security/SignatureException.h new file mode 100644 index 0000000..32dd1bd --- /dev/null +++ b/beecrypt/c++/security/SignatureException.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file SignatureException.h + * \ingroup CXX_SECURITY_m + */ + +#ifndef _CLASS_SIGNATUREEXCEPTION_H +#define _CLASS_SIGNATUREEXCEPTION_H + +#ifdef __cplusplus + +#include "beecrypt/c++/security/GeneralSecurityException.h" +using beecrypt::security::GeneralSecurityException; + +namespace beecrypt { + namespace security { + class BEECRYPTCXXAPI SignatureException : public GeneralSecurityException + { + public: + SignatureException() throw (); + SignatureException(const String&) throw (); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/SignatureSpi.h b/beecrypt/c++/security/SignatureSpi.h new file mode 100644 index 0000000..3469e57 --- /dev/null +++ b/beecrypt/c++/security/SignatureSpi.h @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file SignatureSpi.h + * \ingroup CXX_SECURITY_m + */ + +#ifndef _CLASS_SIGNATURESPI_H +#define _CLASS_SIGNATURESPI_H + +#include "beecrypt/api.h" + +#ifdef __cplusplus + +#include "beecrypt/c++/array.h" +using beecrypt::bytearray; +#include "beecrypt/c++/lang/IllegalStateException.h" +using beecrypt::lang::IllegalStateException; +#include "beecrypt/c++/security/AlgorithmParameters.h" +using beecrypt::security::AlgorithmParameters; +#include "beecrypt/c++/security/PrivateKey.h" +using beecrypt::security::PrivateKey; +#include "beecrypt/c++/security/PublicKey.h" +using beecrypt::security::PublicKey; +#include "beecrypt/c++/security/SecureRandom.h" +using beecrypt::security::SecureRandom; +#include "beecrypt/c++/security/InvalidAlgorithmParameterException.h" +using beecrypt::security::InvalidAlgorithmParameterException; +#include "beecrypt/c++/security/InvalidKeyException.h" +using beecrypt::security::InvalidKeyException; +#include "beecrypt/c++/security/ShortBufferException.h" +using beecrypt::security::ShortBufferException; +#include "beecrypt/c++/security/SignatureException.h" +using beecrypt::security::SignatureException; +#include "beecrypt/c++/security/spec/AlgorithmParameterSpec.h" +using beecrypt::security::spec::AlgorithmParameterSpec; + +namespace beecrypt { + namespace security { + class BEECRYPTCXXAPI SignatureSpi + { + friend class Signature; + + protected: + virtual AlgorithmParameters* engineGetParameters() const = 0; + virtual void engineSetParameter(const AlgorithmParameterSpec&) throw (InvalidAlgorithmParameterException) = 0; + + virtual void engineInitSign(const PrivateKey&, SecureRandom*) throw (InvalidKeyException) = 0; + + virtual void engineInitVerify(const PublicKey&) = 0; + + virtual void engineUpdate(byte) = 0; + virtual void engineUpdate(const byte*, size_t, size_t) = 0; + + virtual bytearray* engineSign() throw (SignatureException) = 0; + virtual size_t engineSign(byte*, size_t, size_t) throw (ShortBufferException, SignatureException) = 0; + virtual size_t engineSign(bytearray&) throw (SignatureException) = 0; + virtual bool engineVerify(const byte*, size_t, size_t) throw (SignatureException) = 0; + + public: + virtual ~SignatureSpi() {}; + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/UnrecoverableKeyException.cxx b/beecrypt/c++/security/UnrecoverableKeyException.cxx new file mode 100644 index 0000000..a46552a --- /dev/null +++ b/beecrypt/c++/security/UnrecoverableKeyException.cxx @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/security/UnrecoverableKeyException.h" + +using namespace beecrypt::security; + +UnrecoverableKeyException::UnrecoverableKeyException() throw () +{ +} + +UnrecoverableKeyException::UnrecoverableKeyException(const String& message) throw () : GeneralSecurityException(message) +{ +} diff --git a/beecrypt/c++/security/UnrecoverableKeyException.h b/beecrypt/c++/security/UnrecoverableKeyException.h new file mode 100644 index 0000000..f4eb887 --- /dev/null +++ b/beecrypt/c++/security/UnrecoverableKeyException.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file UnrecoverableKeyException.h + * \ingroup CXX_SECURITY_m + */ + +#ifndef _CLASS_UNRECOVERABLEKEYEXCEPTION_H +#define _CLASS_UNRECOVERABLEKEYEXCEPTION_H + +#ifdef __cplusplus + +#include "beecrypt/c++/security/GeneralSecurityException.h" +using beecrypt::security::GeneralSecurityException; + +namespace beecrypt { + namespace security { + class BEECRYPTCXXAPI UnrecoverableKeyException : public GeneralSecurityException + { + public: + UnrecoverableKeyException() throw (); + UnrecoverableKeyException(const String&) throw (); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/cert/Certificate.cxx b/beecrypt/c++/security/cert/Certificate.cxx new file mode 100644 index 0000000..aa58a98 --- /dev/null +++ b/beecrypt/c++/security/cert/Certificate.cxx @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/security/cert/Certificate.h" + +using namespace beecrypt::security::cert; + +Certificate::Certificate(const String& type) +{ + _type = type; +} + +Certificate::~Certificate() +{ +} + +bool Certificate::operator==(const Certificate& cmp) const +{ + if (this == &cmp) + return true; + + if (_type != cmp._type) + return false; + + if (getEncoded() != cmp.getEncoded()) + return false; + + return true; +} + +const String& Certificate::getType() const throw () +{ + return _type; +} diff --git a/beecrypt/c++/security/cert/Certificate.h b/beecrypt/c++/security/cert/Certificate.h new file mode 100644 index 0000000..0911652 --- /dev/null +++ b/beecrypt/c++/security/cert/Certificate.h @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file Certificate.h + * \ingroup CXX_SECURITY_CERT_m + */ + +#ifndef _CLASS_CERTIFICATE_H +#define _CLASS_CERTIFICATE_H + +#ifdef __cplusplus + +#include "beecrypt/c++/array.h" +using beecrypt::array; +#include "beecrypt/c++/security/PublicKey.h" +using beecrypt::security::PublicKey; +#include "beecrypt/c++/security/InvalidKeyException.h" +using beecrypt::security::InvalidKeyException; +#include "beecrypt/c++/security/NoSuchAlgorithmException.h" +using beecrypt::security::NoSuchAlgorithmException; +#include "beecrypt/c++/security/NoSuchProviderException.h" +using beecrypt::security::NoSuchProviderException; +#include "beecrypt/c++/security/SignatureException.h" +using beecrypt::security::SignatureException; +#include "beecrypt/c++/security/cert/CertificateException.h" +using beecrypt::security::cert::CertificateException; + +namespace beecrypt { + namespace security { + namespace cert { + class BEECRYPTCXXAPI Certificate + { + private: + String _type; + + protected: + Certificate(const String& type); + + public: + virtual ~Certificate(); + + virtual bool operator==(const Certificate&) const; + + virtual Certificate* clone() const = 0; + + virtual const bytearray& getEncoded() const = 0; + virtual const PublicKey& getPublicKey() const = 0; + + virtual void verify(const PublicKey&) throw (CertificateException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException) = 0; + virtual void verify(const PublicKey&, const String&) throw (CertificateException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException) = 0; + + virtual const String& toString() const throw () = 0; + + const String& getType() const throw (); + }; + } + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/cert/CertificateException.cxx b/beecrypt/c++/security/cert/CertificateException.cxx new file mode 100644 index 0000000..9b0f994 --- /dev/null +++ b/beecrypt/c++/security/cert/CertificateException.cxx @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/security/cert/CertificateException.h" + +using namespace beecrypt::security::cert; + +CertificateException::CertificateException() throw () +{ +} + +CertificateException::CertificateException(const String& message) throw () : GeneralSecurityException(message) +{ +} diff --git a/beecrypt/c++/security/cert/CertificateException.h b/beecrypt/c++/security/cert/CertificateException.h new file mode 100644 index 0000000..db0185a --- /dev/null +++ b/beecrypt/c++/security/cert/CertificateException.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file CertificateException.h + * \ingroup CXX_SECURITY_CERT_m + */ + +#ifndef _CLASS_CERTIFICATEEXCEPTION_H +#define _CLASS_CERTIFICATEEXCEPTION_H + +#ifdef __cplusplus + +#include "beecrypt/c++/security/GeneralSecurityException.h" +using beecrypt::security::GeneralSecurityException; + +namespace beecrypt { + namespace security { + namespace cert { + class BEECRYPTCXXAPI CertificateException : public GeneralSecurityException + { + public: + CertificateException() throw (); + CertificateException(const String&) throw (); + }; + } + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/cert/CertificateExpiredException.cxx b/beecrypt/c++/security/cert/CertificateExpiredException.cxx new file mode 100644 index 0000000..7adf29a --- /dev/null +++ b/beecrypt/c++/security/cert/CertificateExpiredException.cxx @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/security/cert/CertificateExpiredException.h" + +using namespace beecrypt::security::cert; + +CertificateExpiredException::CertificateExpiredException() throw () +{ +} + +CertificateExpiredException::CertificateExpiredException(const String& message) throw () : CertificateException(message) +{ +} diff --git a/beecrypt/c++/security/cert/CertificateExpiredException.h b/beecrypt/c++/security/cert/CertificateExpiredException.h new file mode 100644 index 0000000..9ab9be6 --- /dev/null +++ b/beecrypt/c++/security/cert/CertificateExpiredException.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file CertificateExpiredException.h + * \ingroup CXX_SECURITY_CERT_m + */ + +#ifndef _CLASS_CERTIFICATEEXPIREDEXCEPTION_H +#define _CLASS_CERTIFICATEEXPIREDEXCEPTION_H + +#ifdef __cplusplus + +#include "beecrypt/c++/security/cert/CertificateException.h" +using beecrypt::security::cert::CertificateException; + +namespace beecrypt { + namespace security { + namespace cert { + class BEECRYPTCXXAPI CertificateExpiredException : public CertificateException + { + public: + CertificateExpiredException() throw (); + CertificateExpiredException(const String&) throw (); + }; + } + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/cert/CertificateFactory.cxx b/beecrypt/c++/security/cert/CertificateFactory.cxx new file mode 100644 index 0000000..84d91da --- /dev/null +++ b/beecrypt/c++/security/cert/CertificateFactory.cxx @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/security/Security.h" +#include "beecrypt/c++/security/cert/CertificateFactory.h" + +using namespace beecrypt::security::cert; + +CertificateFactory::CertificateFactory(CertificateFactorySpi* spi, const String& type, const Provider& provider) +{ + _cspi = spi; + _type = type; + _prov = &provider; +} + +CertificateFactory::~CertificateFactory() +{ + delete _cspi; +} + +CertificateFactory* CertificateFactory::getInstance(const String& type) throw (NoSuchAlgorithmException) +{ + Security::spi* tmp = Security::getSpi(type, "CertificateFactory"); + + CertificateFactory* result = new CertificateFactory((CertificateFactorySpi*) tmp->cspi, tmp->name, tmp->prov); + + delete tmp; + + return result; +} + +CertificateFactory* CertificateFactory::getInstance(const String& type, const String& provider) throw (NoSuchAlgorithmException, NoSuchProviderException) +{ + Security::spi* tmp = Security::getSpi(type, "CertificateFactory", provider); + + CertificateFactory* result = new CertificateFactory((CertificateFactorySpi*) tmp->cspi, tmp->name, tmp->prov); + + delete tmp; + + return result; +} + +CertificateFactory* CertificateFactory::getInstance(const String& type, const Provider& provider) throw (NoSuchAlgorithmException) +{ + Security::spi* tmp = Security::getSpi(type, "CertificateFactory", provider); + + CertificateFactory* result = new CertificateFactory((CertificateFactorySpi*) tmp->cspi, tmp->name, tmp->prov); + + delete tmp; + + return result; +} + +Certificate* CertificateFactory::generateCertificate(InputStream& in) throw (CertificateException) +{ + return _cspi->engineGenerateCertificate(in); +} + +vector* CertificateFactory::generateCertificates(InputStream& in) throw (CertificateException) +{ + return _cspi->engineGenerateCertificates(in); +} + +const String& CertificateFactory::getType() const throw () +{ + return _type; +} + +const Provider& CertificateFactory::getProvider() const throw () +{ + return *_prov; +} diff --git a/beecrypt/c++/security/cert/CertificateFactory.h b/beecrypt/c++/security/cert/CertificateFactory.h new file mode 100644 index 0000000..09b43b7 --- /dev/null +++ b/beecrypt/c++/security/cert/CertificateFactory.h @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file CertificateFactory.h + * \ingroup CXX_SECURITY_CERT_m + */ + +#ifndef _CLASS_CERTIFICATEFACTORY_H +#define _CLASS_CERTIFICATEFACTORY_H + +#ifdef __cplusplus + +#include "beecrypt/c++/lang/String.h" +using beecrypt::lang::String; +#include "beecrypt/c++/security/Provider.h" +using beecrypt::security::Provider; +#include "beecrypt/c++/security/NoSuchAlgorithmException.h" +using beecrypt::security::NoSuchAlgorithmException; +#include "beecrypt/c++/security/cert/Certificate.h" +using beecrypt::security::cert::Certificate; +#include "beecrypt/c++/security/cert/CertificateFactorySpi.h" +using beecrypt::security::cert::CertificateFactorySpi; + +#include +using std::vector; + +namespace beecrypt { + namespace security { + namespace cert { + class BEECRYPTCXXAPI CertificateFactory + { + public: + static CertificateFactory* getInstance(const String&) throw (NoSuchAlgorithmException); + static CertificateFactory* getInstance(const String&, const String&) throw (NoSuchAlgorithmException, NoSuchProviderException); + static CertificateFactory* getInstance(const String&, const Provider&) throw (NoSuchAlgorithmException); + + private: + CertificateFactorySpi* _cspi; + String _type; + const Provider* _prov; + + protected: + CertificateFactory(CertificateFactorySpi*, const String&, const Provider&); + + public: + ~CertificateFactory(); + + Certificate* generateCertificate(InputStream& in) throw (CertificateException); + vector* generateCertificates(InputStream& in) throw (CertificateException); + + const String& getType() const throw (); + const Provider& getProvider() const throw (); + }; + } + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/cert/CertificateFactorySpi.h b/beecrypt/c++/security/cert/CertificateFactorySpi.h new file mode 100644 index 0000000..b42fdcf --- /dev/null +++ b/beecrypt/c++/security/cert/CertificateFactorySpi.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file CertificateFactorySpi.h + * \ingroup CXX_SECURITY_CERT_m + */ + +#ifndef _CLASS_CERTIFICATEFACTORYSPI_H +#define _CLASS_CERTIFICATEFACTORYSPI_H + +#include "beecrypt/api.h" + +#ifdef __cplusplus + +#include "beecrypt/c++/io/InputStream.h" +using beecrypt::io::InputStream; +#include "beecrypt/c++/io/OutputStream.h" +using beecrypt::io::OutputStream; +#include "beecrypt/c++/security/cert/Certificate.h" +using beecrypt::security::cert::Certificate; + +#include +using std::vector; + +namespace beecrypt { + namespace security { + namespace cert { + class BEECRYPTCXXAPI CertificateFactorySpi + { + friend class CertificateFactory; + + protected: + virtual Certificate* engineGenerateCertificate(InputStream& in) throw (CertificateException) = 0; + virtual vector* engineGenerateCertificates(InputStream& in) throw (CertificateException) = 0; + + public: + virtual ~CertificateFactorySpi() {}; + }; + } + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/cert/CertificateNotYetValidException.cxx b/beecrypt/c++/security/cert/CertificateNotYetValidException.cxx new file mode 100644 index 0000000..6bcdc8d --- /dev/null +++ b/beecrypt/c++/security/cert/CertificateNotYetValidException.cxx @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/security/cert/CertificateNotYetValidException.h" + +using namespace beecrypt::security::cert; + +CertificateNotYetValidException::CertificateNotYetValidException() throw () +{ +} + +CertificateNotYetValidException::CertificateNotYetValidException(const String& message) throw () : CertificateException(message) +{ +} diff --git a/beecrypt/c++/security/cert/CertificateNotYetValidException.h b/beecrypt/c++/security/cert/CertificateNotYetValidException.h new file mode 100644 index 0000000..b9524f1 --- /dev/null +++ b/beecrypt/c++/security/cert/CertificateNotYetValidException.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file CertificateNotYetValidException.h + * \ingroup CXX_SECURITY_CERT_m + */ + +#ifndef _CLASS_CERTIFICATENOTYETVALIDEXCEPTION_H +#define _CLASS_CERTIFICATENOTYETVALIDEXCEPTION_H + +#ifdef __cplusplus + +#include "beecrypt/c++/security/cert/CertificateException.h" +using beecrypt::security::cert::CertificateException; + +namespace beecrypt { + namespace security { + namespace cert { + class BEECRYPTCXXAPI CertificateNotYetValidException : public CertificateException + { + public: + CertificateNotYetValidException() throw (); + CertificateNotYetValidException(const String&) throw (); + }; + } + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/cert/Makefile.am b/beecrypt/c++/security/cert/Makefile.am new file mode 100644 index 0000000..7fa6b2e --- /dev/null +++ b/beecrypt/c++/security/cert/Makefile.am @@ -0,0 +1,22 @@ +INCLUDES = -I$(top_srcdir)/.. + +AUTOMAKE_OPTIONS = gnu no-dependencies + +noinst_LTLIBRARIES = libcxxsecuritycert.la + +cxxsecuritycertdir=$(pkgincludedir)/c++/security/cert + +libcxxsecuritycert_la_SOURCES =\ +Certificate.cxx \ +CertificateException.cxx \ +CertificateExpiredException.cxx \ +CertificateFactory.cxx \ +CertificateNotYetValidException.cxx + +cxxsecuritycert_HEADERS =\ +Certificate.h \ +CertificateException.h \ +CertificateExpiredException.h \ +CertificateFactory.h \ +CertificateFactorySpi.h \ +CertificateNotYetValidException.h diff --git a/beecrypt/c++/security/cert/Makefile.in b/beecrypt/c++/security/cert/Makefile.in new file mode 100644 index 0000000..5612ecd --- /dev/null +++ b/beecrypt/c++/security/cert/Makefile.in @@ -0,0 +1,500 @@ +# Makefile.in generated by automake 1.8.3 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + + +SOURCES = $(libcxxsecuritycert_la_SOURCES) + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +top_builddir = ../../.. +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +INSTALL = @INSTALL@ +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +host_triplet = @host@ +subdir = c++/security/cert +DIST_COMMON = $(cxxsecuritycert_HEADERS) $(srcdir)/Makefile.am \ + $(srcdir)/Makefile.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \ + $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +LTLIBRARIES = $(noinst_LTLIBRARIES) +libcxxsecuritycert_la_LIBADD = +am_libcxxsecuritycert_la_OBJECTS = Certificate.lo \ + CertificateException.lo CertificateExpiredException.lo \ + CertificateFactory.lo CertificateNotYetValidException.lo +libcxxsecuritycert_la_OBJECTS = $(am_libcxxsecuritycert_la_OBJECTS) +DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir) +depcomp = +am__depfiles_maybe = +CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) +LTCXXCOMPILE = $(LIBTOOL) --mode=compile $(CXX) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CXXFLAGS) $(CXXFLAGS) +CXXLD = $(CXX) +CXXLINK = $(LIBTOOL) --mode=link $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) \ + $(AM_LDFLAGS) $(LDFLAGS) -o $@ +SOURCES = $(libcxxsecuritycert_la_SOURCES) +DIST_SOURCES = $(libcxxsecuritycert_la_SOURCES) +am__installdirs = "$(DESTDIR)$(cxxsecuritycertdir)" +cxxsecuritycertHEADERS_INSTALL = $(INSTALL_HEADER) +HEADERS = $(cxxsecuritycert_HEADERS) +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMDEP_FALSE = @AMDEP_FALSE@ +AMDEP_TRUE = @AMDEP_TRUE@ +AMTAR = @AMTAR@ +AR = @AR@ +AS = @AS@ +ASM_ALIGN = @ASM_ALIGN@ +ASM_ARCH = @ASM_ARCH@ +ASM_BIGENDIAN = @ASM_BIGENDIAN@ +ASM_CPU = @ASM_CPU@ +ASM_GLOBL = @ASM_GLOBL@ +ASM_GSYM_PREFIX = @ASM_GSYM_PREFIX@ +ASM_LSYM_PREFIX = @ASM_LSYM_PREFIX@ +ASM_OS = @ASM_OS@ +ASM_TEXTSEG = @ASM_TEXTSEG@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCAS = @CCAS@ +CCASFLAGS = @CCASFLAGS@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DLLTOOL = @DLLTOOL@ +ECHO = @ECHO@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +F77 = @F77@ +FFLAGS = @FFLAGS@ +INCLUDE_DLFCN_H = @INCLUDE_DLFCN_H@ +INCLUDE_INTTYPES_H = @INCLUDE_INTTYPES_H@ +INCLUDE_MALLOC_H = @INCLUDE_MALLOC_H@ +INCLUDE_PTHREAD_H = @INCLUDE_PTHREAD_H@ +INCLUDE_STDINT_H = @INCLUDE_STDINT_H@ +INCLUDE_STDIO_H = @INCLUDE_STDIO_H@ +INCLUDE_STDLIB_H = @INCLUDE_STDLIB_H@ +INCLUDE_STRING_H = @INCLUDE_STRING_H@ +INCLUDE_SYNCH_H = @INCLUDE_SYNCH_H@ +INCLUDE_THREAD_H = @INCLUDE_THREAD_H@ +INCLUDE_UNISTD_H = @INCLUDE_UNISTD_H@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +JAVAINC = @JAVAINC@ +LDFLAGS = @LDFLAGS@ +LIBALT = @LIBALT@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +MAYBE_LTLIB = @MAYBE_LTLIB@ +MAYBE_SUB = @MAYBE_SUB@ +MP_WBITS = @MP_WBITS@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PYTHONINC = @PYTHONINC@ +PYTHONLIB = @PYTHONLIB@ +RANLIB = @RANLIB@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +TYPEDEF_BC_COND_T = @TYPEDEF_BC_COND_T@ +TYPEDEF_BC_MUTEX_T = @TYPEDEF_BC_MUTEX_T@ +TYPEDEF_BC_THREAD_T = @TYPEDEF_BC_THREAD_T@ +TYPEDEF_INT16_T = @TYPEDEF_INT16_T@ +TYPEDEF_INT32_T = @TYPEDEF_INT32_T@ +TYPEDEF_INT64_T = @TYPEDEF_INT64_T@ +TYPEDEF_INT8_T = @TYPEDEF_INT8_T@ +TYPEDEF_SIZE_T = @TYPEDEF_SIZE_T@ +TYPEDEF_UINT16_T = @TYPEDEF_UINT16_T@ +TYPEDEF_UINT32_T = @TYPEDEF_UINT32_T@ +TYPEDEF_UINT64_T = @TYPEDEF_UINT64_T@ +TYPEDEF_UINT8_T = @TYPEDEF_UINT8_T@ +VERSION = @VERSION@ +ac_ct_AR = @ac_ct_AR@ +ac_ct_AS = @ac_ct_AS@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DLLTOOL = @ac_ct_DLLTOOL@ +ac_ct_F77 = @ac_ct_F77@ +ac_ct_OBJDUMP = @ac_ct_OBJDUMP@ +ac_ct_RANLIB = @ac_ct_RANLIB@ +ac_ct_STRIP = @ac_ct_STRIP@ +ac_cv_have_gcj = @ac_cv_have_gcj@ +ac_cv_have_java = @ac_cv_have_java@ +ac_cv_have_javac = @ac_cv_have_javac@ +ac_cv_have_python = @ac_cv_have_python@ +am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ +am__fastdepCC_TRUE = @am__fastdepCC_TRUE@ +am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@ +am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +datadir = @datadir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +sysconfdir = @sysconfdir@ +target = @target@ +target_alias = @target_alias@ +target_cpu = @target_cpu@ +target_os = @target_os@ +target_vendor = @target_vendor@ +INCLUDES = -I$(top_srcdir)/.. +AUTOMAKE_OPTIONS = gnu no-dependencies +noinst_LTLIBRARIES = libcxxsecuritycert.la +cxxsecuritycertdir = $(pkgincludedir)/c++/security/cert +libcxxsecuritycert_la_SOURCES = \ +Certificate.cxx \ +CertificateException.cxx \ +CertificateExpiredException.cxx \ +CertificateFactory.cxx \ +CertificateNotYetValidException.cxx + +cxxsecuritycert_HEADERS = \ +Certificate.h \ +CertificateException.h \ +CertificateExpiredException.h \ +CertificateFactory.h \ +CertificateFactorySpi.h \ +CertificateNotYetValidException.h + +all: all-am + +.SUFFIXES: +.SUFFIXES: .cxx .lo .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ + && exit 0; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu c++/security/cert/Makefile'; \ + cd $(top_srcdir) && \ + $(AUTOMAKE) --gnu c++/security/cert/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +clean-noinstLTLIBRARIES: + -test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES) + @list='$(noinst_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" = "$$p" && dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +libcxxsecuritycert.la: $(libcxxsecuritycert_la_OBJECTS) $(libcxxsecuritycert_la_DEPENDENCIES) + $(CXXLINK) $(libcxxsecuritycert_la_LDFLAGS) $(libcxxsecuritycert_la_OBJECTS) $(libcxxsecuritycert_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +.cxx.o: + $(CXXCOMPILE) -c -o $@ $< + +.cxx.obj: + $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +.cxx.lo: + $(LTCXXCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +distclean-libtool: + -rm -f libtool +uninstall-info-am: +install-cxxsecuritycertHEADERS: $(cxxsecuritycert_HEADERS) + @$(NORMAL_INSTALL) + test -z "$(cxxsecuritycertdir)" || $(mkdir_p) "$(DESTDIR)$(cxxsecuritycertdir)" + @list='$(cxxsecuritycert_HEADERS)'; for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + f="`echo $$p | sed -e 's|^.*/||'`"; \ + echo " $(cxxsecuritycertHEADERS_INSTALL) '$$d$$p' '$(DESTDIR)$(cxxsecuritycertdir)/$$f'"; \ + $(cxxsecuritycertHEADERS_INSTALL) "$$d$$p" "$(DESTDIR)$(cxxsecuritycertdir)/$$f"; \ + done + +uninstall-cxxsecuritycertHEADERS: + @$(NORMAL_UNINSTALL) + @list='$(cxxsecuritycert_HEADERS)'; for p in $$list; do \ + f="`echo $$p | sed -e 's|^.*/||'`"; \ + echo " rm -f '$(DESTDIR)$(cxxsecuritycertdir)/$$f'"; \ + rm -f "$(DESTDIR)$(cxxsecuritycertdir)/$$f"; \ + done + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(ETAGS_ARGS)$$tags$$unique" \ + || $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$tags $$unique +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(CTAGS_ARGS)$$tags$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$tags $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && cd $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) $$here + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \ + list='$(DISTFILES)'; for file in $$list; do \ + case $$file in \ + $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \ + $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \ + esac; \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test "$$dir" != "$$file" && test "$$dir" != "."; then \ + dir="/$$dir"; \ + $(mkdir_p) "$(distdir)$$dir"; \ + else \ + dir=''; \ + fi; \ + if test -d $$d/$$file; then \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + fi; \ + cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ + else \ + test -f $(distdir)/$$file \ + || cp -p $$d/$$file $(distdir)/$$file \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(LTLIBRARIES) $(HEADERS) +installdirs: + for dir in "$(DESTDIR)$(cxxsecuritycertdir)"; do \ + test -z "$$dir" || $(mkdir_p) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -rm -f $(CONFIG_CLEAN_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libtool clean-noinstLTLIBRARIES \ + mostlyclean-am + +distclean: distclean-am + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-libtool distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +info: info-am + +info-am: + +install-data-am: install-cxxsecuritycertHEADERS + +install-exec-am: + +install-info: install-info-am + +install-man: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-cxxsecuritycertHEADERS uninstall-info-am + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-libtool clean-noinstLTLIBRARIES ctags distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-tags distdir dvi dvi-am html html-am info info-am \ + install install-am install-cxxsecuritycertHEADERS install-data \ + install-data-am install-exec install-exec-am install-info \ + install-info-am install-man install-strip installcheck \ + installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags uninstall uninstall-am uninstall-cxxsecuritycertHEADERS \ + uninstall-info-am + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/beecrypt/c++/security/interfaces/DSAKey.h b/beecrypt/c++/security/interfaces/DSAKey.h new file mode 100644 index 0000000..edf865a --- /dev/null +++ b/beecrypt/c++/security/interfaces/DSAKey.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file DSAKey.h + * \ingroup CXX_SECURITY_INTERFACES_m + */ + +#ifndef _INTERFACE_DSAKEY_H +#define _INTERFACE_DSAKEY_H + +#ifdef __cplusplus + +#include "beecrypt/c++/security/interfaces/DSAParams.h" +using beecrypt::security::interfaces::DSAParams; + +namespace beecrypt { + namespace security { + namespace interfaces { + /*!\brief DSA key interface. + * \ingroup CXX_IF_m + */ + class DSAKey + { + public: + virtual const DSAParams& getParams() const throw () = 0; + }; + } + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/interfaces/DSAParams.h b/beecrypt/c++/security/interfaces/DSAParams.h new file mode 100644 index 0000000..d066c18 --- /dev/null +++ b/beecrypt/c++/security/interfaces/DSAParams.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file DSAParams.h + * \ingroup CXX_SECURITY_INTERFACES_m + */ + +#ifndef _INTERFACE_DSAPARAMS_H +#define _INTERFACE_DSAPARAMS_H + +#include "beecrypt/api.h" +#include "beecrypt/mpbarrett.h" + +#ifdef __cplusplus + +namespace beecrypt { + namespace security { + namespace interfaces { + class DSAParams + { + public: + virtual const mpbarrett& getP() const throw () = 0; + virtual const mpbarrett& getQ() const throw () = 0; + virtual const mpnumber& getG() const throw () = 0; + }; + } + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/interfaces/DSAPrivateKey.h b/beecrypt/c++/security/interfaces/DSAPrivateKey.h new file mode 100644 index 0000000..1bad935 --- /dev/null +++ b/beecrypt/c++/security/interfaces/DSAPrivateKey.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file DSAPrivateKey.h + * \ingroup CXX_SECURITY_INTERFACES_m + */ + +#ifndef _INTERFACE_DSAPRIVATEKEY_H +#define _INTERFACE_DSAPRIVATEKEY_H + +#ifdef __cplusplus + +#include "beecrypt/c++/security/PrivateKey.h" +using beecrypt::security::PrivateKey; +#include "beecrypt/c++/security/interfaces/DSAKey.h" +using beecrypt::security::interfaces::DSAKey; + +namespace beecrypt { + namespace security { + namespace interfaces { + /*!\brief DSA PriveKey interface + * \ingroup CXX_IF_m + */ + class DSAPrivateKey : public PrivateKey, public DSAKey + { + public: + virtual const mpnumber& getX() const throw () = 0; + }; + } + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/interfaces/DSAPublicKey.h b/beecrypt/c++/security/interfaces/DSAPublicKey.h new file mode 100644 index 0000000..f596c9e --- /dev/null +++ b/beecrypt/c++/security/interfaces/DSAPublicKey.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file DSAPublicKey.h + * \ingroup CXX_SECURITY_INTERFACES_m + */ + +#ifndef _INTERFACE_DSAPUBLICKEY_H +#define _INTERFACE_DSAPUBLICKEY_H + +#ifdef __cplusplus + +#include "beecrypt/c++/security/PublicKey.h" +using beecrypt::security::PublicKey; +#include "beecrypt/c++/security/interfaces/DSAKey.h" +using beecrypt::security::interfaces::DSAKey; + +namespace beecrypt { + namespace security { + namespace interfaces { + /*!\brief DSA PublicKey interface + * \ingroup CXX_IF_m + */ + class DSAPublicKey : public PublicKey, public DSAKey + { + public: + virtual const mpnumber& getY() const throw () = 0; + }; + } + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/interfaces/Makefile.am b/beecrypt/c++/security/interfaces/Makefile.am new file mode 100644 index 0000000..f7f4d16 --- /dev/null +++ b/beecrypt/c++/security/interfaces/Makefile.am @@ -0,0 +1,15 @@ +INCLUDES = -I$(top_srcdir)/.. + +AUTOMAKE_OPTIONS = gnu no-dependencies + +cxxsecurityinterfacesdir=$(pkgincludedir)/c++/security/interfaces + +cxxsecurityinterfaces_HEADERS =\ +DSAKey.h \ +DSAParams.h \ +DSAPrivateKey.h \ +DSAPublicKey.h \ +RSAKey.h \ +RSAPrivateCrtKey.h \ +RSAPrivateKey.h \ +RSAPublicKey.h diff --git a/beecrypt/c++/security/interfaces/Makefile.in b/beecrypt/c++/security/interfaces/Makefile.in new file mode 100644 index 0000000..fabf6fe --- /dev/null +++ b/beecrypt/c++/security/interfaces/Makefile.in @@ -0,0 +1,447 @@ +# Makefile.in generated by automake 1.8.3 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +top_builddir = ../../.. +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +INSTALL = @INSTALL@ +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +host_triplet = @host@ +subdir = c++/security/interfaces +DIST_COMMON = $(cxxsecurityinterfaces_HEADERS) $(srcdir)/Makefile.am \ + $(srcdir)/Makefile.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \ + $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +depcomp = +am__depfiles_maybe = +SOURCES = +DIST_SOURCES = +am__installdirs = "$(DESTDIR)$(cxxsecurityinterfacesdir)" +cxxsecurityinterfacesHEADERS_INSTALL = $(INSTALL_HEADER) +HEADERS = $(cxxsecurityinterfaces_HEADERS) +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMDEP_FALSE = @AMDEP_FALSE@ +AMDEP_TRUE = @AMDEP_TRUE@ +AMTAR = @AMTAR@ +AR = @AR@ +AS = @AS@ +ASM_ALIGN = @ASM_ALIGN@ +ASM_ARCH = @ASM_ARCH@ +ASM_BIGENDIAN = @ASM_BIGENDIAN@ +ASM_CPU = @ASM_CPU@ +ASM_GLOBL = @ASM_GLOBL@ +ASM_GSYM_PREFIX = @ASM_GSYM_PREFIX@ +ASM_LSYM_PREFIX = @ASM_LSYM_PREFIX@ +ASM_OS = @ASM_OS@ +ASM_TEXTSEG = @ASM_TEXTSEG@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCAS = @CCAS@ +CCASFLAGS = @CCASFLAGS@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DLLTOOL = @DLLTOOL@ +ECHO = @ECHO@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +F77 = @F77@ +FFLAGS = @FFLAGS@ +INCLUDE_DLFCN_H = @INCLUDE_DLFCN_H@ +INCLUDE_INTTYPES_H = @INCLUDE_INTTYPES_H@ +INCLUDE_MALLOC_H = @INCLUDE_MALLOC_H@ +INCLUDE_PTHREAD_H = @INCLUDE_PTHREAD_H@ +INCLUDE_STDINT_H = @INCLUDE_STDINT_H@ +INCLUDE_STDIO_H = @INCLUDE_STDIO_H@ +INCLUDE_STDLIB_H = @INCLUDE_STDLIB_H@ +INCLUDE_STRING_H = @INCLUDE_STRING_H@ +INCLUDE_SYNCH_H = @INCLUDE_SYNCH_H@ +INCLUDE_THREAD_H = @INCLUDE_THREAD_H@ +INCLUDE_UNISTD_H = @INCLUDE_UNISTD_H@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +JAVAINC = @JAVAINC@ +LDFLAGS = @LDFLAGS@ +LIBALT = @LIBALT@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +MAYBE_LTLIB = @MAYBE_LTLIB@ +MAYBE_SUB = @MAYBE_SUB@ +MP_WBITS = @MP_WBITS@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PYTHONINC = @PYTHONINC@ +PYTHONLIB = @PYTHONLIB@ +RANLIB = @RANLIB@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +TYPEDEF_BC_COND_T = @TYPEDEF_BC_COND_T@ +TYPEDEF_BC_MUTEX_T = @TYPEDEF_BC_MUTEX_T@ +TYPEDEF_BC_THREAD_T = @TYPEDEF_BC_THREAD_T@ +TYPEDEF_INT16_T = @TYPEDEF_INT16_T@ +TYPEDEF_INT32_T = @TYPEDEF_INT32_T@ +TYPEDEF_INT64_T = @TYPEDEF_INT64_T@ +TYPEDEF_INT8_T = @TYPEDEF_INT8_T@ +TYPEDEF_SIZE_T = @TYPEDEF_SIZE_T@ +TYPEDEF_UINT16_T = @TYPEDEF_UINT16_T@ +TYPEDEF_UINT32_T = @TYPEDEF_UINT32_T@ +TYPEDEF_UINT64_T = @TYPEDEF_UINT64_T@ +TYPEDEF_UINT8_T = @TYPEDEF_UINT8_T@ +VERSION = @VERSION@ +ac_ct_AR = @ac_ct_AR@ +ac_ct_AS = @ac_ct_AS@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DLLTOOL = @ac_ct_DLLTOOL@ +ac_ct_F77 = @ac_ct_F77@ +ac_ct_OBJDUMP = @ac_ct_OBJDUMP@ +ac_ct_RANLIB = @ac_ct_RANLIB@ +ac_ct_STRIP = @ac_ct_STRIP@ +ac_cv_have_gcj = @ac_cv_have_gcj@ +ac_cv_have_java = @ac_cv_have_java@ +ac_cv_have_javac = @ac_cv_have_javac@ +ac_cv_have_python = @ac_cv_have_python@ +am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ +am__fastdepCC_TRUE = @am__fastdepCC_TRUE@ +am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@ +am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +datadir = @datadir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +sysconfdir = @sysconfdir@ +target = @target@ +target_alias = @target_alias@ +target_cpu = @target_cpu@ +target_os = @target_os@ +target_vendor = @target_vendor@ +INCLUDES = -I$(top_srcdir)/.. +AUTOMAKE_OPTIONS = gnu no-dependencies +cxxsecurityinterfacesdir = $(pkgincludedir)/c++/security/interfaces +cxxsecurityinterfaces_HEADERS = \ +DSAKey.h \ +DSAParams.h \ +DSAPrivateKey.h \ +DSAPublicKey.h \ +RSAKey.h \ +RSAPrivateCrtKey.h \ +RSAPrivateKey.h \ +RSAPublicKey.h + +all: all-am + +.SUFFIXES: +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ + && exit 0; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu c++/security/interfaces/Makefile'; \ + cd $(top_srcdir) && \ + $(AUTOMAKE) --gnu c++/security/interfaces/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +distclean-libtool: + -rm -f libtool +uninstall-info-am: +install-cxxsecurityinterfacesHEADERS: $(cxxsecurityinterfaces_HEADERS) + @$(NORMAL_INSTALL) + test -z "$(cxxsecurityinterfacesdir)" || $(mkdir_p) "$(DESTDIR)$(cxxsecurityinterfacesdir)" + @list='$(cxxsecurityinterfaces_HEADERS)'; for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + f="`echo $$p | sed -e 's|^.*/||'`"; \ + echo " $(cxxsecurityinterfacesHEADERS_INSTALL) '$$d$$p' '$(DESTDIR)$(cxxsecurityinterfacesdir)/$$f'"; \ + $(cxxsecurityinterfacesHEADERS_INSTALL) "$$d$$p" "$(DESTDIR)$(cxxsecurityinterfacesdir)/$$f"; \ + done + +uninstall-cxxsecurityinterfacesHEADERS: + @$(NORMAL_UNINSTALL) + @list='$(cxxsecurityinterfaces_HEADERS)'; for p in $$list; do \ + f="`echo $$p | sed -e 's|^.*/||'`"; \ + echo " rm -f '$(DESTDIR)$(cxxsecurityinterfacesdir)/$$f'"; \ + rm -f "$(DESTDIR)$(cxxsecurityinterfacesdir)/$$f"; \ + done + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(ETAGS_ARGS)$$tags$$unique" \ + || $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$tags $$unique +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(CTAGS_ARGS)$$tags$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$tags $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && cd $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) $$here + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \ + list='$(DISTFILES)'; for file in $$list; do \ + case $$file in \ + $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \ + $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \ + esac; \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test "$$dir" != "$$file" && test "$$dir" != "."; then \ + dir="/$$dir"; \ + $(mkdir_p) "$(distdir)$$dir"; \ + else \ + dir=''; \ + fi; \ + if test -d $$d/$$file; then \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + fi; \ + cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ + else \ + test -f $(distdir)/$$file \ + || cp -p $$d/$$file $(distdir)/$$file \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(HEADERS) +installdirs: + for dir in "$(DESTDIR)$(cxxsecurityinterfacesdir)"; do \ + test -z "$$dir" || $(mkdir_p) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -rm -f $(CONFIG_CLEAN_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libtool mostlyclean-am + +distclean: distclean-am + -rm -f Makefile +distclean-am: clean-am distclean-generic distclean-libtool \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +info: info-am + +info-am: + +install-data-am: install-cxxsecurityinterfacesHEADERS + +install-exec-am: + +install-info: install-info-am + +install-man: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-generic mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-cxxsecurityinterfacesHEADERS uninstall-info-am + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-libtool ctags distclean distclean-generic \ + distclean-libtool distclean-tags distdir dvi dvi-am html \ + html-am info info-am install install-am \ + install-cxxsecurityinterfacesHEADERS install-data \ + install-data-am install-exec install-exec-am install-info \ + install-info-am install-man install-strip installcheck \ + installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-generic \ + mostlyclean-libtool pdf pdf-am ps ps-am tags uninstall \ + uninstall-am uninstall-cxxsecurityinterfacesHEADERS \ + uninstall-info-am + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/beecrypt/c++/security/interfaces/RSAKey.h b/beecrypt/c++/security/interfaces/RSAKey.h new file mode 100644 index 0000000..b622ae7 --- /dev/null +++ b/beecrypt/c++/security/interfaces/RSAKey.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file RSAKey.h + * \ingroup CXX_SECURITY_INTERFACES_m + */ + +#ifndef _INTERFACE_RSAKEY_H +#define _INTERFACE_RSAKEY_H + +#include "beecrypt/api.h" +#include "beecrypt/mpbarrett.h" + +#ifdef __cplusplus + +namespace beecrypt { + namespace security { + namespace interfaces { + /*!\brief RSA key interface. + * \ingroup CXX_IF_m + */ + class RSAKey + { + public: + virtual const mpbarrett& getModulus() const throw () = 0; + }; + } + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/interfaces/RSAPrivateCrtKey.h b/beecrypt/c++/security/interfaces/RSAPrivateCrtKey.h new file mode 100644 index 0000000..aa243b9 --- /dev/null +++ b/beecrypt/c++/security/interfaces/RSAPrivateCrtKey.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file RSAPrivateCrtKey.h + * \ingroup CXX_SECURITY_INTERFACES_m + */ + +#ifndef _INTERFACE_RSAPRIVATECRTKEY_H +#define _INTERFACE_RSAPRIVATECRTKEY_H + +#ifdef __cplusplus + +#include "beecrypt/c++/security/interfaces/RSAPrivateKey.h" +using beecrypt::security::interfaces::RSAPrivateKey; + +namespace beecrypt { + namespace security { + namespace interfaces { + /*!\brief The interface to an RSA private key, as defined in the PKCS#1 standard, using the Chinese Remainder Theorem (CRT) information values. + * \ingroup CXX_IF_m + */ + class RSAPrivateCrtKey : public RSAPrivateKey + { + public: + virtual const mpnumber& getPublicExponent() const throw () = 0; + virtual const mpbarrett& getPrimeP() const throw () = 0; + virtual const mpbarrett& getPrimeQ() const throw () = 0; + virtual const mpnumber& getPrimeExponentP() const throw () = 0; + virtual const mpnumber& getPrimeExponentQ() const throw () = 0; + virtual const mpnumber& getCrtCoefficient() const throw () = 0; + }; + } + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/interfaces/RSAPrivateKey.h b/beecrypt/c++/security/interfaces/RSAPrivateKey.h new file mode 100644 index 0000000..5fc8c47 --- /dev/null +++ b/beecrypt/c++/security/interfaces/RSAPrivateKey.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file RSAPrivateKey.h + * \ingroup CXX_SECURITY_INTERFACES_m + */ + +#ifndef _INTERFACE_RSAPRIVATEKEY_H +#define _INTERFACE_RSAPRIVATEKEY_H + +#ifdef __cplusplus + +#include "beecrypt/c++/security/PrivateKey.h" +using beecrypt::security::PrivateKey; +#include "beecrypt/c++/security/interfaces/RSAKey.h" +using beecrypt::security::interfaces::RSAKey; + +namespace beecrypt { + namespace security { + namespace interfaces { + /*!\ingroup CXX_IF_m + */ + class RSAPrivateKey : public PrivateKey, public RSAKey + { + public: + virtual const mpnumber& getPrivateExponent() const throw () = 0; + }; + } + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/interfaces/RSAPublicKey.h b/beecrypt/c++/security/interfaces/RSAPublicKey.h new file mode 100644 index 0000000..93f9da1 --- /dev/null +++ b/beecrypt/c++/security/interfaces/RSAPublicKey.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file RSAPublicKey.h + * \ingroup CXX_SECURITY_INTERFACES_m + */ + +#ifndef _INTERFACE_RSAPUBLICKEY_H +#define _INTERFACE_RSAPUBLICKEY_H + +#ifdef __cplusplus + +#include "beecrypt/c++/security/PublicKey.h" +using beecrypt::security::PublicKey; +#include "beecrypt/c++/security/interfaces/RSAKey.h" +using beecrypt::security::interfaces::RSAKey; + +namespace beecrypt { + namespace security { + namespace interfaces { + /*!\ingroup CXX_IF_m + */ + class RSAPublicKey : public PublicKey, public RSAKey + { + public: + virtual const mpnumber& getPublicExponent() const throw () = 0; + }; + } + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/spec/AlgorithmParameterSpec.h b/beecrypt/c++/security/spec/AlgorithmParameterSpec.h new file mode 100644 index 0000000..0010d0d --- /dev/null +++ b/beecrypt/c++/security/spec/AlgorithmParameterSpec.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file AlgorithmParameterSpec.h + * \ingroup CXX_SECURITY_SPEC_m + */ + +#ifndef _CLASS_ALGORITHMPARAMETERSPEC_H +#define _CLASS_ALGORITHMPARAMETERSPEC_H + +#include "beecrypt/api.h" + +#ifdef __cplusplus + +namespace beecrypt { + namespace security { + namespace spec { + /*!\brief The base class for specification of cryptographic parameters. + */ + class BEECRYPTCXXAPI AlgorithmParameterSpec + { + public: + virtual ~AlgorithmParameterSpec() {}; + }; + } + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/spec/DSAParameterSpec.cxx b/beecrypt/c++/security/spec/DSAParameterSpec.cxx new file mode 100644 index 0000000..cc9e855 --- /dev/null +++ b/beecrypt/c++/security/spec/DSAParameterSpec.cxx @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/security/spec/DSAParameterSpec.h" + +using namespace beecrypt::security::spec; + +DSAParameterSpec::DSAParameterSpec(const DSAParams& copy) +{ + _p = copy.getP(); + _q = copy.getQ(); + _g = copy.getG(); +} + +DSAParameterSpec::DSAParameterSpec(const mpbarrett& p, const mpbarrett& q, const mpnumber& g) +{ + _p = p; + _q = q; + _g = g; +} + +DSAParameterSpec::~DSAParameterSpec() +{ +} + +const mpbarrett& DSAParameterSpec::getP() const throw () +{ + return _p; +} + +const mpbarrett& DSAParameterSpec::getQ() const throw () +{ + return _q; +} + +const mpnumber& DSAParameterSpec::getG() const throw () +{ + return _g; +} diff --git a/beecrypt/c++/security/spec/DSAParameterSpec.h b/beecrypt/c++/security/spec/DSAParameterSpec.h new file mode 100644 index 0000000..cb71123 --- /dev/null +++ b/beecrypt/c++/security/spec/DSAParameterSpec.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file DSAParameterSpec.h + * \ingroup CXX_SECURITY_SPEC_m + */ + +#ifndef _CLASS_DSAPARAMETERSPEC_H +#define _CLASS_DSAPARAMETERSPEC_H + +#include "beecrypt/api.h" +#include "beecrypt/mpbarrett.h" +#include "beecrypt/dsa.h" + +#ifdef __cplusplus + +#include "beecrypt/c++/security/interfaces/DSAParams.h" +using beecrypt::security::interfaces::DSAParams; +#include "beecrypt/c++/security/spec/AlgorithmParameterSpec.h" +using beecrypt::security::spec::AlgorithmParameterSpec; + +namespace beecrypt { + namespace security { + namespace spec { + class BEECRYPTCXXAPI DSAParameterSpec : public AlgorithmParameterSpec, public DSAParams + { + private: + mpbarrett _p; + mpbarrett _q; + mpnumber _g; + + public: + DSAParameterSpec(const DSAParams&); + DSAParameterSpec(const mpbarrett& p, const mpbarrett& q, const mpnumber& g); + virtual ~DSAParameterSpec(); + + const mpbarrett& getP() const throw (); + const mpbarrett& getQ() const throw (); + const mpnumber& getG() const throw (); + }; + } + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/spec/DSAPrivateKeySpec.cxx b/beecrypt/c++/security/spec/DSAPrivateKeySpec.cxx new file mode 100644 index 0000000..dece65b --- /dev/null +++ b/beecrypt/c++/security/spec/DSAPrivateKeySpec.cxx @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/security/spec/DSAPrivateKeySpec.h" + +using namespace beecrypt::security::spec; + +DSAPrivateKeySpec::DSAPrivateKeySpec(const mpbarrett& p, const mpbarrett& q, const mpnumber& g, const mpnumber& x) +{ + _p = p; + _q = q; + _g = g; + _x = x; +} + +DSAPrivateKeySpec::~DSAPrivateKeySpec() +{ + _x.wipe(); +} + +const mpbarrett& DSAPrivateKeySpec::getP() const throw () +{ + return _p; +} + +const mpbarrett& DSAPrivateKeySpec::getQ() const throw () +{ + return _q; +} + +const mpnumber& DSAPrivateKeySpec::getG() const throw () +{ + return _g; +} + +const mpnumber& DSAPrivateKeySpec::getX() const throw () +{ + return _x; +} diff --git a/beecrypt/c++/security/spec/DSAPrivateKeySpec.h b/beecrypt/c++/security/spec/DSAPrivateKeySpec.h new file mode 100644 index 0000000..057981a --- /dev/null +++ b/beecrypt/c++/security/spec/DSAPrivateKeySpec.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file DSAPrivateKeySpec.h + * \ingroup CXX_SECURITY_SPEC_m + */ + +#ifndef _CLASS_DSAPRIVATEKEYSPEC_H +#define _CLASS_DSAPRIVATEKEYSPEC_H + +#include "beecrypt/api.h" +#include "beecrypt/mpbarrett.h" + +#ifdef __cplusplus + +#include "beecrypt/c++/security/spec/KeySpec.h" +using beecrypt::security::spec::KeySpec; + +namespace beecrypt { + namespace security { + namespace spec { + class BEECRYPTCXXAPI DSAPrivateKeySpec : public KeySpec + { + private: + mpbarrett _p; + mpbarrett _q; + mpnumber _g; + mpnumber _x; + + public: + DSAPrivateKeySpec(const mpbarrett& p, const mpbarrett& q, const mpnumber& g, const mpnumber& x); + virtual ~DSAPrivateKeySpec(); + + const mpbarrett& getP() const throw (); + const mpbarrett& getQ() const throw (); + const mpnumber& getG() const throw (); + const mpnumber& getX() const throw (); + }; + } + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/spec/DSAPublicKeySpec.cxx b/beecrypt/c++/security/spec/DSAPublicKeySpec.cxx new file mode 100644 index 0000000..7be7a58 --- /dev/null +++ b/beecrypt/c++/security/spec/DSAPublicKeySpec.cxx @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/security/spec/DSAPublicKeySpec.h" + +using namespace beecrypt::security::spec; + +DSAPublicKeySpec::DSAPublicKeySpec(const mpbarrett& p, const mpbarrett& q, const mpnumber& g, const mpnumber& y) +{ + _p = p; + _q = q; + _g = g; + _y = y; +} + +DSAPublicKeySpec::~DSAPublicKeySpec() +{ +} + +const mpbarrett& DSAPublicKeySpec::getP() const throw () +{ + return _p; +} + +const mpbarrett& DSAPublicKeySpec::getQ() const throw () +{ + return _q; +} + +const mpnumber& DSAPublicKeySpec::getG() const throw () +{ + return _g; +} + +const mpnumber& DSAPublicKeySpec::getY() const throw () +{ + return _y; +} diff --git a/beecrypt/c++/security/spec/DSAPublicKeySpec.h b/beecrypt/c++/security/spec/DSAPublicKeySpec.h new file mode 100644 index 0000000..3220f31 --- /dev/null +++ b/beecrypt/c++/security/spec/DSAPublicKeySpec.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file DSAPublicKeySpec.h + * \ingroup CXX_SECURITY_SPEC_m + */ + +#ifndef _CLASS_DSAPUBLICKEYSPEC_H +#define _CLASS_DSAPUBLICKEYSPEC_H + +#include "beecrypt/api.h" +#include "beecrypt/mpbarrett.h" + +#ifdef __cplusplus + +#include "beecrypt/c++/security/spec/KeySpec.h" +using beecrypt::security::spec::KeySpec; + +namespace beecrypt { + namespace security { + namespace spec { + class BEECRYPTCXXAPI DSAPublicKeySpec : public KeySpec + { + private: + mpbarrett _p; + mpbarrett _q; + mpnumber _g; + mpnumber _y; + + public: + DSAPublicKeySpec(const mpbarrett& p, const mpbarrett& q, const mpnumber& g, const mpnumber& y); + virtual ~DSAPublicKeySpec(); + + const mpbarrett& getP() const throw (); + const mpbarrett& getQ() const throw (); + const mpnumber& getG() const throw (); + const mpnumber& getY() const throw (); + }; + } + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/spec/EncodedKeySpec.cxx b/beecrypt/c++/security/spec/EncodedKeySpec.cxx new file mode 100644 index 0000000..c6b05c3 --- /dev/null +++ b/beecrypt/c++/security/spec/EncodedKeySpec.cxx @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/security/spec/EncodedKeySpec.h" + +using namespace beecrypt::security::spec; + +EncodedKeySpec::EncodedKeySpec(const byte* data, size_t size) : _encoded(data, size) +{ +} + +EncodedKeySpec::EncodedKeySpec(const bytearray& copy) : _encoded(copy) +{ +} + +EncodedKeySpec::~EncodedKeySpec() +{ +} + +const bytearray& EncodedKeySpec::getEncoded() const throw () +{ + return _encoded; +} diff --git a/beecrypt/c++/security/spec/EncodedKeySpec.h b/beecrypt/c++/security/spec/EncodedKeySpec.h new file mode 100644 index 0000000..5af27f0 --- /dev/null +++ b/beecrypt/c++/security/spec/EncodedKeySpec.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file EncodedKeySpec.h + * \ingroup CXX_SECURITY_SPEC_m + */ + +#ifndef _CLASS_ENCODEDKEYSPEC_H +#define _CLASS_ENCODEDKEYSPEC_H + +#ifdef __cplusplus + +#include "beecrypt/c++/array.h" +using beecrypt::bytearray; +#include "beecrypt/c++/lang/String.h" +using beecrypt::lang::String; +#include "beecrypt/c++/security/spec/KeySpec.h" +using beecrypt::security::spec::KeySpec; + +namespace beecrypt { + namespace security { + namespace spec { + class BEECRYPTCXXAPI EncodedKeySpec : public KeySpec + { + private: + bytearray _encoded; + + public: + EncodedKeySpec(const byte*, size_t); + EncodedKeySpec(const bytearray&); + virtual ~EncodedKeySpec(); + + const bytearray& getEncoded() const throw (); + virtual const String& getFormat() const throw () = 0; + + }; + } + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/spec/InvalidKeySpecException.cxx b/beecrypt/c++/security/spec/InvalidKeySpecException.cxx new file mode 100644 index 0000000..d9ffc6d --- /dev/null +++ b/beecrypt/c++/security/spec/InvalidKeySpecException.cxx @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/security/spec/InvalidKeySpecException.h" + +using namespace beecrypt::security::spec; + +InvalidKeySpecException::InvalidKeySpecException() throw () +{ +} + +InvalidKeySpecException::InvalidKeySpecException(const String& message) throw () : GeneralSecurityException(message) +{ +} diff --git a/beecrypt/c++/security/spec/InvalidKeySpecException.h b/beecrypt/c++/security/spec/InvalidKeySpecException.h new file mode 100644 index 0000000..4ecf202 --- /dev/null +++ b/beecrypt/c++/security/spec/InvalidKeySpecException.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file InvalidKeySpecException.h + * \ingroup CXX_SECURITY_SPEC_m + */ + +#ifndef _CLASS_INVALIDKEYSPECEXCEPTION_H +#define _CLASS_INVALIDKEYSPECEXCEPTION_H + +#ifdef __cplusplus + +#include "beecrypt/c++/security/GeneralSecurityException.h" +using beecrypt::security::GeneralSecurityException; + +namespace beecrypt { + namespace security { + namespace spec { + class BEECRYPTCXXAPI InvalidKeySpecException : public GeneralSecurityException + { + public: + InvalidKeySpecException() throw (); + InvalidKeySpecException(const String&) throw (); + }; + } + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/spec/InvalidParameterSpecException.cxx b/beecrypt/c++/security/spec/InvalidParameterSpecException.cxx new file mode 100644 index 0000000..a987648 --- /dev/null +++ b/beecrypt/c++/security/spec/InvalidParameterSpecException.cxx @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/security/spec/InvalidParameterSpecException.h" + +using namespace beecrypt::security::spec; + +InvalidParameterSpecException::InvalidParameterSpecException() throw () +{ +} + +InvalidParameterSpecException::InvalidParameterSpecException(const String& message) throw () : GeneralSecurityException(message) +{ +} diff --git a/beecrypt/c++/security/spec/InvalidParameterSpecException.h b/beecrypt/c++/security/spec/InvalidParameterSpecException.h new file mode 100644 index 0000000..a7e69dc --- /dev/null +++ b/beecrypt/c++/security/spec/InvalidParameterSpecException.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file InvalidParameterSpecException.h + * \ingroup CXX_SECURITY_SPEC_m + */ + +#ifndef _CLASS_INVALIDPARAMETERSPECEXCEPTION_H +#define _CLASS_INVALIDPARAMETERSPECEXCEPTION_H + +#ifdef __cplusplus + +#include "beecrypt/c++/security/GeneralSecurityException.h" +using beecrypt::security::GeneralSecurityException; + +namespace beecrypt { + namespace security { + namespace spec { + class BEECRYPTCXXAPI InvalidParameterSpecException : public GeneralSecurityException + { + public: + InvalidParameterSpecException() throw (); + InvalidParameterSpecException(const String&) throw (); + }; + } + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/spec/KeySpec.h b/beecrypt/c++/security/spec/KeySpec.h new file mode 100644 index 0000000..eb102a1 --- /dev/null +++ b/beecrypt/c++/security/spec/KeySpec.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file KeySpec.h + * \ingroup CXX_SECURITY_SPEC_m + */ + +#ifndef _CLASS_KEYSPEC_H +#define _CLASS_KEYSPEC_H + +#include "beecrypt/api.h" + +#ifdef __cplusplus + +namespace beecrypt { + namespace security { + namespace spec { + /*!\brief The base class for specification of cryptographic keys. + */ + class BEECRYPTCXXAPI KeySpec + { + public: + virtual ~KeySpec() {} + }; + } + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/spec/Makefile.am b/beecrypt/c++/security/spec/Makefile.am new file mode 100644 index 0000000..8d6cba6 --- /dev/null +++ b/beecrypt/c++/security/spec/Makefile.am @@ -0,0 +1,33 @@ +INCLUDES = -I$(top_srcdir)/.. + +AUTOMAKE_OPTIONS = gnu no-dependencies + +noinst_LTLIBRARIES = libcxxsecurityspec.la + +cxxsecurityspecdir=$(pkgincludedir)/c++/security/spec + +libcxxsecurityspec_la_SOURCES =\ +DSAParameterSpec.cxx \ +DSAPrivateKeySpec.cxx \ +DSAPublicKeySpec.cxx \ +EncodedKeySpec.cxx \ +InvalidKeySpecException.cxx \ +InvalidParameterSpecException.cxx \ +RSAKeyGenParameterSpec.cxx \ +RSAPrivateCrtKeySpec.cxx \ +RSAPrivateKeySpec.cxx \ +RSAPublicKeySpec.cxx + +cxxsecurityspec_HEADERS =\ +AlgorithmParameterSpec.h \ +DSAParameterSpec.h \ +DSAPrivateKeySpec.h \ +DSAPublicKeySpec.h \ +EncodedKeySpec.h \ +InvalidKeySpecException.h \ +InvalidParameterSpecException.h \ +KeySpec.h \ +RSAKeyGenParameterSpec.h \ +RSAPrivateCrtKeySpec.h \ +RSAPrivateKeySpec.h \ +RSAPublicKeySpec.h diff --git a/beecrypt/c++/security/spec/Makefile.in b/beecrypt/c++/security/spec/Makefile.in new file mode 100644 index 0000000..7981edc --- /dev/null +++ b/beecrypt/c++/security/spec/Makefile.in @@ -0,0 +1,513 @@ +# Makefile.in generated by automake 1.8.3 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + + +SOURCES = $(libcxxsecurityspec_la_SOURCES) + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +top_builddir = ../../.. +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +INSTALL = @INSTALL@ +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +host_triplet = @host@ +subdir = c++/security/spec +DIST_COMMON = $(cxxsecurityspec_HEADERS) $(srcdir)/Makefile.am \ + $(srcdir)/Makefile.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \ + $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +LTLIBRARIES = $(noinst_LTLIBRARIES) +libcxxsecurityspec_la_LIBADD = +am_libcxxsecurityspec_la_OBJECTS = DSAParameterSpec.lo \ + DSAPrivateKeySpec.lo DSAPublicKeySpec.lo EncodedKeySpec.lo \ + InvalidKeySpecException.lo InvalidParameterSpecException.lo \ + RSAKeyGenParameterSpec.lo RSAPrivateCrtKeySpec.lo \ + RSAPrivateKeySpec.lo RSAPublicKeySpec.lo +libcxxsecurityspec_la_OBJECTS = $(am_libcxxsecurityspec_la_OBJECTS) +DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir) +depcomp = +am__depfiles_maybe = +CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) +LTCXXCOMPILE = $(LIBTOOL) --mode=compile $(CXX) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CXXFLAGS) $(CXXFLAGS) +CXXLD = $(CXX) +CXXLINK = $(LIBTOOL) --mode=link $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) \ + $(AM_LDFLAGS) $(LDFLAGS) -o $@ +SOURCES = $(libcxxsecurityspec_la_SOURCES) +DIST_SOURCES = $(libcxxsecurityspec_la_SOURCES) +am__installdirs = "$(DESTDIR)$(cxxsecurityspecdir)" +cxxsecurityspecHEADERS_INSTALL = $(INSTALL_HEADER) +HEADERS = $(cxxsecurityspec_HEADERS) +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMDEP_FALSE = @AMDEP_FALSE@ +AMDEP_TRUE = @AMDEP_TRUE@ +AMTAR = @AMTAR@ +AR = @AR@ +AS = @AS@ +ASM_ALIGN = @ASM_ALIGN@ +ASM_ARCH = @ASM_ARCH@ +ASM_BIGENDIAN = @ASM_BIGENDIAN@ +ASM_CPU = @ASM_CPU@ +ASM_GLOBL = @ASM_GLOBL@ +ASM_GSYM_PREFIX = @ASM_GSYM_PREFIX@ +ASM_LSYM_PREFIX = @ASM_LSYM_PREFIX@ +ASM_OS = @ASM_OS@ +ASM_TEXTSEG = @ASM_TEXTSEG@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCAS = @CCAS@ +CCASFLAGS = @CCASFLAGS@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DLLTOOL = @DLLTOOL@ +ECHO = @ECHO@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +F77 = @F77@ +FFLAGS = @FFLAGS@ +INCLUDE_DLFCN_H = @INCLUDE_DLFCN_H@ +INCLUDE_INTTYPES_H = @INCLUDE_INTTYPES_H@ +INCLUDE_MALLOC_H = @INCLUDE_MALLOC_H@ +INCLUDE_PTHREAD_H = @INCLUDE_PTHREAD_H@ +INCLUDE_STDINT_H = @INCLUDE_STDINT_H@ +INCLUDE_STDIO_H = @INCLUDE_STDIO_H@ +INCLUDE_STDLIB_H = @INCLUDE_STDLIB_H@ +INCLUDE_STRING_H = @INCLUDE_STRING_H@ +INCLUDE_SYNCH_H = @INCLUDE_SYNCH_H@ +INCLUDE_THREAD_H = @INCLUDE_THREAD_H@ +INCLUDE_UNISTD_H = @INCLUDE_UNISTD_H@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +JAVAINC = @JAVAINC@ +LDFLAGS = @LDFLAGS@ +LIBALT = @LIBALT@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +MAYBE_LTLIB = @MAYBE_LTLIB@ +MAYBE_SUB = @MAYBE_SUB@ +MP_WBITS = @MP_WBITS@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PYTHONINC = @PYTHONINC@ +PYTHONLIB = @PYTHONLIB@ +RANLIB = @RANLIB@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +TYPEDEF_BC_COND_T = @TYPEDEF_BC_COND_T@ +TYPEDEF_BC_MUTEX_T = @TYPEDEF_BC_MUTEX_T@ +TYPEDEF_BC_THREAD_T = @TYPEDEF_BC_THREAD_T@ +TYPEDEF_INT16_T = @TYPEDEF_INT16_T@ +TYPEDEF_INT32_T = @TYPEDEF_INT32_T@ +TYPEDEF_INT64_T = @TYPEDEF_INT64_T@ +TYPEDEF_INT8_T = @TYPEDEF_INT8_T@ +TYPEDEF_SIZE_T = @TYPEDEF_SIZE_T@ +TYPEDEF_UINT16_T = @TYPEDEF_UINT16_T@ +TYPEDEF_UINT32_T = @TYPEDEF_UINT32_T@ +TYPEDEF_UINT64_T = @TYPEDEF_UINT64_T@ +TYPEDEF_UINT8_T = @TYPEDEF_UINT8_T@ +VERSION = @VERSION@ +ac_ct_AR = @ac_ct_AR@ +ac_ct_AS = @ac_ct_AS@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DLLTOOL = @ac_ct_DLLTOOL@ +ac_ct_F77 = @ac_ct_F77@ +ac_ct_OBJDUMP = @ac_ct_OBJDUMP@ +ac_ct_RANLIB = @ac_ct_RANLIB@ +ac_ct_STRIP = @ac_ct_STRIP@ +ac_cv_have_gcj = @ac_cv_have_gcj@ +ac_cv_have_java = @ac_cv_have_java@ +ac_cv_have_javac = @ac_cv_have_javac@ +ac_cv_have_python = @ac_cv_have_python@ +am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ +am__fastdepCC_TRUE = @am__fastdepCC_TRUE@ +am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@ +am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +datadir = @datadir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +sysconfdir = @sysconfdir@ +target = @target@ +target_alias = @target_alias@ +target_cpu = @target_cpu@ +target_os = @target_os@ +target_vendor = @target_vendor@ +INCLUDES = -I$(top_srcdir)/.. +AUTOMAKE_OPTIONS = gnu no-dependencies +noinst_LTLIBRARIES = libcxxsecurityspec.la +cxxsecurityspecdir = $(pkgincludedir)/c++/security/spec +libcxxsecurityspec_la_SOURCES = \ +DSAParameterSpec.cxx \ +DSAPrivateKeySpec.cxx \ +DSAPublicKeySpec.cxx \ +EncodedKeySpec.cxx \ +InvalidKeySpecException.cxx \ +InvalidParameterSpecException.cxx \ +RSAKeyGenParameterSpec.cxx \ +RSAPrivateCrtKeySpec.cxx \ +RSAPrivateKeySpec.cxx \ +RSAPublicKeySpec.cxx + +cxxsecurityspec_HEADERS = \ +AlgorithmParameterSpec.h \ +DSAParameterSpec.h \ +DSAPrivateKeySpec.h \ +DSAPublicKeySpec.h \ +EncodedKeySpec.h \ +InvalidKeySpecException.h \ +InvalidParameterSpecException.h \ +KeySpec.h \ +RSAKeyGenParameterSpec.h \ +RSAPrivateCrtKeySpec.h \ +RSAPrivateKeySpec.h \ +RSAPublicKeySpec.h + +all: all-am + +.SUFFIXES: +.SUFFIXES: .cxx .lo .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ + && exit 0; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu c++/security/spec/Makefile'; \ + cd $(top_srcdir) && \ + $(AUTOMAKE) --gnu c++/security/spec/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +clean-noinstLTLIBRARIES: + -test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES) + @list='$(noinst_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" = "$$p" && dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +libcxxsecurityspec.la: $(libcxxsecurityspec_la_OBJECTS) $(libcxxsecurityspec_la_DEPENDENCIES) + $(CXXLINK) $(libcxxsecurityspec_la_LDFLAGS) $(libcxxsecurityspec_la_OBJECTS) $(libcxxsecurityspec_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +.cxx.o: + $(CXXCOMPILE) -c -o $@ $< + +.cxx.obj: + $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +.cxx.lo: + $(LTCXXCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +distclean-libtool: + -rm -f libtool +uninstall-info-am: +install-cxxsecurityspecHEADERS: $(cxxsecurityspec_HEADERS) + @$(NORMAL_INSTALL) + test -z "$(cxxsecurityspecdir)" || $(mkdir_p) "$(DESTDIR)$(cxxsecurityspecdir)" + @list='$(cxxsecurityspec_HEADERS)'; for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + f="`echo $$p | sed -e 's|^.*/||'`"; \ + echo " $(cxxsecurityspecHEADERS_INSTALL) '$$d$$p' '$(DESTDIR)$(cxxsecurityspecdir)/$$f'"; \ + $(cxxsecurityspecHEADERS_INSTALL) "$$d$$p" "$(DESTDIR)$(cxxsecurityspecdir)/$$f"; \ + done + +uninstall-cxxsecurityspecHEADERS: + @$(NORMAL_UNINSTALL) + @list='$(cxxsecurityspec_HEADERS)'; for p in $$list; do \ + f="`echo $$p | sed -e 's|^.*/||'`"; \ + echo " rm -f '$(DESTDIR)$(cxxsecurityspecdir)/$$f'"; \ + rm -f "$(DESTDIR)$(cxxsecurityspecdir)/$$f"; \ + done + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(ETAGS_ARGS)$$tags$$unique" \ + || $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$tags $$unique +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(CTAGS_ARGS)$$tags$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$tags $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && cd $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) $$here + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \ + list='$(DISTFILES)'; for file in $$list; do \ + case $$file in \ + $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \ + $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \ + esac; \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test "$$dir" != "$$file" && test "$$dir" != "."; then \ + dir="/$$dir"; \ + $(mkdir_p) "$(distdir)$$dir"; \ + else \ + dir=''; \ + fi; \ + if test -d $$d/$$file; then \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + fi; \ + cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ + else \ + test -f $(distdir)/$$file \ + || cp -p $$d/$$file $(distdir)/$$file \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(LTLIBRARIES) $(HEADERS) +installdirs: + for dir in "$(DESTDIR)$(cxxsecurityspecdir)"; do \ + test -z "$$dir" || $(mkdir_p) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -rm -f $(CONFIG_CLEAN_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libtool clean-noinstLTLIBRARIES \ + mostlyclean-am + +distclean: distclean-am + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-libtool distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +info: info-am + +info-am: + +install-data-am: install-cxxsecurityspecHEADERS + +install-exec-am: + +install-info: install-info-am + +install-man: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-cxxsecurityspecHEADERS uninstall-info-am + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-libtool clean-noinstLTLIBRARIES ctags distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-tags distdir dvi dvi-am html html-am info info-am \ + install install-am install-cxxsecurityspecHEADERS install-data \ + install-data-am install-exec install-exec-am install-info \ + install-info-am install-man install-strip installcheck \ + installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags uninstall uninstall-am uninstall-cxxsecurityspecHEADERS \ + uninstall-info-am + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/beecrypt/c++/security/spec/RSAKeyGenParameterSpec.cxx b/beecrypt/c++/security/spec/RSAKeyGenParameterSpec.cxx new file mode 100644 index 0000000..17cec6b --- /dev/null +++ b/beecrypt/c++/security/spec/RSAKeyGenParameterSpec.cxx @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/security/spec/RSAKeyGenParameterSpec.h" + +using namespace beecrypt::security::spec; + +const mpnumber RSAKeyGenParameterSpec::F0(3); +const mpnumber RSAKeyGenParameterSpec::F4(65537); + +RSAKeyGenParameterSpec::RSAKeyGenParameterSpec(size_t keysize, const mpnumber& publicExponent) +{ + _keysize = keysize; + _e = publicExponent; +} + +RSAKeyGenParameterSpec::~RSAKeyGenParameterSpec() +{ +} + +size_t RSAKeyGenParameterSpec::getKeysize() const throw () +{ + return _keysize; +} + +const mpnumber& RSAKeyGenParameterSpec::getPublicExponent() const throw () +{ + return _e; +} diff --git a/beecrypt/c++/security/spec/RSAKeyGenParameterSpec.h b/beecrypt/c++/security/spec/RSAKeyGenParameterSpec.h new file mode 100644 index 0000000..dd4f9a0 --- /dev/null +++ b/beecrypt/c++/security/spec/RSAKeyGenParameterSpec.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file RSAKeyGenParameterSpec.h + * \ingroup CXX_SECURITY_SPEC_m + */ + +#ifndef _CLASS_RSAKEYGENPARAMETERSPEC +#define _CLASS_RSAKEYGENPARAMETERSPEC + +#include "beecrypt/beecrypt.h" + +#ifdef __cplusplus + +#include "beecrypt/c++/security/spec/AlgorithmParameterSpec.h" +using beecrypt::security::spec::AlgorithmParameterSpec; + +namespace beecrypt { + namespace security { + namespace spec { + class BEECRYPTCXXAPI RSAKeyGenParameterSpec : public AlgorithmParameterSpec + { + public: + static const mpnumber F0; + static const mpnumber F4; + + private: + size_t _keysize; + mpnumber _e; + + public: + RSAKeyGenParameterSpec(size_t, const mpnumber&); + virtual ~RSAKeyGenParameterSpec(); + + size_t getKeysize() const throw (); + const mpnumber& getPublicExponent() const throw (); + }; + } + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/spec/RSAPrivateCrtKeySpec.cxx b/beecrypt/c++/security/spec/RSAPrivateCrtKeySpec.cxx new file mode 100644 index 0000000..7caeb56 --- /dev/null +++ b/beecrypt/c++/security/spec/RSAPrivateCrtKeySpec.cxx @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/security/spec/RSAPrivateCrtKeySpec.h" + +using namespace beecrypt::security::spec; + +RSAPrivateCrtKeySpec::RSAPrivateCrtKeySpec(const mpbarrett& modulus, const mpnumber& publicExponent, const mpnumber& privateExponent, const mpbarrett& primeP, const mpbarrett& primeQ, const mpnumber& primeExponentP, const mpnumber& primeExponentQ, const mpnumber& crtCoefficient) : RSAPrivateKeySpec(modulus, privateExponent) +{ + _e = publicExponent; + _p = primeP; + _q = primeQ; + _dp = primeExponentP; + _dq = primeExponentQ; + _qi = crtCoefficient; +} + +RSAPrivateCrtKeySpec::~RSAPrivateCrtKeySpec() +{ +} + +const mpnumber& RSAPrivateCrtKeySpec::getPublicExponent() const throw () +{ + return _e; +} + +const mpbarrett& RSAPrivateCrtKeySpec::getPrimeP() const throw () +{ + return _p; +} + +const mpbarrett& RSAPrivateCrtKeySpec::getPrimeQ() const throw () +{ + return _q; +} + +const mpnumber& RSAPrivateCrtKeySpec::getPrimeExponentP() const throw () +{ + return _dp; +} + +const mpnumber& RSAPrivateCrtKeySpec::getPrimeExponentQ() const throw () +{ + return _dq; +} + +const mpnumber& RSAPrivateCrtKeySpec::getCrtCoefficient() const throw () +{ + return _qi; +} diff --git a/beecrypt/c++/security/spec/RSAPrivateCrtKeySpec.h b/beecrypt/c++/security/spec/RSAPrivateCrtKeySpec.h new file mode 100644 index 0000000..9642a96 --- /dev/null +++ b/beecrypt/c++/security/spec/RSAPrivateCrtKeySpec.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file RSAPrivateCrtKeySpec.h + * \ingroup CXX_SECURITY_SPEC_m + */ + +#ifndef _CLASS_RSAPRIVATECRTKEYSPEC_H +#define _CLASS_RSAPRIVATECRTKEYSPEC_H + +#ifdef __cplusplus + +#include "beecrypt/c++/security/spec/RSAPrivateKeySpec.h" +using beecrypt::security::spec::RSAPrivateKeySpec; + +namespace beecrypt { + namespace security { + namespace spec { + class BEECRYPTCXXAPI RSAPrivateCrtKeySpec : public RSAPrivateKeySpec + { + private: + mpnumber _e; + mpbarrett _p; + mpbarrett _q; + mpnumber _dp; + mpnumber _dq; + mpnumber _qi; + + public: + RSAPrivateCrtKeySpec(const mpbarrett& modulus, const mpnumber& publicExponent, const mpnumber& privateExponent, const mpbarrett& primeP, const mpbarrett& primeQ, const mpnumber& primeExponentP, const mpnumber& primeExponentQ, const mpnumber& crtCoefficient); + virtual ~RSAPrivateCrtKeySpec(); + + const mpnumber& getPublicExponent() const throw (); + const mpbarrett& getPrimeP() const throw (); + const mpbarrett& getPrimeQ() const throw (); + const mpnumber& getPrimeExponentP() const throw (); + const mpnumber& getPrimeExponentQ() const throw (); + const mpnumber& getCrtCoefficient() const throw (); + }; + } + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/spec/RSAPrivateKeySpec.cxx b/beecrypt/c++/security/spec/RSAPrivateKeySpec.cxx new file mode 100644 index 0000000..8b1d4b4 --- /dev/null +++ b/beecrypt/c++/security/spec/RSAPrivateKeySpec.cxx @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/security/spec/RSAPrivateKeySpec.h" + +using namespace beecrypt::security::spec; + +RSAPrivateKeySpec::RSAPrivateKeySpec(const mpbarrett& modulus, const mpnumber& privateExponent) +{ + _n = modulus; + _d = privateExponent; +} + +RSAPrivateKeySpec::~RSAPrivateKeySpec() +{ +} + +const mpbarrett& RSAPrivateKeySpec::getModulus() const throw () +{ + return _n; +} + +const mpnumber& RSAPrivateKeySpec::getPrivateExponent() const throw () +{ + return _d; +} diff --git a/beecrypt/c++/security/spec/RSAPrivateKeySpec.h b/beecrypt/c++/security/spec/RSAPrivateKeySpec.h new file mode 100644 index 0000000..4562560 --- /dev/null +++ b/beecrypt/c++/security/spec/RSAPrivateKeySpec.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file RSAPrivateKeySpec.h + * \ingroup CXX_SECURITY_SPEC_m + */ + +#ifndef _CLASS_RSAPRIVATEKEYSPEC_H +#define _CLASS_RSAPRIVATEKEYSPEC_H + +#include "beecrypt/api.h" +#include "beecrypt/mpbarrett.h" + +#ifdef __cplusplus + +#include "beecrypt/c++/security/spec/KeySpec.h" +using beecrypt::security::spec::KeySpec; + +namespace beecrypt { + namespace security { + namespace spec { + class BEECRYPTCXXAPI RSAPrivateKeySpec : public KeySpec + { + private: + mpbarrett _n; + mpnumber _d; + + public: + RSAPrivateKeySpec(const mpbarrett& modulus, const mpnumber& privateExponent); + virtual ~RSAPrivateKeySpec(); + + const mpbarrett& getModulus() const throw (); + const mpnumber& getPrivateExponent() const throw (); + }; + } + } +} + +#endif + +#endif diff --git a/beecrypt/c++/security/spec/RSAPublicKeySpec.cxx b/beecrypt/c++/security/spec/RSAPublicKeySpec.cxx new file mode 100644 index 0000000..779928e --- /dev/null +++ b/beecrypt/c++/security/spec/RSAPublicKeySpec.cxx @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/security/spec/RSAPublicKeySpec.h" + +using namespace beecrypt::security::spec; + +RSAPublicKeySpec::RSAPublicKeySpec(const mpbarrett& modulus, const mpnumber& publicExponent) +{ + _n = modulus; + _e = publicExponent; +} + +RSAPublicKeySpec::~RSAPublicKeySpec() +{ +} + +const mpbarrett& RSAPublicKeySpec::getModulus() const throw () +{ + return _n; +} + +const mpnumber& RSAPublicKeySpec::getPublicExponent() const throw () +{ + return _e; +} diff --git a/beecrypt/c++/security/spec/RSAPublicKeySpec.h b/beecrypt/c++/security/spec/RSAPublicKeySpec.h new file mode 100644 index 0000000..7a8c0e6 --- /dev/null +++ b/beecrypt/c++/security/spec/RSAPublicKeySpec.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file RSAPublicKeySpec.h + * \ingroup CXX_SECURITY_SPEC_m + */ + +#ifndef _CLASS_RSAPUBLICKEYSPEC_H +#define _CLASS_RSAPUBLICKEYSPEC_H + +#include "beecrypt/api.h" +#include "beecrypt/mpbarrett.h" + +#ifdef __cplusplus + +#include "beecrypt/c++/security/spec/KeySpec.h" +using beecrypt::security::spec::KeySpec; + +namespace beecrypt { + namespace security { + namespace spec { + class BEECRYPTCXXAPI RSAPublicKeySpec : public KeySpec + { + private: + mpbarrett _n; + mpnumber _e; + + public: + RSAPublicKeySpec(const mpbarrett& modulus, const mpnumber& publicExponent); + virtual ~RSAPublicKeySpec(); + + const mpbarrett& getModulus() const throw (); + const mpnumber& getPublicExponent() const throw (); + }; + } + } +} + +#endif + +#endif diff --git a/beecrypt/c++/testdsa.cxx b/beecrypt/c++/testdsa.cxx new file mode 100644 index 0000000..18832a4 --- /dev/null +++ b/beecrypt/c++/testdsa.cxx @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/security/AlgorithmParameterGenerator.h" +using beecrypt::security::AlgorithmParameterGenerator; +#include "beecrypt/c++/security/AlgorithmParameters.h" +using beecrypt::security::AlgorithmParameters; +#include "beecrypt/c++/security/KeyFactory.h" +using beecrypt::security::KeyFactory; +#include "beecrypt/c++/security/KeyPairGenerator.h" +using beecrypt::security::KeyPairGenerator; +#include "beecrypt/c++/security/Signature.h" +using beecrypt::security::Signature; +#include "beecrypt/c++/security/spec/EncodedKeySpec.h" +using beecrypt::security::spec::EncodedKeySpec; + +#include +using namespace std; +#include + +int main(int argc, char* argv[]) +{ + int failures = 0; + + try + { + KeyPairGenerator* kpg = KeyPairGenerator::getInstance("DSA"); + + kpg->initialize(1024); + + KeyPair* pair = kpg->generateKeyPair(); + + Signature* sig = Signature::getInstance("SHA1withDSA"); + + sig->initSign(pair->getPrivate()); + + bytearray* tmp = sig->sign(); + + sig->initVerify(pair->getPublic()); + + if (!sig->verify(*tmp)) + failures++; + + KeyFactory* kf = KeyFactory::getInstance("BEE"); + + KeySpec* spec = kf->getKeySpec(pair->getPublic(), typeid(EncodedKeySpec)); + + PublicKey* pub = kf->generatePublic(*spec); + + delete pub; + delete spec; + delete kf; + delete tmp; + delete sig; + delete pair; + delete kpg; + } + catch (Exception& ex) + { + cerr << "exception: " << ex.getMessage() << endl; + failures++; + } + catch (...) + { + cerr << "exception" << endl; + failures++; + } + return failures; +} diff --git a/beecrypt/c++/testks.cxx b/beecrypt/c++/testks.cxx new file mode 100644 index 0000000..67153b4 --- /dev/null +++ b/beecrypt/c++/testks.cxx @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/io/FileInputStream.h" +using beecrypt::io::FileInputStream; +#include "beecrypt/c++/io/FileOutputStream.h" +using beecrypt::io::FileOutputStream; +#include "beecrypt/c++/security/KeyStore.h" +using beecrypt::security::KeyStore; +#include "beecrypt/c++/security/KeyPairGenerator.h" +using beecrypt::security::KeyPairGenerator; +#include "beecrypt/c++/beeyond/BeeCertificate.h" +using beecrypt::beeyond::BeeCertificate; + +#include +using std::cout; +using std::endl; +#include + +int main(int argc, char* argv[]) +{ + try + { + array password(4); + + password[0] = (javachar) 't'; + password[1] = (javachar) 'e'; + password[2] = (javachar) 's'; + password[3] = (javachar) 't'; + + KeyStore* ks = KeyStore::getInstance(KeyStore::getDefaultType()); + + if (argc == 2) + { + FileInputStream fin(fopen(argv[1], "rb")); + + ks->load(&fin, &password); + + Key* k = ks->getKey("rsa", password); + + cout << "k algorithm = " << k->getAlgorithm() << endl; + + delete k; + } + else + { + KeyPairGenerator* kpg = KeyPairGenerator::getInstance("RSA"); + + kpg->initialize(1024); + + KeyPair* pair = kpg->generateKeyPair(); + + vector chain; + + chain.push_back(BeeCertificate::self(pair->getPublic(), pair->getPrivate(), "SHA1withRSA")); + + FileOutputStream fos(fopen("keystore", "wb")); + + // create an empty stream + ks->load((InputStream*) 0, &password); + ks->setKeyEntry("rsa", pair->getPrivate(), password, chain); + ks->store(fos, &password); + } + + delete ks; + } + catch (Exception e) + { + cout << "Exception: " + e.getMessage() << endl; + } +} diff --git a/beecrypt/c++/testrsa.cxx b/beecrypt/c++/testrsa.cxx new file mode 100644 index 0000000..3461cd9 --- /dev/null +++ b/beecrypt/c++/testrsa.cxx @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/security/Security.h" +using beecrypt::security::Security; +#include "beecrypt/c++/security/AlgorithmParameterGenerator.h" +using beecrypt::security::AlgorithmParameterGenerator; +#include "beecrypt/c++/security/AlgorithmParameters.h" +using beecrypt::security::AlgorithmParameters; +#include "beecrypt/c++/security/KeyFactory.h" +using beecrypt::security::KeyFactory; +#include "beecrypt/c++/security/KeyPairGenerator.h" +using beecrypt::security::KeyPairGenerator; +#include "beecrypt/c++/security/Signature.h" +using beecrypt::security::Signature; +#include "beecrypt/c++/security/spec/EncodedKeySpec.h" +using beecrypt::security::spec::EncodedKeySpec; + +#include +using namespace std; +#include + +int main(int argc, char* argv[]) +{ + int failures = 0; + + try + { + KeyPairGenerator* kpg = KeyPairGenerator::getInstance("RSA"); + + kpg->initialize(1024); + + KeyPair* pair = kpg->generateKeyPair(); + + Signature* sig = Signature::getInstance("SHA1withRSA"); + + sig->initSign(pair->getPrivate()); + + bytearray* tmp = sig->sign(); + + sig->initVerify(pair->getPublic()); + + if (!sig->verify(*tmp)) + failures++; + + KeyFactory* kf = KeyFactory::getInstance("BEE"); + + KeySpec* spec = kf->getKeySpec(pair->getPublic(), typeid(EncodedKeySpec)); + + PublicKey* pub = kf->generatePublic(*spec); + + delete pub; + delete spec; + delete kf; + delete tmp; + delete sig; + delete pair; + delete kpg; + } + catch (Exception& ex) + { + cerr << "Exception: " << ex.getMessage() << endl; + failures++; + } + catch (...) + { + cerr << "exception" << endl; + failures++; + } + return failures; +} diff --git a/beecrypt/c++/util/Date.cxx b/beecrypt/c++/util/Date.cxx new file mode 100644 index 0000000..8bce5f3 --- /dev/null +++ b/beecrypt/c++/util/Date.cxx @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/timestamp.h" +#include "beecrypt/c++/util/Date.h" + +#include + +namespace { + #if WIN32 + __declspec(thread) String* result = 0; + __declspec(thread) DateFormat* format = 0; + #else + # if __GNUC__ && __GNUC_PREREQ (3, 3) + __thread String* result = 0; + __thread DateFormat* format = 0; + # else + # warning Date.toString() method routine is not multi-thread safe + String* result = 0; + DateFormat* format = 0; + # endif + #endif +} + +using namespace beecrypt::util; + +Date::Date() throw () +{ + _time = timestamp(); +} + +Date::Date(javalong time) throw () +{ + _time = time; +} + +const Date& Date::operator=(const Date& set) throw () +{ + _time = set._time; + return *this; +} + +bool Date::operator==(const Date& cmp) const throw () +{ + return _time == cmp._time; +} + +bool Date::operator!=(const Date& cmp) const throw () +{ + return _time != cmp._time; +} + +bool Date::after(const Date& cmp) const throw () +{ + return _time > cmp._time; +} + +bool Date::before(const Date& cmp) const throw () +{ + return _time < cmp._time; +} + +javalong Date::getTime() const throw () +{ + return _time; +} + +void Date::setTime(javalong time) throw () +{ + _time = time; +} + +const String& Date::toString() const +{ + if (!format) + format = DateFormat::createDateTimeInstance(); + + if (!result) + result = new String(); + + *result = format->format((UDate) _time, *result); + + return *result; +} diff --git a/beecrypt/c++/util/Date.h b/beecrypt/c++/util/Date.h new file mode 100644 index 0000000..a1e6db7 --- /dev/null +++ b/beecrypt/c++/util/Date.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file Date.h + * \ingroup CXX_UTIL_m + */ + +#ifndef _CLASS_DATE_H +#define _CLASS_DATE_H + +#include "beecrypt/api.h" + +#ifdef __cplusplus + +#include "beecrypt/c++/lang/String.h" +using beecrypt::lang::String; + +namespace beecrypt { + namespace util { + class BEECRYPTCXXAPI Date + { + private: + javalong _time; + + public: + Date() throw (); + Date(javalong) throw (); + + const Date& operator=(const Date&) throw (); + bool operator==(const Date&) const throw (); + bool operator!=(const Date&) const throw (); + + bool after(const Date&) const throw (); + bool before(const Date&) const throw (); + + javalong getTime() const throw (); + void setTime(javalong) throw (); + + const String& toString() const; + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/util/Enumeration.h b/beecrypt/c++/util/Enumeration.h new file mode 100644 index 0000000..78fd49b --- /dev/null +++ b/beecrypt/c++/util/Enumeration.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file Enumeration.h + * \ingroup CXX_UTIL_m + */ + +#ifndef _INTERFACE_ENUMERATION_H +#define _INTERFACE_ENUMERATION_H + +#ifdef __cplusplus + +#include "beecrypt/c++/util/NoSuchElementException.h" +using beecrypt::util::NoSuchElementException; + +namespace beecrypt { + namespace util { + class BEECRYPTCXXAPI Enumeration + { + public: + virtual ~Enumeration() throw () {}; + + virtual bool hasMoreElements() throw () = 0; + virtual const void* nextElement() throw (NoSuchElementException) = 0; + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/util/Makefile.am b/beecrypt/c++/util/Makefile.am new file mode 100644 index 0000000..7d5d7a1 --- /dev/null +++ b/beecrypt/c++/util/Makefile.am @@ -0,0 +1,27 @@ +INCLUDES = -I$(top_srcdir)/.. + +AUTOMAKE_OPTIONS = gnu no-dependencies + +noinst_LTLIBRARIES = libcxxutil.la +cxxutildir= $(pkgincludedir)/c++/util + +libcxxutil_la_SOURCES =\ +Date.cxx \ +NoSuchElementException.cxx \ +Properties.cxx + +cxxutil_HEADERS =\ +Date.h \ +Enumeration.h \ +NoSuchElementException.h \ +Properties.h + +TESTS = testdate testprop + +check_PROGRAMS = testdate testprop + +testdate_SOURCES = testdate.cxx +testdate_LDADD = ../libbeecrypt_cxx.la + +testprop_SOURCES = testprop.cxx +testprop_LDADD = ../libbeecrypt_cxx.la diff --git a/beecrypt/c++/util/Makefile.in b/beecrypt/c++/util/Makefile.in new file mode 100644 index 0000000..05b5c4c --- /dev/null +++ b/beecrypt/c++/util/Makefile.in @@ -0,0 +1,597 @@ +# Makefile.in generated by automake 1.8.3 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + + +SOURCES = $(libcxxutil_la_SOURCES) $(testdate_SOURCES) $(testprop_SOURCES) + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +top_builddir = ../.. +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +INSTALL = @INSTALL@ +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +host_triplet = @host@ +check_PROGRAMS = testdate$(EXEEXT) testprop$(EXEEXT) +subdir = c++/util +DIST_COMMON = $(cxxutil_HEADERS) $(srcdir)/Makefile.am \ + $(srcdir)/Makefile.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \ + $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +LTLIBRARIES = $(noinst_LTLIBRARIES) +libcxxutil_la_LIBADD = +am_libcxxutil_la_OBJECTS = Date.lo NoSuchElementException.lo \ + Properties.lo +libcxxutil_la_OBJECTS = $(am_libcxxutil_la_OBJECTS) +am_testdate_OBJECTS = testdate.$(OBJEXT) +testdate_OBJECTS = $(am_testdate_OBJECTS) +testdate_DEPENDENCIES = ../libbeecrypt_cxx.la +am_testprop_OBJECTS = testprop.$(OBJEXT) +testprop_OBJECTS = $(am_testprop_OBJECTS) +testprop_DEPENDENCIES = ../libbeecrypt_cxx.la +DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir) +depcomp = +am__depfiles_maybe = +CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) +LTCXXCOMPILE = $(LIBTOOL) --mode=compile $(CXX) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CXXFLAGS) $(CXXFLAGS) +CXXLD = $(CXX) +CXXLINK = $(LIBTOOL) --mode=link $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) \ + $(AM_LDFLAGS) $(LDFLAGS) -o $@ +SOURCES = $(libcxxutil_la_SOURCES) $(testdate_SOURCES) \ + $(testprop_SOURCES) +DIST_SOURCES = $(libcxxutil_la_SOURCES) $(testdate_SOURCES) \ + $(testprop_SOURCES) +am__installdirs = "$(DESTDIR)$(cxxutildir)" +cxxutilHEADERS_INSTALL = $(INSTALL_HEADER) +HEADERS = $(cxxutil_HEADERS) +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMDEP_FALSE = @AMDEP_FALSE@ +AMDEP_TRUE = @AMDEP_TRUE@ +AMTAR = @AMTAR@ +AR = @AR@ +AS = @AS@ +ASM_ALIGN = @ASM_ALIGN@ +ASM_ARCH = @ASM_ARCH@ +ASM_BIGENDIAN = @ASM_BIGENDIAN@ +ASM_CPU = @ASM_CPU@ +ASM_GLOBL = @ASM_GLOBL@ +ASM_GSYM_PREFIX = @ASM_GSYM_PREFIX@ +ASM_LSYM_PREFIX = @ASM_LSYM_PREFIX@ +ASM_OS = @ASM_OS@ +ASM_TEXTSEG = @ASM_TEXTSEG@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCAS = @CCAS@ +CCASFLAGS = @CCASFLAGS@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DLLTOOL = @DLLTOOL@ +ECHO = @ECHO@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +F77 = @F77@ +FFLAGS = @FFLAGS@ +INCLUDE_DLFCN_H = @INCLUDE_DLFCN_H@ +INCLUDE_INTTYPES_H = @INCLUDE_INTTYPES_H@ +INCLUDE_MALLOC_H = @INCLUDE_MALLOC_H@ +INCLUDE_PTHREAD_H = @INCLUDE_PTHREAD_H@ +INCLUDE_STDINT_H = @INCLUDE_STDINT_H@ +INCLUDE_STDIO_H = @INCLUDE_STDIO_H@ +INCLUDE_STDLIB_H = @INCLUDE_STDLIB_H@ +INCLUDE_STRING_H = @INCLUDE_STRING_H@ +INCLUDE_SYNCH_H = @INCLUDE_SYNCH_H@ +INCLUDE_THREAD_H = @INCLUDE_THREAD_H@ +INCLUDE_UNISTD_H = @INCLUDE_UNISTD_H@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +JAVAINC = @JAVAINC@ +LDFLAGS = @LDFLAGS@ +LIBALT = @LIBALT@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +MAYBE_LTLIB = @MAYBE_LTLIB@ +MAYBE_SUB = @MAYBE_SUB@ +MP_WBITS = @MP_WBITS@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PYTHONINC = @PYTHONINC@ +PYTHONLIB = @PYTHONLIB@ +RANLIB = @RANLIB@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +TYPEDEF_BC_COND_T = @TYPEDEF_BC_COND_T@ +TYPEDEF_BC_MUTEX_T = @TYPEDEF_BC_MUTEX_T@ +TYPEDEF_BC_THREAD_T = @TYPEDEF_BC_THREAD_T@ +TYPEDEF_INT16_T = @TYPEDEF_INT16_T@ +TYPEDEF_INT32_T = @TYPEDEF_INT32_T@ +TYPEDEF_INT64_T = @TYPEDEF_INT64_T@ +TYPEDEF_INT8_T = @TYPEDEF_INT8_T@ +TYPEDEF_SIZE_T = @TYPEDEF_SIZE_T@ +TYPEDEF_UINT16_T = @TYPEDEF_UINT16_T@ +TYPEDEF_UINT32_T = @TYPEDEF_UINT32_T@ +TYPEDEF_UINT64_T = @TYPEDEF_UINT64_T@ +TYPEDEF_UINT8_T = @TYPEDEF_UINT8_T@ +VERSION = @VERSION@ +ac_ct_AR = @ac_ct_AR@ +ac_ct_AS = @ac_ct_AS@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DLLTOOL = @ac_ct_DLLTOOL@ +ac_ct_F77 = @ac_ct_F77@ +ac_ct_OBJDUMP = @ac_ct_OBJDUMP@ +ac_ct_RANLIB = @ac_ct_RANLIB@ +ac_ct_STRIP = @ac_ct_STRIP@ +ac_cv_have_gcj = @ac_cv_have_gcj@ +ac_cv_have_java = @ac_cv_have_java@ +ac_cv_have_javac = @ac_cv_have_javac@ +ac_cv_have_python = @ac_cv_have_python@ +am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ +am__fastdepCC_TRUE = @am__fastdepCC_TRUE@ +am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@ +am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +datadir = @datadir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +sysconfdir = @sysconfdir@ +target = @target@ +target_alias = @target_alias@ +target_cpu = @target_cpu@ +target_os = @target_os@ +target_vendor = @target_vendor@ +INCLUDES = -I$(top_srcdir)/.. +AUTOMAKE_OPTIONS = gnu no-dependencies +noinst_LTLIBRARIES = libcxxutil.la +cxxutildir = $(pkgincludedir)/c++/util +libcxxutil_la_SOURCES = \ +Date.cxx \ +NoSuchElementException.cxx \ +Properties.cxx + +cxxutil_HEADERS = \ +Date.h \ +Enumeration.h \ +NoSuchElementException.h \ +Properties.h + +TESTS = testdate testprop +testdate_SOURCES = testdate.cxx +testdate_LDADD = ../libbeecrypt_cxx.la +testprop_SOURCES = testprop.cxx +testprop_LDADD = ../libbeecrypt_cxx.la +all: all-am + +.SUFFIXES: +.SUFFIXES: .cxx .lo .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ + && exit 0; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu c++/util/Makefile'; \ + cd $(top_srcdir) && \ + $(AUTOMAKE) --gnu c++/util/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +clean-noinstLTLIBRARIES: + -test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES) + @list='$(noinst_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" = "$$p" && dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +libcxxutil.la: $(libcxxutil_la_OBJECTS) $(libcxxutil_la_DEPENDENCIES) + $(CXXLINK) $(libcxxutil_la_LDFLAGS) $(libcxxutil_la_OBJECTS) $(libcxxutil_la_LIBADD) $(LIBS) + +clean-checkPROGRAMS: + @list='$(check_PROGRAMS)'; for p in $$list; do \ + f=`echo $$p|sed 's/$(EXEEXT)$$//'`; \ + echo " rm -f $$p $$f"; \ + rm -f $$p $$f ; \ + done +testdate$(EXEEXT): $(testdate_OBJECTS) $(testdate_DEPENDENCIES) + @rm -f testdate$(EXEEXT) + $(CXXLINK) $(testdate_LDFLAGS) $(testdate_OBJECTS) $(testdate_LDADD) $(LIBS) +testprop$(EXEEXT): $(testprop_OBJECTS) $(testprop_DEPENDENCIES) + @rm -f testprop$(EXEEXT) + $(CXXLINK) $(testprop_LDFLAGS) $(testprop_OBJECTS) $(testprop_LDADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +.cxx.o: + $(CXXCOMPILE) -c -o $@ $< + +.cxx.obj: + $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +.cxx.lo: + $(LTCXXCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +distclean-libtool: + -rm -f libtool +uninstall-info-am: +install-cxxutilHEADERS: $(cxxutil_HEADERS) + @$(NORMAL_INSTALL) + test -z "$(cxxutildir)" || $(mkdir_p) "$(DESTDIR)$(cxxutildir)" + @list='$(cxxutil_HEADERS)'; for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + f="`echo $$p | sed -e 's|^.*/||'`"; \ + echo " $(cxxutilHEADERS_INSTALL) '$$d$$p' '$(DESTDIR)$(cxxutildir)/$$f'"; \ + $(cxxutilHEADERS_INSTALL) "$$d$$p" "$(DESTDIR)$(cxxutildir)/$$f"; \ + done + +uninstall-cxxutilHEADERS: + @$(NORMAL_UNINSTALL) + @list='$(cxxutil_HEADERS)'; for p in $$list; do \ + f="`echo $$p | sed -e 's|^.*/||'`"; \ + echo " rm -f '$(DESTDIR)$(cxxutildir)/$$f'"; \ + rm -f "$(DESTDIR)$(cxxutildir)/$$f"; \ + done + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(ETAGS_ARGS)$$tags$$unique" \ + || $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$tags $$unique +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(CTAGS_ARGS)$$tags$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$tags $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && cd $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) $$here + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +check-TESTS: $(TESTS) + @failed=0; all=0; xfail=0; xpass=0; skip=0; \ + srcdir=$(srcdir); export srcdir; \ + list='$(TESTS)'; \ + if test -n "$$list"; then \ + for tst in $$list; do \ + if test -f ./$$tst; then dir=./; \ + elif test -f $$tst; then dir=; \ + else dir="$(srcdir)/"; fi; \ + if $(TESTS_ENVIRONMENT) $${dir}$$tst; then \ + all=`expr $$all + 1`; \ + case " $(XFAIL_TESTS) " in \ + *" $$tst "*) \ + xpass=`expr $$xpass + 1`; \ + failed=`expr $$failed + 1`; \ + echo "XPASS: $$tst"; \ + ;; \ + *) \ + echo "PASS: $$tst"; \ + ;; \ + esac; \ + elif test $$? -ne 77; then \ + all=`expr $$all + 1`; \ + case " $(XFAIL_TESTS) " in \ + *" $$tst "*) \ + xfail=`expr $$xfail + 1`; \ + echo "XFAIL: $$tst"; \ + ;; \ + *) \ + failed=`expr $$failed + 1`; \ + echo "FAIL: $$tst"; \ + ;; \ + esac; \ + else \ + skip=`expr $$skip + 1`; \ + echo "SKIP: $$tst"; \ + fi; \ + done; \ + if test "$$failed" -eq 0; then \ + if test "$$xfail" -eq 0; then \ + banner="All $$all tests passed"; \ + else \ + banner="All $$all tests behaved as expected ($$xfail expected failures)"; \ + fi; \ + else \ + if test "$$xpass" -eq 0; then \ + banner="$$failed of $$all tests failed"; \ + else \ + banner="$$failed of $$all tests did not behave as expected ($$xpass unexpected passes)"; \ + fi; \ + fi; \ + dashes="$$banner"; \ + skipped=""; \ + if test "$$skip" -ne 0; then \ + skipped="($$skip tests were not run)"; \ + test `echo "$$skipped" | wc -c` -gt `echo "$$banner" | wc -c` && \ + dashes="$$skipped"; \ + fi; \ + report=""; \ + if test "$$failed" -ne 0 && test -n "$(PACKAGE_BUGREPORT)"; then \ + report="Please report to $(PACKAGE_BUGREPORT)"; \ + test `echo "$$report" | wc -c` -gt `echo "$$banner" | wc -c` && \ + dashes="$$report"; \ + fi; \ + dashes=`echo "$$dashes" | sed s/./=/g`; \ + echo "$$dashes"; \ + echo "$$banner"; \ + test -n "$$skipped" && echo "$$skipped"; \ + test -n "$$report" && echo "$$report"; \ + echo "$$dashes"; \ + test "$$failed" -eq 0; \ + else :; fi + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \ + list='$(DISTFILES)'; for file in $$list; do \ + case $$file in \ + $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \ + $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \ + esac; \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test "$$dir" != "$$file" && test "$$dir" != "."; then \ + dir="/$$dir"; \ + $(mkdir_p) "$(distdir)$$dir"; \ + else \ + dir=''; \ + fi; \ + if test -d $$d/$$file; then \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + fi; \ + cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ + else \ + test -f $(distdir)/$$file \ + || cp -p $$d/$$file $(distdir)/$$file \ + || exit 1; \ + fi; \ + done +check-am: all-am + $(MAKE) $(AM_MAKEFLAGS) $(check_PROGRAMS) + $(MAKE) $(AM_MAKEFLAGS) check-TESTS +check: check-am +all-am: Makefile $(LTLIBRARIES) $(HEADERS) +installdirs: + for dir in "$(DESTDIR)$(cxxutildir)"; do \ + test -z "$$dir" || $(mkdir_p) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -rm -f $(CONFIG_CLEAN_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-checkPROGRAMS clean-generic clean-libtool \ + clean-noinstLTLIBRARIES mostlyclean-am + +distclean: distclean-am + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-libtool distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +info: info-am + +info-am: + +install-data-am: install-cxxutilHEADERS + +install-exec-am: + +install-info: install-info-am + +install-man: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-cxxutilHEADERS uninstall-info-am + +.PHONY: CTAGS GTAGS all all-am check check-TESTS check-am clean \ + clean-checkPROGRAMS clean-generic clean-libtool \ + clean-noinstLTLIBRARIES ctags distclean distclean-compile \ + distclean-generic distclean-libtool distclean-tags distdir dvi \ + dvi-am html html-am info info-am install install-am \ + install-cxxutilHEADERS install-data install-data-am \ + install-exec install-exec-am install-info install-info-am \ + install-man install-strip installcheck installcheck-am \ + installdirs maintainer-clean maintainer-clean-generic \ + mostlyclean mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool pdf pdf-am ps ps-am tags uninstall \ + uninstall-am uninstall-cxxutilHEADERS uninstall-info-am + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/beecrypt/c++/util/NoSuchElementException.cxx b/beecrypt/c++/util/NoSuchElementException.cxx new file mode 100644 index 0000000..6d22074 --- /dev/null +++ b/beecrypt/c++/util/NoSuchElementException.cxx @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/util/NoSuchElementException.h" + +using namespace beecrypt::util; + +NoSuchElementException::NoSuchElementException() throw () +{ +} + +NoSuchElementException::NoSuchElementException(const String& message) throw () : RuntimeException(message) +{ +} diff --git a/beecrypt/c++/util/NoSuchElementException.h b/beecrypt/c++/util/NoSuchElementException.h new file mode 100644 index 0000000..4271d20 --- /dev/null +++ b/beecrypt/c++/util/NoSuchElementException.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file NoSuchElementException.h + * \ingroup CXX_UTIL_m + */ + +#ifndef _CLASS_NOSUCHELEMENTEXCEPTION_H +#define _CLASS_NOSUCHELEMENTEXCEPTION_H + +#ifdef __cplusplus + +#include "beecrypt/c++/lang/RuntimeException.h" +using beecrypt::lang::RuntimeException; + +namespace beecrypt { + namespace util { + class BEECRYPTCXXAPI NoSuchElementException : public RuntimeException + { + public: + NoSuchElementException() throw (); + NoSuchElementException(const String&) throw (); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/util/Properties.cxx b/beecrypt/c++/util/Properties.cxx new file mode 100644 index 0000000..d1b0b8c --- /dev/null +++ b/beecrypt/c++/util/Properties.cxx @@ -0,0 +1,171 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/c++/util/Properties.h" +using beecrypt::util::Properties; +#include "beecrypt/c++/io/DataInputStream.h" +using beecrypt::io::DataInputStream; +#include "beecrypt/c++/io/PrintStream.h" +using beecrypt::io::PrintStream; + +using namespace beecrypt::util; + +Properties::PropEnum::PropEnum(const properties_map& _map) throw () +{ + _it = _map.begin(); + _end = _map.end(); +} + +Properties::PropEnum::~PropEnum() throw () +{ +} + +bool Properties::PropEnum::hasMoreElements() throw () +{ + return _it != _end; +} + +const void* Properties::PropEnum::nextElement() throw (NoSuchElementException) +{ + if (_it == _end) + throw NoSuchElementException(); + + return (const void*) &((_it++)->first); +} + +Properties::Properties() +{ + _lock.init(); + defaults = 0; +} + +Properties::Properties(const Properties& copy) +{ + _lock.init(); + /* copy every item in the map */ + _pmap = copy._pmap; + defaults = copy.defaults; +} + +Properties::Properties(const Properties* defaults) : defaults(defaults) +{ + _lock.init(); +} + +Properties::~Properties() +{ + _lock.destroy(); +} + +const String* Properties::getProperty(const String& key) const throw () +{ + properties_map::const_iterator it = _pmap.find(key); + + if (it != _pmap.end()) + return &(it->second); + else if (defaults) + return defaults->getProperty(key); + + return 0; +} + +const String* Properties::getProperty(const String& key, const String& defaultValue) const throw () +{ + const String* result = getProperty(key); + + if (result) + return result; + else + return &defaultValue; +} + +void Properties::setProperty(const String& key, const String& value) throw () +{ + _lock.lock(); + _pmap[key] = value; + _lock.unlock(); +} + +Enumeration* Properties::propertyNames() const +{ + return new PropEnum(_pmap); +} + +void Properties::load(InputStream& in) throw (IOException) +{ + String line; + String key; + String value; + + DataInputStream dis(in); + + _lock.lock(); + try + { + while (dis.available()) + { + dis.readLine(line); + + if (line.indexOf((UChar) 0x23) != 0) + { + // more advanced parsing can come later + // see if we can find an '=' somewhere inside the string + int32_t eqidx = line.indexOf((UChar) 0x3D); + if (eqidx >= 0) + { + // we can split the line into two parts + key.setTo(line, 0, eqidx); + value.setTo(line, eqidx+1); + _pmap[key] = value; + } + } + // else it's a comment line which we discard + } + _lock.unlock(); + } + catch (IOException) + { + _lock.unlock(); + throw; + } +} + +void Properties::store(OutputStream& out, const String& header) throw (IOException) +{ + properties_map::const_iterator pit; + PrintStream ps(out); + + ps.println("# " + header); + + _lock.lock(); + + for (pit = _pmap.begin(); pit != _pmap.end(); ++pit) + { + ps.print(pit->first); + ps.print((javachar) 0x3D); + ps.println(pit->second); + } + + _lock.unlock(); +} diff --git a/beecrypt/c++/util/Properties.h b/beecrypt/c++/util/Properties.h new file mode 100644 index 0000000..f5a2aeb --- /dev/null +++ b/beecrypt/c++/util/Properties.h @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/*!\file Properties.h + * \ingroup CXX_UTIL_m + */ + +#ifndef _CLASS_PROPERTIES_H +#define _CLASS_PROPERTIES_H + +#ifdef __cplusplus + +#include "beecrypt/c++/mutex.h" +using beecrypt::mutex; +#include "beecrypt/c++/io/InputStream.h" +using beecrypt::io::InputStream; +#include "beecrypt/c++/io/OutputStream.h" +using beecrypt::io::OutputStream; +#include "beecrypt/c++/lang/String.h" +using beecrypt::lang::String; +#include "beecrypt/c++/util/Enumeration.h" +using beecrypt::util::Enumeration; + +#include +using std::map; + +namespace beecrypt { + namespace util { + class BEECRYPTCXXAPI Properties + { + private: + typedef map properties_map; + + class PropEnum : public Enumeration + { + public: + properties_map::const_iterator _it; + properties_map::const_iterator _end; + + public: + PropEnum(const properties_map&) throw (); + virtual ~PropEnum() throw (); + + virtual bool hasMoreElements() throw (); + virtual const void* nextElement() throw (NoSuchElementException); + }; + + properties_map _pmap; + + mutex _lock; + + protected: + const Properties* defaults; + + public: + Properties(); + Properties(const Properties& copy); + Properties(const Properties* defaults); + ~Properties(); + + const String* getProperty(const String& key) const throw (); + const String* getProperty(const String& key, const String& defaultValue) const throw (); + + void setProperty(const String& key, const String& value) throw (); + + Enumeration* propertyNames() const; + + void load(InputStream& in) throw (IOException); + void store(OutputStream& out, const String& header) throw (IOException); + }; + } +} + +#endif + +#endif diff --git a/beecrypt/c++/util/testdate.cxx b/beecrypt/c++/util/testdate.cxx new file mode 100644 index 0000000..e822b31 --- /dev/null +++ b/beecrypt/c++/util/testdate.cxx @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +// #define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "c++/util/Date.h" +using beecrypt::util::Date; + +#include +#include +using namespace std; + +int main(int argc, char* argv[]) +{ + Date now; + + cout << now.toString() << endl; +} diff --git a/beecrypt/c++/util/testprop.cxx b/beecrypt/c++/util/testprop.cxx new file mode 100644 index 0000000..9646da4 --- /dev/null +++ b/beecrypt/c++/util/testprop.cxx @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2004 Beeyond Software Holding BV + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +// #define BEECRYPT_CXX_DLL_EXPORT + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "c++/io/FileOutputStream.h" +using beecrypt::io::FileOutputStream; +#include "c++/util/Properties.h" +using beecrypt::util::Properties; + +#include +#include +using namespace std; +#include + +int main(int argc, char* argv[]) +{ + + Properties p; + + p.setProperty("apple", "red"); + p.setProperty("yam", "orange"); + p.setProperty("lime", "green"); + p.setProperty("grape", "blue"); + + Enumeration* e = p.propertyNames(); + + while (e->hasMoreElements()) + { + const String* s = (const String*) e->nextElement(); + + cout << *s << endl; + } + + delete e; + + FileOutputStream fso(stdout); + p.store(fso, "properties test"); +} diff --git a/beecrypt/config.m4.in b/beecrypt/config.m4.in index 3d83dd9..a394065 100644 --- a/beecrypt/config.m4.in +++ b/beecrypt/config.m4.in @@ -12,5 +12,4 @@ define(`GSYM_PREFIX',`@ASM_GSYM_PREFIX@') define(`LSYM_PREFIX',`@ASM_LSYM_PREFIX@') define(`ALIGN',`@ASM_ALIGN@') define(`__CONFIG_M4_INCLUDED__') -include(`@top_srcdir@/gas/asmdefs.m4') ') diff --git a/beecrypt/configure.ac b/beecrypt/configure.ac index df3c620..69dba94 100644 --- a/beecrypt/configure.ac +++ b/beecrypt/configure.ac @@ -1,6 +1,6 @@ # Process this file with autoconf to produce a configure script. -AC_INIT([beecrypt],[3.0.0pre],[bob.deblier@pandora.be]) +AC_INIT([beecrypt],[4.0.0],[bob.deblier@telenet.be]) AM_INIT_AUTOMAKE AC_CANONICAL_TARGET AC_CONFIG_SRCDIR(beecrypt.h) @@ -17,125 +17,15 @@ AC_ARG_ENABLE(debug, [ --enable-debug creates debugging code [default= ],[ ac_enable_debug=no]) AC_ARG_WITH(cpu,[ --with-cpu optimize for specific cpu],[ - ac_with_cpu=yes - bc_target_cpu=$withval - case $target_cpu in - i[[3456]]86) - case $withval in - i[[3456]]86 | \ - pentium | pentium-mmx | pentiumpro | pentium[[234]] | \ - athlon | athlon-tbird | athlon-4 | athlon-xp | athlon-mp) - ;; - *) - AC_MSG_WARN([invalid cpu type]) - bc_target_cpu=$target_cpu - ;; - esac - ;; - powerpc) - case $withval in - 403 | 505 | \ - 60[[1234]] | 60[[34]]e | 6[[23]]0 | \ - 7[[45]]0 | 74[[05]]0 | \ - 801 | 82[[13]] | 860 | \ - power | power2 | powerpc | powerpc64) - ;; - *) - AC_MSG_WARN([invalid cpu type]) - bc_target_cpu=$target_cpu - ;; - esac - ;; - sparc) - case $withval in - sparcv8 | sparcv8plus | sparcv8plus[[ab]] | sparcv9 | sparcv9[[ab]]) - ;; - *) - AC_MSG_WARN([invalid cpu type]) - bc_target_cpu=$target_cpu - ;; - esac - ;; - x86) # QNX Neutrino doesn't list the exact cpu type - case $withval in - i[[3456]]86) - ;; - *) - AC_MSG_WARN([unsupported or invalid cpu type]) - bc_target_cpu=$target_cpu - ;; - esac - ;; - *) - AC_MSG_WARN([unsupported or invalid cpu type]) - bc_target_cpu=$target_cpu - ;; - esac + BEECRYPT_WITH_CPU ],[ - ac_with_cpu=no - bc_target_cpu=$target_cpu + BEECRYPT_WITHOUT_CPU ]) AC_ARG_WITH(arch,[ --with-arch optimize for specific architecture (may not run on other cpus of same family)],[ - ac_with_arch=yes - bc_target_arch=$withval - case $target_cpu in - i[[3456]]86) - case $withval in - i[[3456]]86 | \ - pentium | pentium-mmx | pentiumpro | pentium[[234]] | \ - athlon | athlon-tbird | athlon-4 | athlon-xp | athlon-mp) - if test "$ac_with_cpu" != yes; then - bc_target_cpu=$withval - fi - ;; - esac - ;; - powerpc*) - case $withval in - powerpc) - ;; - powerpc64) - bc_target_arch=powerpc64 - ;; - *) - AC_MSG_WARN([unsupported on invalid arch type]) - bc_target_arch=powerpc - ;; - esac - ;; - esac + BEECRYPT_WITH_ARCH ],[ - ac_with_arch=no - case $target_cpu in - alpha*) - bc_target_arch=alpha - ;; - arm*) - bc_target_arch=arm - ;; - i[[3456]]86) - bc_target_arch=i386 - ;; - ia64) - bc_target_arch=ia64 - ;; - m68k) - bc_target_arch=m68k - ;; - powerpc*) - bc_target_arch=powerpc - ;; - s390x) - bc_target_arch=s390x - ;; - sparc*) - bc_target_arch=sparc - ;; - x86_64) - bc_target_arch=x86_64 - ;; - esac + BEECRYPT_WITHOUT_ARCH ]) AC_ARG_ENABLE(threads,[ --enable-threads enables multithread support [default=yes]],[ @@ -146,8 +36,6 @@ AC_ARG_ENABLE(threads,[ --enable-threads enables multithread support [de fi ],[ ac_enable_threads=yes]) -AH_TEMPLATE([ENABLE_THREADS],[Define to 1 if you want to enable multithread support]) - AC_ARG_ENABLE(aio,[ --enable-aio enables asynchronous i/o for entropy gathering [default=yes]],[ if test "$enableval" = no; then ac_enable_aio=no @@ -166,21 +54,29 @@ AC_ARG_WITH(mtmalloc,[ --with-mtmalloc links against the mtmalloc libra fi ],[ac_with_mtmalloc=no]) -AC_ARG_WITH(java,[ --with-java creates the java glue code [default=no]],[ +AC_ARG_WITH(cplusplus,[ --with-cplusplus creates the C++ API code [default=yes]],[ + if test "$withval" = no; then + ac_with_cplusplus=no + else + ac_with_cplusplus=yes + fi + ],[ac_with_cplusplus=yes]) + +AC_ARG_WITH(java,[ --with-java creates the java glue code [default=yes]],[ if test "$withval" = no; then ac_with_java=no else ac_with_java=yes fi - ],[ac_with_java=no]) + ],[ac_with_java=yes]) -AC_ARG_WITH(python,[ --with-python creates the python bindings code [default=no]],[ +AC_ARG_WITH(python,[ --with-python creates the python bindings code [default=yes]],[ if test "$withval" = no; then ac_with_python=no else ac_with_python=yes fi - ],[ac_with_python=no]) + ],[ac_with_python=yes]) # Check for Unix variants AC_AIX @@ -188,49 +84,21 @@ AC_AIX # Checks for C compiler and preprocessor AC_PROG_CC AC_PROG_CPP +AC_PROG_CXX +AC_PROG_CXXCPP +AC_PROG_LD +AC_PROG_LN_S AM_PROG_AS # Checks for compiler characteristics and flags -if test "$ac_cv_c_compiler_gnu" = yes; then - BEECRYPT_GNU_CC -else - case $target_os in - aix*) - BEECRYPT_IBM_CC - ;; - hpux*) - BEECRYPT_HPUX_CC - ;; - linux*) - BEECRYPT_INTEL_CC - ;; - solaris*) - BEECRYPT_SUN_FORTE_CC - ;; - osf*) - BEECRYPT_COMPAQ_CC - ;; - esac -fi +BEECRYPT_CC +BEECRYPT_CXX + +# Check for stack protection +BEECRYPT_NOEXECSTACK # Checks for program flags needed by libtool -case $target_os in -aix*) - case $bc_target_arch in - powerpc64) - AR="ar -X64" - NM="/usr/bin/nm -B -X64" - ;; - esac - ;; -solaris*) - case $bc_target_arch in - sparcv9*) - LD="/usr/ccs/bin/ld -64" - ;; - esac - ;; -esac +BEECRYPT_LIBTOOL # Checks for further programs AC_PROG_AWK @@ -238,66 +106,7 @@ AC_PROG_INSTALL AC_PROG_LIBTOOL # Predefines for autoheader -AH_TEMPLATE([AIX],[Define to 1 if you are using AIX]) -AH_TEMPLATE([CYGWIN],[Define to 1 if you are using Cygwin]) -AH_TEMPLATE([DARWIN],[Define to 1 if you are using Darwin/MacOS X]) -AH_TEMPLATE([FREEBSD],[Define to 1 if you are using FreeBSD]) -AH_TEMPLATE([HPUX],[Define to 1 if you are using HPUX]) -AH_TEMPLATE([LINUX],[Define to 1 if you are using GNU/Linux]) -AH_TEMPLATE([NETBSD],[Define to 1 if you are using NetBSD]) -AH_TEMPLATE([OPENBSD],[Define to 1 if you are using OpenBSD]) -AH_TEMPLATE([OSF],[Define to 1 if you are using OSF]) -AH_TEMPLATE([QNX],[Define to 1 if you are using QNX]) -AH_TEMPLATE([SCO_UNIX],[Define to 1 if you are using SCO Unix]) -AH_TEMPLATE([SOLARIS],[Define to 1 if you are using Solaris]) -AH_VERBATIM([WIN32],[ -#ifndef WIN32 -#undef WIN32 -#endif -]) - -case $target_os in - aix*) - AC_DEFINE([AIX]) - ;; - cygwin*) - AC_DEFINE([CYGWIN]) - AC_DEFINE([WIN32]) - ;; - darwin*) - AC_DEFINE([DARWIN]) - ;; - freebsd*) - AC_DEFINE([FREEBSD]) - ;; - hpux*) - AC_DEFINE([HPUX]) - ;; - linux*) - AC_DEFINE([LINUX]) - ;; - netbsd*) - AC_DEFINE([NETBSD]) - ;; - openbsd*) - AC_DEFINE([OPENBSD]) - ;; - osf*) - AC_DEFINE([OSF]) - ;; - *qnx) - AC_DEFINE([QNX]) - ;; - solaris*) - AC_DEFINE([SOLARIS]) - ;; - sysv*uv*) - AC_DEFINE([SCO_UNIX]) - ;; - *) - AC_MSG_WARN([Operating system type $target_os currently not supported and/or tested]) - ;; -esac +BEECRYPT_OS_DEFS AH_TEMPLATE([HAVE_CTYPE_H],[.]) AH_TEMPLATE([HAVE_ERRNO_H],[.]) @@ -305,6 +114,7 @@ AH_TEMPLATE([HAVE_FCNTL_H],[.]) AH_TEMPLATE([HAVE_TERMIO_H],[.]) AH_TEMPLATE([HAVE_TERMIOS_H],[.]) AH_TEMPLATE([HAVE_TIME_H],[.]) +AH_TEMPLATE([HAVE_DLFCN_H],[.]) AH_TEMPLATE([HAVE_SYS_AUDIOIO_H],[.]) AH_TEMPLATE([HAVE_SYS_IOCTL_H],[.]) @@ -313,11 +123,6 @@ AH_TEMPLATE([HAVE_SYS_STAT_H],[.]) AH_TEMPLATE([HAVE_SYS_TIME_H],[.]) AH_TEMPLATE([HAVE_SYS_TYPES_H],[.]) -AH_TEMPLATE([HAVE_THREAD_H],[.]) -AH_TEMPLATE([HAVE_PTHREAD_H],[.]) -AH_TEMPLATE([HAVE_SYNCH_H],[.]) -AH_TEMPLATE([HAVE_SEMAPHORE_H],[.]) - AH_TEMPLATE([HAVE_AIO_H],[.]) AH_TEMPLATE([HAVE_DEV_AUDIO],[Define to 1 if your system has device /dev/audio]) @@ -353,6 +158,7 @@ bc_include_stdlib_h= bc_include_malloc_h= bc_include_string_h= bc_include_unistd_h= +bc_include_dlfcn_h= if test "$ac_cv_header_stdio_h" = yes; then bc_include_stdio_h="#include " fi @@ -374,48 +180,20 @@ fi if test "$ac_cv_header_unistd_h" = yes; then bc_include_unistd_h="#include " fi +if test "$ac_cv_header_dlfcn_h" = yes; then + bc_include_dlfcn_h="#include " +fi AC_SUBST(INCLUDE_STDIO_H,$bc_include_stdio_h) AC_SUBST(INCLUDE_STDLIB_H,$bc_include_stdlib_h) AC_SUBST(INCLUDE_MALLOC_H,$bc_include_malloc_h) AC_SUBST(INCLUDE_STRING_H,$bc_include_string_h) AC_SUBST(INCLUDE_UNISTD_H,$bc_include_unistd_h) +AC_SUBST(INCLUDE_DLFCN_H,$bc_include_dlfcn_h) -if test "$ac_enable_threads" = yes; then - AC_CHECK_HEADERS([thread.h pthread.h synch.h semaphore.h]) -fi +BEECRYPT_DLFCN +BEECRYPT_MULTITHREAD # Checks for libraries. -bc_include_synch_h= -bc_include_pthread_h= -bc_typedef_bc_lock_t= -if test "$ac_enable_threads" = yes; then - if test "$ac_cv_header_thread_h" = yes -a "$ac_cv_header_synch_h" = yes; then - AC_SEARCH_LIBS([mutex_lock],[thread],[ - AC_DEFINE([ENABLE_THREADS],1) - bc_include_synch_h="#include " - bc_typedef_bc_lock_t="typedef mutex_t bc_lock_t;" - ]) - elif test "$ac_cv_header_pthread_h" = yes; then - AC_SEARCH_LIBS([pthread_mutex_lock],[pthread],[ - AC_DEFINE([ENABLE_THREADS],1) - bc_include_pthread_h="#include " - bc_typedef_bc_lock_t="typedef pthread_mutex_t bc_lock_t;" - # On most systems this tests will say 'none required', but that doesn't - # mean that the linked code will work correctly! - case $target_os in - linux* | solaris* ) - LIBS="-lpthread $LIBS" - ;; - esac - ]) - else - AC_MSG_WARN([Don't know which thread library to check for]) - fi -fi -AC_SUBST(INCLUDE_SYNCH_H,$bc_include_synch_h) -AC_SUBST(INCLUDE_PTHREAD_H,$bc_include_pthread_h) -AC_SUBST(TYPEDEF_BC_LOCK_T,$bc_typedef_bc_lock_t) - if test "$ac_enable_aio" = yes; then BEECRYPT_WORKING_AIO if test "$bc_cv_aio_works" = yes; then @@ -450,9 +228,43 @@ AC_CHECK_FUNCS([memset memcmp memmove strcspn strerror strspn]) AH_TEMPLATE([HAVE_GETHRTIME],[.]) AH_TEMPLATE([HAVE_GETTIMEOFDAY],[.]) if test "$ac_cv_header_sys_time_h" = yes; then - AC_CHECK_FUNCS([gethrtime gettimeofday]) + AC_CHECK_FUNCS([gethrtime]) + # gettimeofday detection fails on HP/UX! + AC_MSG_CHECKING([for gettimeofday]) + AC_TRY_LINK([#include ],[ + struct timeval dummy; + gettimeofday(&dummy, (void*) 0); + ],[ + AC_MSG_RESULT([yes]) + AC_DEFINE([HAVE_GETTIMEOFDAY],1) + ac_cv_func_gettimeofday=yes + ],[ + AC_MSG_RESULT([no]) + AC_DEFINE([HAVE_GETTIMEOFDAY],0) + ac_cv_func_gettimeofday=no + ]) fi +# Predefines and checks for C++ API support +AH_TEMPLATE([CPPGLUE],[Define to 1 if you want to include the C++ code]) + +if test "$ac_with_cplusplus" = yes; then + AC_MSG_CHECKING([for IBM's ICU library]) + AC_TRY_LINK([#include ],[ + ],[ + AC_MSG_RESULT([yes]) + ],[ + AC_MSG_RESULT([no]) + AC_MSG_WARN([disabling cplusplus]) + ac_with_cplusplus=no + ]) +fi + +if test "$ac_with_cplusplus" = yes ; then + AC_DEFINE([CPPGLUE],1) +fi + + # Predefines and checks for Java API support AH_TEMPLATE([JAVAGLUE],[Define to 1 if you want to include the Java code]) @@ -524,6 +336,8 @@ EOF cygwin*) ac_cv_java_include="-I$java_include -I$java_include/win32" ;; darwin*) ;; + hpux*) + ac_cv_java_include="-I$java_include -I$java_include/hpux" ;; linux*) ac_cv_java_include="-I$java_include -I$java_include/linux" ;; osf*) @@ -559,8 +373,34 @@ fi if test "$ac_with_java" = yes ; then AC_DEFINE([JAVAGLUE],1) + AC_SUBST(JAVAINC,$ac_cv_java_include) +fi + + +# Predefines and checks for Python API support +AH_TEMPLATE([PYTHONGLUE],[Define to 1 if you want to include the Python code]) + +if test "$ac_with_python" = yes ; then + AC_CHECK_PROG(ac_cv_have_python, python, yes, no) + if test "$ac_cv_have_python" = yes; then + AC_CACHE_CHECK([for python headers], ac_cv_python_include, [ + ac_cv_python_include="-I`python -c 'import distutils.sysconfig; print distutils.sysconfig.get_python_inc()'`" + ]) + AC_CACHE_CHECK([for python libraries], ac_cv_python_libdir, [ + ac_cv_python_libdir="`python -c 'import distutils.sysconfig; print distutils.sysconfig.get_python_lib()'`" + ]) + else + ac_with_python=no + fi +fi + +if test "$ac_with_python" = yes; then + AC_DEFINE([PYTHONGLUE],1) + AC_SUBST(PYTHONINC,$ac_cv_python_include) + AC_SUBST(PYTHONLIB,$ac_cv_python_libdir) fi + # Checks for entropy sources. AS_MESSAGE(checking for specific entropy devices...) case $target_os in @@ -669,9 +509,12 @@ if test "$ac_enable_debug" != yes; then m68k) CPPFLAGS="$CPPFLAGS -DOPTIMIZE_M68K" ;; - pentium | pentium-mmx) + pentium) CPPFLAGS="$CPPFLAGS -DOPTIMIZE_I586" ;; + pentium-mmx) + CPPFLAGS="$CPPFLAGS -DOPTIMIZE_I586 -DOPTIMIZE_MMX" + ;; pentiumpro) CPPFLAGS="$CPPFLAGS -DOPTIMIZE_I686" ;; @@ -682,7 +525,7 @@ if test "$ac_enable_debug" != yes; then CPPFLAGS="$CPPFLAGS -DOPTIMIZE_I686 -DOPTIMIZE_MMX -DOPTIMIZE_SSE" ;; pentium4) - CPPFLAGS="$CPPFLAGS -DOPTIMIZE_I686 -DOPTIMIZE_MMX -DOPTIMIZE_SSE -DOPTIMIZE_SSE2" + CPPFLAGS="$CPPFLAGS -DOPTIMIZE_I686 -DOPTIMIZE_MMX -DOPTIMIZE_SSE -DOPTIMIZE_SSE2" ;; powerpc) CPPFLAGS="$CPPFLAGS -DOPTIMIZE_POWERPC" @@ -728,22 +571,26 @@ BEECRYPT_ASM_SOURCES BEECRYPT_INT_TYPES BEECRYPT_CPU_BITS -if test "$ac_with_java" = yes ; then - CFLAGS="$CFLAGS $ac_cv_java_include" -fi +MAYBE_SUB= +MAYBE_LTLIB= -MAYBE_OPT= +if test "$ac_with_cplusplus" = yes; then + MAYBE_SUB="$MAYBE_SUB c++" + MAYBE_LTLIB="$MAYBE_LTLIB libbeecrypt_cxx.la" +fi if test "$ac_with_java" = yes; then - MAYBE_OPT="$MAYBE_OPT java" + MAYBE_SUB="$MAYBE_SUB java" + MAYBE_LTLIB="$MAYBE_LTLIB libbeecrypt_java.la" fi if test "$ac_with_python" = yes; then - MAYBE_OPT="$MAYBE_OPT python" + MAYBE_SUB="$MAYBE_SUB python" fi -AC_SUBST([MAYBE_OPT]) - +AC_SUBST([MAYBE_SUB]) +AC_SUBST([MAYBE_LTLIB]) + # Check where to install the libraries bc_libalt= case $target_os in @@ -751,22 +598,47 @@ linux*) case $bc_target_arch in alpha* | powerpc64 | s390x | x86_64) bc_libalt="64" - ;; - esac + ;; + esac ;; esac AC_SUBST(LIBALT,$bc_libalt) # Generate output files. -AC_CONFIG_FILES([Makefile - Doxyfile - beecrypt.gnu.h - config.m4 - docs/Makefile - gas/Makefile - java/Makefile - masm/Makefile - python/Makefile - python/test/Makefile - tests/Makefile]) +AC_CONFIG_FILES([ + Makefile + Doxyfile + config.m4 + c++/Makefile + c++/beeyond/Makefile + c++/crypto/Makefile + c++/crypto/interfaces/Makefile + c++/crypto/spec/Makefile + c++/io/Makefile + c++/lang/Makefile + c++/provider/Makefile + c++/security/Makefile + c++/security/cert/Makefile + c++/security/interfaces/Makefile + c++/security/spec/Makefile + c++/util/Makefile + docs/Makefile + gas/Makefile + java/Makefile + masm/Makefile + python/Makefile + python/test/Makefile + tests/Makefile + ]) +AC_CONFIG_FILES([gnu.h],[ + if test $srcdir != "."; then + cp gnu.h $ac_top_srcdir/gnu.h + fi + ]) +AC_CONFIG_COMMANDS_POST([ + if test -h "beecrypt"; then + rm -f beecrypt + fi + $LN_S $srcdir beecrypt + ]) AC_OUTPUT diff --git a/beecrypt/cppglue.cxx b/beecrypt/cppglue.cxx new file mode 100644 index 0000000..9a62617 --- /dev/null +++ b/beecrypt/cppglue.cxx @@ -0,0 +1,296 @@ +/* + * Copyright (c) 2004 Bob Deblier + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define BEECRYPT_DLL_EXPORT + +#if HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/beecrypt.h" +#include "beecrypt/mpnumber.h" +#include "beecrypt/mpbarrett.h" +#include "beecrypt/dldp.h" +#include "beecrypt/dlkp.h" +#include "beecrypt/dlpk.h" +#include "beecrypt/rsakp.h" +#include "beecrypt/rsapk.h" + +#include + +#if CPPGLUE + +mpnumber::mpnumber() +{ + mpnzero(this); +} + +mpnumber::mpnumber(unsigned int value) +{ + mpnsize(this, 1); + mpnsetw(this, value); +} + +mpnumber::mpnumber(const mpnumber& copy) +{ + mpnzero(this); + mpncopy(this, ©); +} + +mpnumber::~mpnumber() +{ + mpnfree(this); +} + +const mpnumber& mpnumber::operator=(const mpnumber& copy) +{ + mpncopy(this, ©); + return *this; +} + +bool mpnumber::operator==(const mpnumber& cmp) +{ + return mpeqx(size, data, cmp.size, cmp.data); +} + +bool mpnumber::operator!=(const mpnumber& cmp) +{ + return mpnex(size, data, cmp.size, cmp.data); +} + +void mpnumber::wipe() +{ + mpnwipe(this); +} + +size_t mpnumber::bitlength() const +{ + return mpbits(size, data); +} + +std::ostream& operator<<(std::ostream& stream, const mpnumber& n) +{ + if (n.size) + { + stream << std::hex << std::setfill('0') << n.data[0]; + for (size_t i = 1; i < n.size; i++) + stream << std::setw(MP_WNIBBLES) << n.data[i]; + } + + return stream; +} + +/* +std::istream& operator>>(std:istream& stream, mpnumber& n) +{ +} +*/ + +mpbarrett::mpbarrett() +{ + mpbzero(this); +} + +mpbarrett::mpbarrett(const mpbarrett& copy) +{ + mpbzero(this); + mpbcopy(this, ©); +} + +mpbarrett::~mpbarrett() +{ + mpbfree(this); +} + +const mpbarrett& mpbarrett::operator=(const mpbarrett& copy) +{ + mpbcopy(this, ©); + return *this; +} + +bool mpbarrett::operator==(const mpbarrett& cmp) +{ + return mpeqx(size, modl, cmp.size, cmp.modl); +} + +bool mpbarrett::operator!=(const mpbarrett& cmp) +{ + return mpnex(size, modl, cmp.size, cmp.modl); +} + +void mpbarrett::wipe() +{ + mpbwipe(this); +} + +size_t mpbarrett::bitlength() const +{ + return mpbits(size, modl); +} + +std::ostream& operator<<(std::ostream& stream, const mpbarrett& b) +{ + stream << std::hex << std::setfill('0'); + + for (size_t i = 0; i < b.size; i++) + stream << std::setw(MP_WNIBBLES) << b.modl[i]; + + return stream; +} + +dldp_p::dldp_p() +{ + dldp_pInit(this); +} + +dldp_p::dldp_p(const dldp_p& copy) +{ + dldp_pInit(this); + dldp_pCopy(this, ©); +} + +dldp_p::~dldp_p() +{ + dldp_pFree(this); +} + +dlkp_p::dlkp_p() +{ + dlkp_pInit(this); +} + +dlkp_p::dlkp_p(const dlkp_p& copy) +{ + dlkp_pInit(this); + dlkp_pCopy(this, ©); +} + +dlkp_p::~dlkp_p() +{ + dlkp_pFree(this); +} + +dlpk_p::dlpk_p() +{ + dlpk_pInit(this); +} + +dlpk_p::dlpk_p(const dlpk_p& copy) +{ + dlpk_pInit(this); + dlpk_pCopy(this, ©); +} + +dlpk_p::~dlpk_p() +{ + dlpk_pFree(this); +} + +rsakp::rsakp() +{ + rsakpInit(this); +} + +rsakp::rsakp(const rsakp& copy) +{ + rsakpInit(this); + rsakpCopy(this, ©); +} + +rsakp::~rsakp() +{ + rsakpFree(this); +} + +rsapk::rsapk() +{ + rsapkInit(this); +} + +rsapk::rsapk(const rsapk& copy) +{ + rsapkInit(this); + rsapkCopy(this, ©); +} + +rsapk::~rsapk() +{ + rsapkFree(this); +} + +blockCipherContext::blockCipherContext() +{ + blockCipherContextInit(this, blockCipherDefault()); +} + +blockCipherContext::blockCipherContext(const blockCipher* b) +{ + blockCipherContextInit(this, b); +} + +blockCipherContext::~blockCipherContext() +{ + blockCipherContextFree(this); +} + +hashFunctionContext::hashFunctionContext() +{ + hashFunctionContextInit(this, hashFunctionDefault()); +} + +hashFunctionContext::hashFunctionContext(const hashFunction* h) +{ + hashFunctionContextInit(this, h); +} + +hashFunctionContext::~hashFunctionContext() +{ + hashFunctionContextFree(this); +} + +keyedHashFunctionContext::keyedHashFunctionContext() +{ + keyedHashFunctionContextInit(this, keyedHashFunctionDefault()); +} + +keyedHashFunctionContext::keyedHashFunctionContext(const keyedHashFunction* k) +{ + keyedHashFunctionContextInit(this, k); +} + +keyedHashFunctionContext::~keyedHashFunctionContext() +{ + keyedHashFunctionContextFree(this); +} + +randomGeneratorContext::randomGeneratorContext() +{ + randomGeneratorContextInit(this, randomGeneratorDefault()); +} + +randomGeneratorContext::randomGeneratorContext(const randomGenerator* rng) +{ + randomGeneratorContextInit(this, rng); +} + +randomGeneratorContext::~randomGeneratorContext() +{ + randomGeneratorContextFree(this); +} + +#endif diff --git a/beecrypt/debug.h b/beecrypt/debug.h deleted file mode 100644 index 19376c0..0000000 --- a/beecrypt/debug.h +++ /dev/null @@ -1,13 +0,0 @@ -/** - * To be included after all other includes. - */ -#ifndef H_DEBUG -#define H_DEBUG - -#include - -#ifdef DMALLOC -#include -#endif - -#endif /* H_DEBUG */ diff --git a/beecrypt/dhaes.c b/beecrypt/dhaes.c index 6c415a2..994cd6f 100644 --- a/beecrypt/dhaes.c +++ b/beecrypt/dhaes.c @@ -1,4 +1,3 @@ -/*@-compdef@*/ /* * Copyright (c) 2000, 2001, 2002 Virtual Unlimited, B.V. * @@ -20,38 +19,40 @@ /*!\file dhaes.c * \brief DHAES encryption scheme. - * - * This code implements the encryption scheme from the paper: - * - * "DHAES: An Encryption Scheme Based on the Diffie-Hellman Problem" - * Michel Abdalla, Mihir Bellare, Phillip Rogaway - * September 1998 - * + * \author Bob Deblier + * \ingroup DL_m DL_dh_m + */ + +#define BEECRYPT_DLL_EXPORT + +#if HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/dhaes.h" +#include "beecrypt/dlsvdp-dh.h" +#include "beecrypt/blockmode.h" +#include "beecrypt/blockpad.h" + +/* * Good combinations will be: * - * - For 64-bit encryption: - * - DHAES(MD5, Blowfish, HMAC-MD5) <- best candidate - * - DHAES(MD5, Blowfish, HMAC-SHA-1) - * - DHAES(MD5, Blowfish, HMAC-SHA-256) + * For 64-bit encryption: + * DHAES(MD5, Blowfish, HMAC-MD5) <- best candidate + * DHAES(MD5, Blowfish, HMAC-SHA-1) + * DHAES(MD5, Blowfish, HMAC-SHA-256) * - * - For 96-bit encryption with 64-bit mac: - * - DHAES(SHA-1, Blowfish, HMAC-MD5, 96) - * - DHAES(SHA-1, Blowfish, HMAC-SHA-1, 96) <- best candidate - * - DHAES(SHA-1, Blowfish, HMAC-SHA-256, 96) <- best candidate + * For 96-bit encryption with 64-bit mac: + * DHAES(SHA-1, Blowfish, HMAC-MD5, 96) + * DHAES(SHA-1, Blowfish, HMAC-SHA-1, 96) <- best candidate + * DHAES(SHA-1, Blowfish, HMAC-SHA-256, 96) <- best candidate * - * - For 128-bit encryption: - * - DHAES(SHA-256, Blowfish, HMAC-MD5) - * - DHAES(SHA-256, Blowfish, HMAC-SHA-1) - * - DHAES(SHA-256, Blowfish, HMAC-SHA-256) + * For 128-bit encryption: + * DHAES(SHA-256, Blowfish, HMAC-MD5) + * DHAES(SHA-256, Blowfish, HMAC-SHA-1) + * DHAES(SHA-256, Blowfish, HMAC-SHA-256) */ -#include "system.h" -#include "dhaes.h" -#include "dlsvdp-dh.h" -#include "blockmode.h" -#include "blockpad.h" -#include "debug.h" - int dhaes_pUsable(const dhaes_pParameters* params) { size_t keybits = (params->hash->digestsize << 3); /* digestsize in bytes times 8 bits */ @@ -84,7 +85,7 @@ int dhaes_pUsable(const dhaes_pParameters* params) /* test if keybits length is appropriate for mac */ if ((mackeybits < params->mac->keybitsmin) || - (((unsigned)params->mackeybits) > params->mac->keybitsmax)) + (params->mackeybits > params->mac->keybitsmax)) return 0; if (((mackeybits - params->mac->keybitsmin) % params->mac->keybitsinc) != 0) @@ -116,13 +117,12 @@ int dhaes_pContextInit(dhaes_pContext* ctxt, const dhaes_pParameters* params) if (!dhaes_pUsable(params)) return -1; - (void) dldp_pInit(&ctxt->param); - (void) dldp_pCopy(&ctxt->param, params->param); + dldp_pInit(&ctxt->param); + dldp_pCopy(&ctxt->param, params->param); mpnzero(&ctxt->pub); mpnzero(&ctxt->pri); - /*@-modobserver@*/ if (hashFunctionContextInit(&ctxt->hash, params->hash)) return -1; @@ -131,7 +131,6 @@ int dhaes_pContextInit(dhaes_pContext* ctxt, const dhaes_pParameters* params) if (keyedHashFunctionContextInit(&ctxt->mac, params->mac)) return -1; - /*@=modobserver@*/ ctxt->cipherkeybits = params->cipherkeybits; ctxt->mackeybits = params->mackeybits; @@ -161,12 +160,11 @@ int dhaes_pContextInitEncrypt(dhaes_pContext* ctxt, const dhaes_pParameters* par int dhaes_pContextFree(dhaes_pContext* ctxt) { - (void) dldp_pFree(&ctxt->param); + dldp_pFree(&ctxt->param); mpnfree(&ctxt->pub); mpnfree(&ctxt->pri); - /*@-mustfree -modobserver @*/ /* ctxt is OK */ if (hashFunctionContextFree(&ctxt->hash)) return -1; @@ -177,13 +175,9 @@ int dhaes_pContextFree(dhaes_pContext* ctxt) return -1; return 0; - /*@=mustfree =modobserver @*/ } -/** - */ -static int dhaes_pContextSetup(dhaes_pContext* ctxt, const mpnumber* privkey, const mpnumber* pubkey, const mpnumber* message, cipherOperation op) - /*@modifies ctxt @*/ +static int dhaes_pContextSetup(dhaes_pContext* ctxt, const mpnumber* private, const mpnumber* public, const mpnumber* message, cipherOperation op) { register int rc; @@ -196,7 +190,7 @@ static int dhaes_pContextSetup(dhaes_pContext* ctxt, const mpnumber* privkey, co /* compute the shared secret, Diffie-Hellman style */ mpnzero(&secret); - if (dlsvdp_pDHSecret(&ctxt->param, privkey, pubkey, &secret)) + if (dlsvdp_pDHSecret(&ctxt->param, private, public, &secret)) { mpnfree(&secret); free(digest); @@ -204,10 +198,11 @@ static int dhaes_pContextSetup(dhaes_pContext* ctxt, const mpnumber* privkey, co } /* compute the hash of the message (ephemeral public) key and the shared secret */ - (void) hashFunctionContextReset (&ctxt->hash); - (void) hashFunctionContextUpdateMP(&ctxt->hash, message); - (void) hashFunctionContextUpdateMP(&ctxt->hash, &secret); - (void) hashFunctionContextDigest (&ctxt->hash, digest); + + hashFunctionContextReset (&ctxt->hash); + hashFunctionContextUpdateMP(&ctxt->hash, message); + hashFunctionContextUpdateMP(&ctxt->hash, &secret); + hashFunctionContextDigest (&ctxt->hash, digest); /* we don't need the secret anymore */ mpnwipe(&secret); @@ -224,11 +219,10 @@ static int dhaes_pContextSetup(dhaes_pContext* ctxt, const mpnumber* privkey, co * size requirements. */ - /*@-usedef@*/ /* LCL: digest already set */ if (ctxt->hash.algo->digestsize > 0) { byte* mackey = digest; - byte* cipherkey = digest + ((unsigned)(ctxt->mackeybits + 7) >> 3); + byte* cipherkey = digest + ((ctxt->mackeybits + 7) >> 3); if ((rc = keyedHashFunctionContextSetup(&ctxt->mac, mackey, ctxt->mackeybits))) goto setup_end; @@ -240,16 +234,13 @@ static int dhaes_pContextSetup(dhaes_pContext* ctxt, const mpnumber* privkey, co } else rc = -1; - /*@=usedef@*/ setup_end: /* wipe digest for good measure */ memset(digest, 0, ctxt->hash.algo->digestsize); free(digest); - /*@-mustfree@*/ /* {secret,digest}.data are OK */ return rc; - /*@=mustfree@*/ } memchunk* dhaes_pContextEncrypt(dhaes_pContext* ctxt, mpnumber* ephemeralPublicKey, mpnumber* mac, const memchunk* cleartext, randomGeneratorContext* rng) @@ -261,7 +252,7 @@ memchunk* dhaes_pContextEncrypt(dhaes_pContext* ctxt, mpnumber* ephemeralPublicK /* make the ephemeral keypair */ mpnzero(&ephemeralPrivateKey); - (void) dldp_pPair(&ctxt->param, rng, &ephemeralPrivateKey, ephemeralPublicKey); + dldp_pPair(&ctxt->param, rng, &ephemeralPrivateKey, ephemeralPublicKey); /* Setup the key and initialize the mac and the blockcipher */ if (dhaes_pContextSetup(ctxt, &ephemeralPrivateKey, &ctxt->pub, ephemeralPublicKey, ENCRYPT)) @@ -269,8 +260,6 @@ memchunk* dhaes_pContextEncrypt(dhaes_pContext* ctxt, mpnumber* ephemeralPublicK /* add pkcs-5 padding */ paddedtext = pkcs5PadCopy(ctxt->cipher.algo->blocksize, cleartext); - if (paddedtext == (memchunk*) 0) - goto encrypt_end; /* encrypt the memchunk in CBC mode */ if (blockEncryptCBC(ctxt->cipher.algo, ctxt->cipher.param, (uint32_t*) paddedtext->data, (const uint32_t*) paddedtext->data, paddedtext->size / ctxt->cipher.algo->blocksize)) @@ -301,9 +290,7 @@ encrypt_end: mpnwipe(&ephemeralPrivateKey); mpnfree(&ephemeralPrivateKey); - /*@-mustfree@*/ /* ephemeralPrivateKey.data is OK */ return ciphertext; - /*@=mustfree@*/ } memchunk* dhaes_pContextDecrypt(dhaes_pContext* ctxt, const mpnumber* ephemeralPublicKey, const mpnumber* mac, const memchunk* ciphertext) @@ -323,15 +310,13 @@ memchunk* dhaes_pContextDecrypt(dhaes_pContext* ctxt, const mpnumber* ephemeralP goto decrypt_end; /* decrypt the memchunk with CBC mode */ - paddedtext = (memchunk*) calloc(1, sizeof(*paddedtext)); + paddedtext = (memchunk*) calloc(1, sizeof(memchunk)); if (paddedtext == (memchunk*) 0) goto decrypt_end; paddedtext->size = ciphertext->size; - /*@-mustfree@*/ /* paddedtext->data is OK */ paddedtext->data = (byte*) malloc(ciphertext->size); - /*@=mustfree@*/ if (paddedtext->data == (byte*) 0) { @@ -357,8 +342,5 @@ memchunk* dhaes_pContextDecrypt(dhaes_pContext* ctxt, const mpnumber* ephemeralP decrypt_end: - /*@-usereleased@*/ /* LCL: cleartext released??? */ return cleartext; - /*@=usereleased@*/ } -/*@=compdef@*/ diff --git a/beecrypt/dhaes.h b/beecrypt/dhaes.h index 5ae3683..3816d99 100644 --- a/beecrypt/dhaes.h +++ b/beecrypt/dhaes.h @@ -33,85 +33,51 @@ #ifndef _DHAES_H #define _DHAES_H -#include "beecrypt.h" -#include "dldp.h" +#include "beecrypt/beecrypt.h" +#include "beecrypt/dldp.h" -/** - */ typedef struct { - const dldp_p* param; - const hashFunction* hash; - const blockCipher* cipher; + const dldp_p* param; + const hashFunction* hash; + const blockCipher* cipher; const keyedHashFunction* mac; - size_t cipherkeybits; - size_t mackeybits; + size_t cipherkeybits; + size_t mackeybits; } dhaes_pParameters; -/** - */ typedef struct { - dldp_p param; - mpnumber pub; - mpnumber pri; - hashFunctionContext hash; - blockCipherContext cipher; + dldp_p param; + mpnumber pub; + mpnumber pri; + hashFunctionContext hash; + blockCipherContext cipher; keyedHashFunctionContext mac; - size_t cipherkeybits; - size_t mackeybits; + size_t cipherkeybits; + size_t mackeybits; } dhaes_pContext; #ifdef __cplusplus extern "C" { #endif -/** - */ -/*@-exportlocal@*/ BEECRYPTAPI -int dhaes_pUsable(const dhaes_pParameters* params) - /*@*/; -/*@=exportlocal@*/ +int dhaes_pUsable(const dhaes_pParameters*); -/** - */ -/*@-exportlocal@*/ BEECRYPTAPI -int dhaes_pContextInit (/*@special@*/ dhaes_pContext* ctxt, const dhaes_pParameters* params) - /*@defines ctxt->hash, ctxt->cipher, ctxt->mac @*/ - /*@modifies ctxt @*/; -/*@=exportlocal@*/ - -/** - */ -BEECRYPTAPI /*@unused@*/ -int dhaes_pContextInitDecrypt(dhaes_pContext* ctxt, const dhaes_pParameters* params, const mpnumber* pri) - /*@modifies ctxt @*/; - -/** - */ -BEECRYPTAPI /*@unused@*/ -int dhaes_pContextInitEncrypt(dhaes_pContext* ctxt, const dhaes_pParameters* params, const mpnumber* pub) - /*@modifies ctxt @*/; - -/** - */ -BEECRYPTAPI /*@unused@*/ -int dhaes_pContextFree (/*@only@*/ dhaes_pContext* ctxt) - /*@modifies ctxt @*/; - -/** - */ -BEECRYPTAPI /*@only@*/ /*@null@*/ /*@unused@*/ -memchunk* dhaes_pContextEncrypt(dhaes_pContext* ctxt, mpnumber* ephemeralPublicKey, mpnumber* mac, const memchunk* cleartext, randomGeneratorContext* rng) - /*@modifies ctxt, ephemeralPublicKey, mac, rng @*/; +int dhaes_pContextInit (dhaes_pContext*, const dhaes_pParameters*); +BEECRYPTAPI +int dhaes_pContextInitDecrypt(dhaes_pContext*, const dhaes_pParameters*, const mpnumber*); +BEECRYPTAPI +int dhaes_pContextInitEncrypt(dhaes_pContext*, const dhaes_pParameters*, const mpnumber*); +BEECRYPTAPI +int dhaes_pContextFree (dhaes_pContext*); -/** - */ -BEECRYPTAPI /*@only@*/ /*@null@*/ /*@unused@*/ -memchunk* dhaes_pContextDecrypt(dhaes_pContext* ctxt, const mpnumber* ephemeralPublicKey, const mpnumber* mac, const memchunk* ciphertext) - /*@modifies ctxt @*/; +BEECRYPTAPI +memchunk* dhaes_pContextEncrypt(dhaes_pContext*, mpnumber*, mpnumber*, const memchunk*, randomGeneratorContext*); +BEECRYPTAPI +memchunk* dhaes_pContextDecrypt(dhaes_pContext*, const mpnumber*, const mpnumber*, const memchunk*); #ifdef __cplusplus } diff --git a/beecrypt/dldp.c b/beecrypt/dldp.c index 839595b..51f32e6 100644 --- a/beecrypt/dldp.c +++ b/beecrypt/dldp.c @@ -23,25 +23,21 @@ * \ingroup DL_m */ -#include "system.h" -#include "dldp.h" -#include "mp.h" -#include "mpprime.h" -#include "debug.h" +#define BEECRYPT_DLL_EXPORT -/*!\addtogroup DL_m - * \{ - */ +#if HAVE_CONFIG_H +# include "config.h" +#endif -/** - */ -static int dldp_pgoqGenerator_w(dldp_p* dp, randomGeneratorContext* rgc, /*@out@*/ mpw* wksp) - /*@modifies dp->g, wksp @*/; +#include "beecrypt/dldp.h" +#include "beecrypt/mp.h" +#include "beecrypt/mpprime.h" -/** +/*!\addtogroup DL_m + * \{ */ -static int dldp_pgonGenerator_w(dldp_p* dp, randomGeneratorContext* rgc, /*@out@*/ mpw* wksp) - /*@modifies dp->g, wksp @*/; +static int dldp_pgoqGenerator_w(dldp_p*, randomGeneratorContext*, mpw*); +static int dldp_pgonGenerator_w(dldp_p*, randomGeneratorContext*, mpw*); int dldp_pPrivate(const dldp_p* dp, randomGeneratorContext* rgc, mpnumber* x) { @@ -56,6 +52,19 @@ int dldp_pPrivate(const dldp_p* dp, randomGeneratorContext* rgc, mpnumber* x) return 0; } +int dldp_pPrivate_s(const dldp_p* dp, randomGeneratorContext* rgc, mpnumber* x, size_t xbits) +{ + /* + * Note: the private key is randomly selected smaller than q with xbits < mpbits(q) + * + */ + + mpbnrnd(&dp->q, rgc, x); + mpntrbits(x, xbits); + + return 0; +} + int dldp_pPublic(const dldp_p* dp, const mpnumber* x, mpnumber* y) { /* @@ -79,6 +88,15 @@ int dldp_pPair(const dldp_p* dp, randomGeneratorContext* rgc, mpnumber* x, mpnum return 0; } +int dldp_pPair_s(const dldp_p* dp, randomGeneratorContext* rgc, mpnumber* x, mpnumber* y, size_t xbits) +{ + mpbnrnd(&dp->q, rgc, x); + mpntrbits(x, xbits); + mpbnpowmod(&dp->p, &dp->g, x, y); + + return 0; +} + int dldp_pEqual(const dldp_p* a, const dldp_p* b) { return mpeqx(a->p.size, a->p.modl, b->p.size, b->p.modl) && @@ -86,14 +104,14 @@ int dldp_pEqual(const dldp_p* a, const dldp_p* b) mpeqx(a->g.size, a->g.data, b->g.size, b->g.data); } -/** +/* * needs to make workspace of 8*size+2 */ -static int dldp_pValidate(const dldp_p* dp, randomGeneratorContext* rgc) - /*@*/ +int dldp_pValidate(const dldp_p* dp, randomGeneratorContext* rgc) { register size_t size = dp->p.size; - register mpw* temp = (mpw*) malloc((8*size+2) * sizeof(*temp)); + + register mpw* temp = (mpw*) malloc((8*size+2) * sizeof(mpw)); if (temp) { @@ -150,13 +168,11 @@ int dldp_pInit(dldp_p* dp) int dldp_pFree(dldp_p* dp) { - /*@-usedef -compdef@*/ mpbfree(&dp->p); mpbfree(&dp->q); mpnfree(&dp->g); mpnfree(&dp->r); mpbfree(&dp->n); - /*@=usedef =compdef@*/ return 0; } @@ -178,7 +194,7 @@ int dldp_pgoqMake(dldp_p* dp, randomGeneratorContext* rgc, size_t pbits, size_t * Generate parameters as described by IEEE P1363, A.16.1 */ register size_t psize = MP_BITS_TO_WORDS(pbits + MP_WBITS - 1); - register mpw* temp = (mpw*) malloc((8*psize+2) * sizeof(*temp)); + register mpw* temp = (mpw*) malloc((8*psize+2) * sizeof(mpw)); if (temp) { @@ -194,7 +210,7 @@ int dldp_pgoqMake(dldp_p* dp, randomGeneratorContext* rgc, size_t pbits, size_t /* clear g */ mpnzero(&dp->g); - (void) dldp_pgoqGenerator_w(dp, rgc, temp); + dldp_pgoqGenerator_w(dp, rgc, temp); free(temp); @@ -212,7 +228,7 @@ int dldp_pgoqMakeSafe(dldp_p* dp, randomGeneratorContext* rgc, size_t bits) */ register size_t size = MP_BITS_TO_WORDS(bits + MP_WBITS - 1); - register mpw* temp = (mpw*) malloc((8*size+2) * sizeof(*temp)); + register mpw* temp = (mpw*) malloc((8*size+2) * sizeof(mpw)); if (temp) { @@ -230,7 +246,7 @@ int dldp_pgoqMakeSafe(dldp_p* dp, randomGeneratorContext* rgc, size_t bits) /* clear n */ mpbzero(&dp->n); - (void) dldp_pgoqGenerator_w(dp, rgc, temp); + dldp_pgoqGenerator_w(dp, rgc, temp); free(temp); @@ -269,11 +285,11 @@ int dldp_pgoqGenerator_w(dldp_p* dp, randomGeneratorContext* rgc, mpw* wksp) int dldp_pgoqGenerator(dldp_p* dp, randomGeneratorContext* rgc) { register size_t size = dp->p.size; - register mpw* temp = (mpw*) malloc((4*size+2) * sizeof(*temp)); + register mpw* temp = (mpw*) malloc((4*size+2)*sizeof(mpw)); if (temp) { - (void) dldp_pgoqGenerator_w(dp, rgc, temp); + dldp_pgoqGenerator_w(dp, rgc, temp); free(temp); @@ -282,7 +298,7 @@ int dldp_pgoqGenerator(dldp_p* dp, randomGeneratorContext* rgc) return -1; } -int dldp_pgoqValidate(const dldp_p* dp, randomGeneratorContext* rgc, /*@unused@*/ int cofactor) +int dldp_pgoqValidate(const dldp_p* dp, randomGeneratorContext* rgc, int cofactor) { register int rc = dldp_pValidate(dp, rgc); @@ -305,7 +321,7 @@ int dldp_pgonMake(dldp_p* dp, randomGeneratorContext* rgc, size_t pbits, size_t */ register size_t psize = MP_BITS_TO_WORDS(pbits + MP_WBITS - 1); - register mpw* temp = (mpw*) malloc((8*psize+2) * sizeof(*temp)); + register mpw* temp = (mpw*) malloc((8*psize+2) * sizeof(mpw)); if (temp) { @@ -319,7 +335,7 @@ int dldp_pgonMake(dldp_p* dp, randomGeneratorContext* rgc, size_t pbits, size_t mpbsubone(&dp->p, temp); mpbset(&dp->n, psize, temp); - (void) dldp_pgonGenerator_w(dp, rgc, temp); + dldp_pgonGenerator_w(dp, rgc, temp); free(temp); @@ -335,7 +351,7 @@ int dldp_pgonMakeSafe(dldp_p* dp, randomGeneratorContext* rgc, size_t pbits) */ register size_t psize = MP_BITS_TO_WORDS(pbits + MP_WBITS - 1); - register mpw* temp = (mpw*) malloc((8*psize+2) * sizeof(*temp)); + register mpw* temp = (mpw*) malloc((8*psize+2) * sizeof(mpw)); if (temp) { @@ -354,7 +370,7 @@ int dldp_pgonMakeSafe(dldp_p* dp, randomGeneratorContext* rgc, size_t pbits) /* set r = 2 */ mpnsetw(&dp->r, 2); - (void) dldp_pgonGenerator_w(dp, rgc, temp); + dldp_pgonGenerator_w(dp, rgc, temp); free(temp); @@ -431,11 +447,11 @@ int dldp_pgonGenerator_w(dldp_p* dp, randomGeneratorContext* rgc, mpw* wksp) int dldp_pgonGenerator(dldp_p* dp, randomGeneratorContext* rgc) { register size_t psize = dp->p.size; - register mpw* temp = (mpw*) malloc((8*psize+2) * sizeof(*temp)); + register mpw* temp = (mpw*) malloc((8*psize+2) * sizeof(mpw)); if (temp) { - (void) dldp_pgonGenerator_w(dp, rgc, temp); + dldp_pgonGenerator_w(dp, rgc, temp); free(temp); diff --git a/beecrypt/dldp.h b/beecrypt/dldp.h index 4c1f6cf..d19eefe 100644 --- a/beecrypt/dldp.h +++ b/beecrypt/dldp.h @@ -19,16 +19,16 @@ /*!\file dldp.h * \brief Discrete Logarithm domain parameters, headers. - * \author Bob Deblier + * \author Bob Deblier * \ingroup DL_m */ #ifndef _DLDP_H #define _DLDP_H -#include "mpbarrett.h" +#include "beecrypt/mpbarrett.h" -/** +/* * Discrete Logarithm Domain Parameters - Prime * * Standard definition where p = qr+1; in case where p=2q+1, r=2 @@ -43,127 +43,120 @@ * g is either a generator of a subgroup of order q, or a generator of order * n = (p-1) */ -typedef struct + +/*!\brief Discrete Logarithm Domain Parameters over a prime field. + * + * For the variables in this structure /f$p=qr+1/f$; if /f$p=2q+1 then r=2/f$. + * + * \ingroup DL_m + */ +#ifdef __cplusplus +struct BEECRYPTAPI dldp_p +#else +struct _dldp_p +#endif { + /*!\var p + * \brief The prime. + * + */ mpbarrett p; + /*!\var q + * \brief The cofactor. + * + * \f$q\f$ is a prime divisor of \f$p-1\f$. + */ mpbarrett q; - mpnumber r; - mpnumber g; + /*!\var r + * + * \f$p=qr+1\f$ + */ + mpnumber r; + /*!\var g + * \brief The generator. + * + * \f$g\f$ is either a generator of \f$\mathds{Z}^{*}_p\f$, or a generator + * of a cyclic subgroup \f$G\f$ of \f$\mathds{Z}^{*}_p\f$ of order \f$q\f$. + */ + mpnumber g; + /*!\var n + * + * \f$n=p-1=qr\f$ + */ mpbarrett n; -} dldp_p; +#ifdef __cplusplus + dldp_p(); + dldp_p(const dldp_p&); + ~dldp_p(); +#endif +}; + +#ifndef __cplusplus +typedef struct _dldp_p dldp_p; +#endif #ifdef __cplusplus extern "C" { #endif -/** +/* + * Functions for setting up and copying */ -BEECRYPTAPI -int dldp_pInit(dldp_p* dp) - /*@modifies dp->p, dp->q, dp->r, dp->g, dp->n @*/; -/** - */ BEECRYPTAPI -int dldp_pFree(/*@special@*/ dldp_p* dp) - /*@releases dp->p.modl, dp->q.modl, dp->n.modl @*/ - /*@modifies dp->p, dp->q, dp->r, dp->g, dp->n @*/; - -/** - */ +int dldp_pInit(dldp_p*); BEECRYPTAPI -int dldp_pCopy(dldp_p* dst, const dldp_p* src) - /*@modifies dst @*/; +int dldp_pFree(dldp_p*); +BEECRYPTAPI +int dldp_pCopy(dldp_p*, const dldp_p*); /* * Functions for generating keys */ -/** - */ -BEECRYPTAPI /*@unused@*/ -int dldp_pPrivate(const dldp_p* dp, randomGeneratorContext* rgc, mpnumber* x) - /*@modifies rgc, x @*/; - -/** - */ -BEECRYPTAPI /*@unused@*/ -int dldp_pPublic(const dldp_p* dp, const mpnumber* x, mpnumber* y) - /*@modifies y @*/; - -/** - */ BEECRYPTAPI -int dldp_pPair(const dldp_p* dp, randomGeneratorContext* rgc, mpnumber* x, mpnumber* y) - /*@modifies rgc, x, y @*/; +int dldp_pPrivate (const dldp_p*, randomGeneratorContext*, mpnumber*); +BEECRYPTAPI +int dldp_pPrivate_s(const dldp_p*, randomGeneratorContext*, mpnumber*, size_t); +BEECRYPTAPI +int dldp_pPublic (const dldp_p*, const mpnumber*, mpnumber*); +BEECRYPTAPI +int dldp_pPair (const dldp_p*, randomGeneratorContext*, mpnumber*, mpnumber*); +BEECRYPTAPI +int dldp_pPair_s (const dldp_p*, randomGeneratorContext*, mpnumber*, mpnumber*, size_t); /* * Function for comparing domain parameters */ - -/** - */ BEECRYPTAPI -int dldp_pEqual(const dldp_p* a, const dldp_p* b) - /*@*/; +int dldp_pEqual (const dldp_p*, const dldp_p*); /* * Functions for generating and validating dldp_pgoq variant domain parameters */ - -/** - */ -BEECRYPTAPI /*@unused@*/ -int dldp_pgoqMake(dldp_p* dp, randomGeneratorContext* rgc, size_t pbits, size_t qbits, int cofactor) - /*@modifies dp, rgc @*/; - -/** - */ -BEECRYPTAPI /*@unused@*/ -int dldp_pgoqMakeSafe(dldp_p* dp, randomGeneratorContext* rgc, size_t bits) - /*@modifies dp->p, dp->q, dp->r, dp->g, dp->n, rgc @*/; - -/** - */ -BEECRYPTAPI /*@unused@*/ -int dldp_pgoqGenerator(dldp_p* dp, randomGeneratorContext* rgc) - /*@modifies dp->p, dp->q, dp->r, dp->g, dp->n, rgc @*/; - -/** - */ -BEECRYPTAPI /*@unused@*/ -int dldp_pgoqValidate(const dldp_p*, randomGeneratorContext* rgc, int cofactor) - /*@modifies rgc @*/; +BEECRYPTAPI +int dldp_pgoqMake (dldp_p*, randomGeneratorContext*, size_t, size_t, int); +BEECRYPTAPI +int dldp_pgoqMakeSafe (dldp_p*, randomGeneratorContext*, size_t); +BEECRYPTAPI +int dldp_pgoqGenerator(dldp_p*, randomGeneratorContext*); +BEECRYPTAPI +int dldp_pgoqValidate (const dldp_p*, randomGeneratorContext*, int); /* * Functions for generating and validating dldp_pgon variant domain parameters */ -/** - */ -BEECRYPTAPI /*@unused@*/ -int dldp_pgonMake(dldp_p* dp, randomGeneratorContext* rgc, size_t pbits, size_t qbits) - /*@modifies dp->p, dp->q, dp->r, dp->g, dp->n, rgc @*/; - -/** - */ -BEECRYPTAPI /*@unused@*/ -int dldp_pgonMakeSafe(dldp_p* dp, randomGeneratorContext* rgc, size_t pbits) - /*@modifies dp->p, dp->q, dp->r, dp->g, dp->n, rgc @*/; - -/** - */ -BEECRYPTAPI /*@unused@*/ -int dldp_pgonGenerator(dldp_p* dp, randomGeneratorContext* rgc) - /*@modifies dp->p, dp->q, dp->r, dp->g, dp->n, rgc @*/; - -/** - */ -BEECRYPTAPI /*@unused@*/ -int dldp_pgonValidate(const dldp_p* dp, randomGeneratorContext* rgc) - /*@modifies rgc @*/; +BEECRYPTAPI +int dldp_pgonMake (dldp_p*, randomGeneratorContext*, size_t, size_t); +BEECRYPTAPI +int dldp_pgonMakeSafe (dldp_p*, randomGeneratorContext*, size_t); +BEECRYPTAPI +int dldp_pgonGenerator(dldp_p*, randomGeneratorContext*); +BEECRYPTAPI +int dldp_pgonValidate (const dldp_p*, randomGeneratorContext*); #ifdef __cplusplus } diff --git a/beecrypt/dlkp.c b/beecrypt/dlkp.c index 78f0b5c..65dc185 100644 --- a/beecrypt/dlkp.c +++ b/beecrypt/dlkp.c @@ -23,13 +23,13 @@ * \ingroup DL_m */ -#include "system.h" -#include "dlkp.h" -#include "debug.h" +#define BEECRYPT_DLL_EXPORT -/*!\addtogroup DL_m - * \{ - */ +#if HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/dlkp.h" int dlkp_pPair(dlkp_p* kp, randomGeneratorContext* rgc, const dldp_p* param) { @@ -56,15 +56,15 @@ int dlkp_pInit(dlkp_p* kp) int dlkp_pFree(dlkp_p* kp) { - /*@-usereleased -compdef @*/ /* kp->param.{p,q,n}.modl is OK */ if (dldp_pFree(&kp->param) < 0) return -1; mpnfree(&kp->y); + /* wipe secret key before freeing */ + mpnwipe(&kp->x); mpnfree(&kp->x); return 0; - /*@=usereleased =compdef @*/ } int dlkp_pCopy(dlkp_p* dst, const dlkp_p* src) @@ -77,6 +77,3 @@ int dlkp_pCopy(dlkp_p* dst, const dlkp_p* src) return 0; } - -/*!\} - */ diff --git a/beecrypt/dlkp.h b/beecrypt/dlkp.h index 9e7557e..2629073 100644 --- a/beecrypt/dlkp.h +++ b/beecrypt/dlkp.h @@ -26,44 +26,43 @@ #ifndef _DLKP_H #define _DLKP_H -#include "dlpk.h" +#include "beecrypt/dlpk.h" /*!\ingroup DL_m */ -typedef struct +#ifdef __cplusplus +struct BEECRYPTAPI dlkp_p +#else +struct _dlkp_p +#endif { dldp_p param; mpnumber y; mpnumber x; -} dlkp_p; + + #ifdef __cplusplus + dlkp_p(); + dlkp_p(const dlkp_p&); + ~dlkp_p(); + #endif +}; + +#ifndef __cplusplus +typedef struct _dlkp_p dlkp_p; +#endif #ifdef __cplusplus extern "C" { #endif -/** - */ -BEECRYPTAPI /*@unused@*/ -int dlkp_pPair(dlkp_p* kp, randomGeneratorContext* rgc, const dldp_p* param) - /*@modifies kp, rgc @*/; - -/** - */ -BEECRYPTAPI /*@unused@*/ -int dlkp_pInit(dlkp_p* kp) - /*@modifies kp @*/; - -/** - */ -BEECRYPTAPI /*@unused@*/ -int dlkp_pFree(dlkp_p* kp) - /*@modifies kp @*/; - -/** - */ -BEECRYPTAPI /*@unused@*/ -int dlkp_pCopy(dlkp_p* dst, const dlkp_p* src) - /*@modifies dst @*/; +BEECRYPTAPI +int dlkp_pPair(dlkp_p*, randomGeneratorContext*, const dldp_p*); +BEECRYPTAPI +int dlkp_pInit(dlkp_p*); +BEECRYPTAPI +int dlkp_pFree(dlkp_p*); +BEECRYPTAPI +int dlkp_pCopy(dlkp_p*, const dlkp_p*); #ifdef __cplusplus } diff --git a/beecrypt/dlpk.c b/beecrypt/dlpk.c index fd50828..02dc622 100644 --- a/beecrypt/dlpk.c +++ b/beecrypt/dlpk.c @@ -17,16 +17,19 @@ * */ -/*!\file dlpk.c +/*!\file dlpk.h * \brief Discrete Logarithm public key. * \author Bob Deblier * \ingroup DL_m */ -#include "system.h" -#include "dlpk.h" -#include "mp.h" -#include "debug.h" +#define BEECRYPT_DLL_EXPORT + +#if HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/dlpk.h" /*!\addtogroup DL_m * \{ @@ -44,14 +47,12 @@ int dlpk_pInit(dlpk_p* pk) int dlpk_pFree(dlpk_p* pk) { - /*@-usereleased -compdef @*/ /* pk->param.{p,q,n}.modl is OK */ if (dldp_pFree(&pk->param) < 0) return -1; mpnfree(&pk->y); return 0; - /*@=usereleased =compdef @*/ } int dlpk_pCopy(dlpk_p* dst, const dlpk_p* src) diff --git a/beecrypt/dlpk.h b/beecrypt/dlpk.h index 8726222..e91f623 100644 --- a/beecrypt/dlpk.h +++ b/beecrypt/dlpk.h @@ -26,55 +26,47 @@ #ifndef _DLPK_H #define _DLPK_H -#include "dldp.h" +#include "beecrypt/dldp.h" -/** +/*!\ingroup DL_m */ -typedef struct +#ifdef __cplusplus +struct BEECRYPTAPI dlpk_p +#else +struct _dlpk_p +#endif { dldp_p param; mpnumber y; -} dlpk_p; - #ifdef __cplusplus -extern "C" { + dlpk_p(); + dlpk_p(const dlpk_p&); + ~dlpk_p(); #endif +}; -/** - */ -BEECRYPTAPI /*@unused@*/ -int dlpk_pInit(dlpk_p* pk) - /*@modifies pk @*/; - -/** - */ -BEECRYPTAPI /*@unused@*/ -int dlpk_pFree(dlpk_p* pk) - /*@modifies pk @*/; +#ifndef __cplusplus +typedef struct _dlpk_p dlpk_p; +#endif -/** - */ -BEECRYPTAPI /*@unused@*/ -int dlpk_pCopy(dlpk_p* dst, const dlpk_p* src) - /*@modifies dst @*/; +#ifdef __cplusplus +extern "C" { +#endif -/** - */ -BEECRYPTAPI /*@unused@*/ -int dlpk_pEqual(const dlpk_p* a, const dlpk_p* b) - /*@*/; +BEECRYPTAPI +int dlpk_pInit(dlpk_p*); +BEECRYPTAPI +int dlpk_pFree(dlpk_p*); +BEECRYPTAPI +int dlpk_pCopy(dlpk_p*, const dlpk_p*); -/** - */ -BEECRYPTAPI /*@unused@*/ -int dlpk_pgoqValidate(const dlpk_p* pk, randomGeneratorContext* rgc, int cofactor) - /*@modifies rgc @*/; +BEECRYPTAPI +int dlpk_pEqual(const dlpk_p*, const dlpk_p*); -/** - */ -BEECRYPTAPI /*@unused@*/ -int dlpk_pgonValidate(const dlpk_p* pk, randomGeneratorContext* rgc) - /*@modifies rgc @*/; +BEECRYPTAPI +int dlpk_pgoqValidate(const dlpk_p*, randomGeneratorContext*, int cofactor); +BEECRYPTAPI +int dlpk_pgonValidate(const dlpk_p*, randomGeneratorContext*); #ifdef __cplusplus } diff --git a/beecrypt/dlsvdp-dh.c b/beecrypt/dlsvdp-dh.c index cb89e18..9f1cb68 100644 --- a/beecrypt/dlsvdp-dh.c +++ b/beecrypt/dlsvdp-dh.c @@ -27,15 +27,34 @@ * \ingroup DL_m DL_dh_m */ -#include "system.h" -#include "dlsvdp-dh.h" -#include "debug.h" +#define BEECRYPT_DLL_EXPORT + +#if HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/dlsvdp-dh.h" /*!\addtogroup DL_dh_m * \{ */ -int dlsvdp_pDHSecret(const dldp_p* dp, const mpnumber* x, const mpnumber* y, mpnumber* s) +/*!\fn dlsvdp_pDHSecret(const dhparam* dp, const mpnumber* x, const mpnumber* y, mpnumber* s) + * \brief Computes the shared secret. + * + * Equation: + * + * \li \f$s=y^{x}\ \textrm{mod}\ p\f$ + * + * \param dp The domain parameters. + * \param x The private value. + * \param y The public value (of the peer). + * \param s The computed secret value. + * + * \retval 0 on success. + * \retval -1 on failure. + */ +int dlsvdp_pDHSecret(const dhparam* dp, const mpnumber* x, const mpnumber* y, mpnumber* s) { mpbnpowmod(&dp->p, y, x, s); diff --git a/beecrypt/dlsvdp-dh.h b/beecrypt/dlsvdp-dh.h index 7b486a7..19d989e 100644 --- a/beecrypt/dlsvdp-dh.h +++ b/beecrypt/dlsvdp-dh.h @@ -20,34 +20,24 @@ /*!\file dlsvdp-dh.h * \brief Diffie-Hellman algorithm, headers. * \author Bob Deblier - * \ingroup DL_m DL_dh_m + * \ingroup DL_m DL_dh_m */ #ifndef _DLSVDP_DH_H #define _DLSVDP_DH_H -#include "dldp.h" +#include "beecrypt/dldp.h" +#include "beecrypt/dlkp.h" #ifdef __cplusplus extern "C" { #endif -/** - * Computes the shared secret. - * - * Equation: - * - * \li \f$s=y^{x}\ \textrm{mod}\ p\f$ - * - * @param dp domain parameters - * @param x private value - * @param y public value (of the peer) - * @param s computed secret value - * @retval 0 on success, -1 on failure. - */ +typedef dldp_p dhparam; +typedef dlkp_p dhkp; + BEECRYPTAPI -int dlsvdp_pDHSecret(const dldp_p* dp, const mpnumber* x, const mpnumber* y, mpnumber* s) - /*@modifies s @*/; +int dlsvdp_pDHSecret(const dhparam*, const mpnumber*, const mpnumber*, mpnumber*); #ifdef __cplusplus } diff --git a/beecrypt/docs/.cvsignore b/beecrypt/docs/.cvsignore deleted file mode 100644 index 540cfea..0000000 --- a/beecrypt/docs/.cvsignore +++ /dev/null @@ -1,19 +0,0 @@ -.deps -.depend -.depend-done -.libs -Makefile -Makefile.in -config.cache -config.guess -config.log -config.status -config.sub -configure -libtool -ltconfig -ltmain.sh -*.o -*.lo -stamp-h -stamp-h.in diff --git a/beecrypt/dsa.c b/beecrypt/dsa.c index 8d08b46..291392f 100644 --- a/beecrypt/dsa.c +++ b/beecrypt/dsa.c @@ -18,33 +18,18 @@ */ /*!\file dsa.c - * \brief Digital Signature Algorithm, as specified by NIST FIPS 186. - * - * FIPS 186 specifies the DSA algorithm as having a large prime \f$p\f$, - * a cofactor \f$q\f$ and a generator \f$g\f$ of a subgroup of - * \f$\mathds{Z}^{*}_p\f$ with order \f$q\f$. The private and public key - * values are \f$x\f$ and \f$y\f$ respectively. - * - * \author Bob Deblier + * \brief Digital Signature Algorithm. * \ingroup DL_m DL_dsa_m - * - * - Signing equation: - * - r = (g^k mod p) mod q and - * - s = (inv(k) * (h(m) + x*r)) mod q - * - Verifying equation: - * - check 0 < r < q and 0 < s < q - * - w = inv(s) mod q - * - u1 = (h(m)*w) mod q - * - u2 = (r*w) mod q - * - v = ((g^u1 * y^u2) mod p) mod q - * - check v == r */ + +#define BEECRYPT_DLL_EXPORT -#include "system.h" -#include "dsa.h" -#include "dldp.h" -#include "mp.h" -#include "debug.h" +#if HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/dsa.h" +#include "beecrypt/dldp.h" int dsasign(const mpbarrett* p, const mpbarrett* q, const mpnumber* g, randomGeneratorContext* rgc, const mpnumber* hm, const mpnumber* x, mpnumber* r, mpnumber* s) { @@ -59,11 +44,11 @@ int dsasign(const mpbarrett* p, const mpbarrett* q, const mpnumber* g, randomGen register int rc = -1; - ptemp = (mpw*) malloc((5*psize+2) * sizeof(*ptemp)); + ptemp = (mpw*) malloc((5*psize+2)*sizeof(mpw)); if (ptemp == (mpw*) 0) return rc; - qtemp = (mpw*) malloc((14*qsize+11) * sizeof(*qtemp)); + qtemp = (mpw*) malloc((9*qsize+6)*sizeof(mpw)); if (qtemp == (mpw*) 0) { free(ptemp); @@ -133,11 +118,11 @@ int dsavrfy(const mpbarrett* p, const mpbarrett* q, const mpnumber* g, const mpn if (mpgex(s->size, s->data, qsize, q->modl)) return rc; - ptemp = (mpw*) malloc((6*psize+2) * sizeof(*ptemp)); + ptemp = (mpw*) malloc((6*psize+2)*sizeof(mpw)); if (ptemp == (mpw*) 0) return rc; - qtemp = (mpw*) malloc((13*qsize+11) * sizeof(*qtemp)); + qtemp = (mpw*) malloc((8*qsize+6)*sizeof(mpw)); if (qtemp == (mpw*) 0) { free(ptemp); @@ -150,11 +135,8 @@ int dsavrfy(const mpbarrett* p, const mpbarrett* q, const mpnumber* g, const mpn mpsetx(qsize, qtemp+qsize, s->size, s->data); /* compute w = inv(s) mod q */ -/*@-compdef@*/ /* FIX: mpsetx annotations, qtemp[qsize] is defined */ - if (mpextgcd_w(qsize, qtemp+qsize, q->modl, qtemp, qwksp)) -/*@=compdef@*/ + if (mpextgcd_w(qsize, q->modl, qtemp+qsize, qtemp, qwksp)) { - /* compute u1 = h(m)*w mod q */ mpbmulmod_w(q, hm->size, hm->data, qsize, qtemp, qtemp+qsize, qwksp); @@ -181,3 +163,16 @@ int dsavrfy(const mpbarrett* p, const mpbarrett* q, const mpnumber* g, const mpn return rc; } + +int dsaparamMake(dsaparam* dp, randomGeneratorContext* rgc, size_t psize) +{ + /* psize must be >= 512 and <= 1024 */ + if ((psize < 512) || (psize > 1024)) + return -1; + + /* psize must be a multiple of 64 */ + if ((psize & 0x3f) != 0) + return -1; + + return dldp_pgoqMake(dp, rgc, psize, 160, 1); +} diff --git a/beecrypt/dsa.h b/beecrypt/dsa.h index c963796..34165b2 100644 --- a/beecrypt/dsa.h +++ b/beecrypt/dsa.h @@ -32,36 +32,40 @@ #ifndef _DSA_H #define _DSA_H -#include "mpbarrett.h" +#include "beecrypt/dlkp.h" + +typedef dldp_p dsaparam; +typedef dlpk_p dsapub; +typedef dlkp_p dsakp; #ifdef __cplusplus extern "C" { #endif -/** - * The raw DSA signing function. +/*!\fn int dsasign(const mpbarrett* p, const mpbarrett* q, const mpnumber* g, randomGeneratorContext* rgc, const mpnumber* hm, const mpnumber* x, mpnumber* r, mpnumber* s) + * \brief This function performs a raw DSA signature. * * Signing equations: * * \li \f$r=(g^{k}\ \textrm{mod}\ p)\ \textrm{mod}\ q\f$ * \li \f$s=k^{-1}(h(m)+xr)\ \textrm{mod}\ q\f$ * - * @param p The prime. - * @param q The cofactor. - * @param g The generator. - * @param rgc The pseudo-random generator context. - * @param hm The hash to be signed. - * @param x The private key value. - * @param r The signature's \e r value. - * @param s The signature's \e r value. - * @retval 0 on success, -1 on failure. + * \param p The prime. + * \param q The cofactor. + * \param g The generator. + * \param rgc The pseudo-random generator context. + * \param hm The hash to be signed. + * \param x The private key value. + * \param r The signature's \e r value. + * \param s The signature's \e s value. + * \retval 0 on success. + * \retval -1 on failure. */ -BEECRYPTAPI /*@unused@*/ -int dsasign(const mpbarrett* p, const mpbarrett* q, const mpnumber* g, randomGeneratorContext* rgc, const mpnumber* hm, const mpnumber* x, mpnumber* r, mpnumber* s) - /*@modifies r->size, r->data, *r->data, s->size, s->data @*/; +BEECRYPTAPI +int dsasign(const mpbarrett* p, const mpbarrett* q, const mpnumber* g, randomGeneratorContext*, const mpnumber* hm, const mpnumber* x, mpnumber* r, mpnumber* s); -/** - * The raw DSA verification function. +/*!\fn int dsavrfy(const mpbarrett* p, const mpbarrett* q, const mpnumber* g, const mpnumber* hm, const mpnumber* y, const mpnumber* r, const mpnumber* s) + * \brief This function performs a raw DSA verification. * * Verifying equations: * \li Check \f$0= 512 and <= 1024, and be a multiple of 64. + * \retval 0 on success. + * \retval -1 on failure. */ -BEECRYPTAPI /*@unused@*/ -int dsavrfy(const mpbarrett* p, const mpbarrett* q, const mpnumber* g, const mpnumber* hm, const mpnumber* y, const mpnumber* r, const mpnumber* s) - /*@*/; +BEECRYPTAPI +int dsaparamMake(dsaparam*, randomGeneratorContext*, size_t); #ifdef __cplusplus } diff --git a/beecrypt/elgamal.c b/beecrypt/elgamal.c index f525d41..73d824e 100644 --- a/beecrypt/elgamal.c +++ b/beecrypt/elgamal.c @@ -16,61 +16,25 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ - + /*!\file elgamal.c * \brief ElGamal algorithm. - * - * For more information on this algorithm, see: - * "Handbook of Applied Cryptography" - * 11.5.2: "The ElGamal signature scheme", p. 454-459 - * - * Two of the signature variants in Note 11.70 are described. - * - * \todo Explore the possibility of using simultaneous multiple exponentiation, - * as described in HAC, 14.87 (iii). - * * \author Bob Deblier - * \ingroup DL_m DL_elgamal_m - * - * - ElGamal Signature variant 1: (i.e. the standard version) - * - Signing equation: - * - r = g^k mod p and - * - s = inv(k) * (h(m) - x*r) mod (p-1) - * - Verifying equation: - * - check 1 <= r <= (p-1) - * - v1 = g^h(m) mod p - * - v2 = y^r * r^s mod p - * - check v1 == v2 - * - Simultaneous multiple exponentiation verification: - * - y^r * r^s * g^(p-1-h(m)) mod p = 1 or (the former is probably faster) - * - y^r * r^s * inv(g)^h(m) mod p = 1 - * - * - ElGamal Signature variant 3: signing is simpler, because no inverse has to be calculated - * - Signing equation: - * - r = g^k mod p and - * - s = x*r + k*h(m) mod (p-1) - * - Verifying equation: - * - check 1 <= r <= (p-1) - * - v1 = g^s mod p - * - v2 = y^r * r^h(m) mod p - * - Simultaneous multiple exponentiation verification: - * - y^r * r^h(m) * g^(p-1-s) mod p = 1 (one of the exponents is significantly smaller, i.e. h(m)) */ -#include "system.h" -#include "elgamal.h" -#include "dldp.h" -#include "mp.h" -#include "debug.h" +#define BEECRYPT_DLL_EXPORT -/*!\addtogroup DL_elgamal_m - * \{ - */ +#if HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/elgamal.h" +#include "beecrypt/dldp.h" int elgv1sign(const mpbarrett* p, const mpbarrett* n, const mpnumber* g, randomGeneratorContext* rgc, const mpnumber* hm, const mpnumber* x, mpnumber* r, mpnumber* s) { register size_t size = p->size; - register mpw* temp = (mpw*) malloc((13*size+11) * sizeof(*temp)); + register mpw* temp = (mpw*) malloc((8*size+6)*sizeof(mpw)); if (temp) { @@ -87,7 +51,7 @@ int elgv1sign(const mpbarrett* p, const mpbarrett* n, const mpnumber* g, randomG /* compute -(x*r) mod n */ mpneg(size, temp); - (void) mpadd(size, temp, n->modl); + mpadd(size, temp, n->modl); /* compute h(m) - x*r mod n */ mpbaddmod_w(n, hm->size, hm->data, size, temp, temp, temp+2*size); @@ -121,7 +85,7 @@ int elgv1vrfy(const mpbarrett* p, const mpbarrett* n, const mpnumber* g, const m if (mpgex(s->size, s->data, n->size, n->modl)) return 0; - temp = (mpw*) malloc((6*size+2) * sizeof(*temp)); + temp = (mpw*) malloc((6*size+2)*sizeof(mpw)); if (temp) { @@ -151,7 +115,7 @@ int elgv1vrfy(const mpbarrett* p, const mpbarrett* n, const mpnumber* g, const m int elgv3sign(const mpbarrett* p, const mpbarrett* n, const mpnumber* g, randomGeneratorContext* rgc, const mpnumber* hm, const mpnumber* x, mpnumber* r, mpnumber* s) { register size_t size = p->size; - register mpw* temp = (mpw*) malloc((6*size+2) * sizeof(*temp)); + register mpw* temp = (mpw*) malloc((6*size+2)*sizeof(mpw)); if (temp) { @@ -198,7 +162,7 @@ int elgv3vrfy(const mpbarrett* p, const mpbarrett* n, const mpnumber* g, const m if (mpgex(s->size, s->data, n->size, n->modl)) return 0; - temp = (mpw*) malloc((6*size+2) * sizeof(*temp)); + temp = (mpw*) malloc((6*size+2)*sizeof(mpw)); if (temp) { diff --git a/beecrypt/elgamal.h b/beecrypt/elgamal.h index 7f04c0d..164a836 100644 --- a/beecrypt/elgamal.h +++ b/beecrypt/elgamal.h @@ -38,58 +38,38 @@ #ifndef _ELGAMAL_H #define _ELGAMAL_H -#include "mpbarrett.h" +#include "beecrypt/mpbarrett.h" #ifdef __cplusplus extern "C" { #endif -/** - * The raw ElGamal signing funcion, variant 1. +/*!\fn int elgv1sign(const mpbarrett* p, const mpbarrett* n, const mpnumber* g, +randomGeneratorContext* rgc, const mpnumber* hm, const mpnumber* x, mpnumber* r, + mpnumber* s) + * \brief This function performs raw ElGamal signing, variant 1. * * Signing equations: * * \li \f$r=g^{k}\ \textrm{mod}\ p\f$ * \li \f$s=k^{-1}(h(m)-xr)\ \textrm{mod}\ (p-1)\f$ * - * @param p The prime. - * @param n The reducer mod (p-1). - * @param g The generator. - * @param rgc The pseudo-random generator. - * @param hm The hash to be signed. - * @param x The private key value. - * @param r The signature's \e r value. - * @param s The signature's \e r value. - * @retval 0 on success, -1 on failure. + * \param p The prime. + * \param n The reducer mod (p-1). + * \param g The generator. + * \param rgc The pseudo-random generat + * \param hm The hash to be signed. + * \param x The private key value. + * \param r The signature's \e r value. + * \param s The signature's \e s value. + * \retval 0 on success. + * \retval -1 on failure. */ -BEECRYPTAPI /*@unused@*/ -int elgv1sign(const mpbarrett* p, const mpbarrett* n, const mpnumber* g, randomGeneratorContext* rgc, const mpnumber* hm, const mpnumber* x, mpnumber* r, mpnumber* s) - /*@modifies r, s */; +BEECRYPTAPI +int elgv1sign(const mpbarrett* p, const mpbarrett* n, const mpnumber* g, randomGeneratorContext*, const mpnumber* hm, const mpnumber* x, mpnumber* r, mpnumber* s); -/** - * The raw ElGamal signing funcion, variant 3. - * - * Signing equations: - * - * \li \f$r=g^{k}\ \textrm{mod}\ p\f$ - * \li \f$s=xr+kh(m)\ \textrm{mod}\ (p-1)\f$ - * - * @param p The prime. - * @param n The reducer mod (p-1). - * @param g The generator. - * @param rgc The pseudo-random generator. - * @param hm The hash to be signed. - * @param x The private key value. - * @param r The signature's \e r value. - * @param s The signature's \e r value. - * @retval 0 on success, -1 on failure. - */ -BEECRYPTAPI /*@unused@*/ -int elgv3sign(const mpbarrett* p, const mpbarrett* n, const mpnumber* g, randomGeneratorContext* rgc, const mpnumber* hm, const mpnumber* x, mpnumber* r, mpnumber* s) - /*@modifies r, s */; - -/** - * The raw ElGamal verification funcion, variant 1. +/*!\fn int elgv1vrfy(const mpbarrett* p, const mpbarrett* n, const mpnumber* g, const mpnumber* hm, const mpnumber* y, const mpnumber* r, const mpnumber* s) + * \brief This function performs raw ElGamal verification, variant 1. * * Verifying equations: * @@ -98,24 +78,43 @@ int elgv3sign(const mpbarrett* p, const mpbarrett* n, const mpnumber* g, randomG * \li \f$v_2=g^{h(m)}\ \textrm{mod}\ p\f$ * \li Check \f$v_1=v_2\f$ * - * @warning The return type of this function should be a boolean, but since - * that type isn't as portable, an int is used. - * - * @param p The prime. - * @param n The reducer mod (p-1). - * @param g The generator. - * @param hm The hash to be signed. - * @param y The public key value. - * @param r The signature's \e r value. - * @param s The signature's \e r value. - * @retval 1 on success, 0 on failure. + * \param p The prime. + * \param n The reducer mod (p-1). + * \param g The generator. + * \param hm The hash to be signed. + * \param y The public key value. + * \param r The signature's \e r value. + * \param s The signature's \e s value. + * \retval 1 on success. + * \retval 0 on failure. + */ +BEECRYPTAPI +int elgv3sign(const mpbarrett* p, const mpbarrett* n, const mpnumber* g, randomGeneratorContext*, const mpnumber* hm, const mpnumber* x, mpnumber* r, mpnumber* s); + +/*!\fn int elgv3sign(const mpbarrett* p, const mpbarrett* n, const mpnumber* g, randomGeneratorContext* rgc, const mpnumber* hm, const mpnumber* x, mpnumber* r, mpnumber* s) + * \brief This function performs raw ElGamal signing, variant 3. + * + * Signing equations: + * + * \li \f$r=g^{k}\ \textrm{mod}\ p\f$ + * \li \f$s=xr+kh(m)\ \textrm{mod}\ (p-1)\f$ + * + * \param p The prime. + * \param n The reducer mod (p-1). + * \param g The generator. + * \param rgc The pseudo-random generat + * \param hm The hash to be signed. + * \param x The private key value. + * \param r The signature's \e r value. + * \param s The signature's \e s value. + * \retval 0 on success. + * \retval -1 on failure. */ -BEECRYPTAPI /*@unused@*/ -int elgv1vrfy(const mpbarrett* p, const mpbarrett* n, const mpnumber* g, const mpnumber* hm, const mpnumber* y, const mpnumber* r, const mpnumber* s) - /*@*/; +BEECRYPTAPI +int elgv1vrfy(const mpbarrett* p, const mpbarrett* n, const mpnumber* g, const mpnumber* hm, const mpnumber* y, const mpnumber* r, const mpnumber* s); -/** - * The raw ElGamal verification funcion, variant 3. +/*!\fn int elgv3vrfy(const mpbarrett* p, const mpbarrett* n, const mpnumber* g, const mpnumber* hm, const mpnumber* y, const mpnumber* r, const mpnumber* s) + * \brief This function performs raw ElGamal verification, variant 3. * * Verifying equations: * @@ -124,21 +123,18 @@ int elgv1vrfy(const mpbarrett* p, const mpbarrett* n, const mpnumber* g, const m * \li \f$v_2=y^{r}r^{h(m)}\ \textrm{mod}\ p\f$ * \li Check \f$v_1=v_2\f$ * - * @warning The return type of this function should be a boolean, but since - * that type isn't as portable, an int is used. - * - * @param p The prime. - * @param n The reducer mod (p-1). - * @param g The generator. - * @param hm The hash to be signed. - * @param y The public key value. - * @param r The signature's \e r value. - * @param s The signature's \e r value. - * @retval 1 on success, 0 on failure. + * \param p The prime. + * \param n The reducer mod (p-1). + * \param g The generator. + * \param hm The hash to be signed. + * \param y The public key value. + * \param r The signature's \e r value. + * \param s The signature's \e s value. + * \retval 1 on success. + * \retval 0 on failure. */ -BEECRYPTAPI /*@unused@*/ -int elgv3vrfy(const mpbarrett* p, const mpbarrett* n, const mpnumber* g, const mpnumber* hm, const mpnumber* y, const mpnumber* r, const mpnumber* s) - /*@*/; +BEECRYPTAPI +int elgv3vrfy(const mpbarrett* p, const mpbarrett* n, const mpnumber* g, const mpnumber* hm, const mpnumber* y, const mpnumber* r, const mpnumber* s); #ifdef __cplusplus } diff --git a/beecrypt/endianness.c b/beecrypt/endianness.c index 5f974f3..750403d 100644 --- a/beecrypt/endianness.c +++ b/beecrypt/endianness.c @@ -1,4 +1,3 @@ -/*@-bitwisesigned -shiftimplementation @*/ /* * Copyright (c) 1998, 1999, 2000, 2001 Virtual Unlimited B.V. * @@ -23,9 +22,13 @@ * \author Bob Deblier */ -#include "system.h" -#include "endianness.h" -#include "debug.h" +#define BEECRYPT_DLL_EXPORT + +#if HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/endianness.h" int16_t swap16(int16_t n) { @@ -57,13 +60,12 @@ uint32_t swapu32(uint32_t n) int64_t swap64(int64_t n) { - return ( ((n & ((int64_t) 0xff) ) << 56) | - ((n & ((int64_t) 0xff) << 8) << 40) | - ((n & ((int64_t) 0xff) << 16) << 24) | - ((n & ((int64_t) 0xff) << 24) << 8) | - ((n & ((int64_t) 0xff) << 32) >> 8) | - ((n & ((int64_t) 0xff) << 40) >> 24) | - ((n & ((int64_t) 0xff) << 48) >> 40) | - ((n & ((int64_t) 0xff) << 56) >> 56) ); + return ( ((n & (((int64_t) 0xff) )) << 56) | + ((n & (((int64_t) 0xff) << 8)) << 40) | + ((n & (((int64_t) 0xff) << 16)) << 24) | + ((n & (((int64_t) 0xff) << 24)) << 8) | + ((n & (((int64_t) 0xff) << 32)) >> 8) | + ((n & (((int64_t) 0xff) << 40)) >> 24) | + ((n & (((int64_t) 0xff) << 48)) >> 40) | + ((n & (((int64_t) 0xff) << 56)) >> 56) ); } -/*@=bitwisesigned =shiftimplementation @*/ diff --git a/beecrypt/endianness.h b/beecrypt/endianness.h index df9942e..f11dddb 100644 --- a/beecrypt/endianness.h +++ b/beecrypt/endianness.h @@ -5,6 +5,8 @@ * * Copyright (c) 1998, 1999, 2000, 2001 Virtual Unlimited B.V. * + * Author: Bob Deblier + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either @@ -24,7 +26,7 @@ #ifndef _ENDIANNESS_H #define _ENDIANNESS_H -#include "beecrypt.h" +#include "beecrypt/beecrypt.h" #ifdef __cplusplus inline int16_t swap16(int16_t n) @@ -67,35 +69,19 @@ inline int64_t swap64(int64_t n) ((n & ((int64_t) 0xff) << 56) >> 56) ); } #else -/*@-exportlocal@*/ -/** - */ -/*@unused@*/ - int16_t swap16 (int16_t n) - /*@*/; - -/** - */ -uint16_t swapu16(uint16_t n) - /*@*/; - -/** - */ -/*@unused@*/ - int32_t swap32 (int32_t n) - /*@*/; + int16_t swap16 (int16_t); +uint16_t swapu16(uint16_t); + int32_t swap32 (int32_t); +uint32_t swapu32(uint32_t); + int64_t swap64 (int64_t); +#endif -/** - */ -uint32_t swapu32(uint32_t n) - /*@*/; +#ifdef __cplusplus +extern "C" { +#endif -/** - */ -/*@unused@*/ - int64_t swap64 (int64_t n) - /*@*/; -/*@=exportlocal@*/ +#ifdef __cplusplus +} #endif #endif diff --git a/beecrypt/entropy.c b/beecrypt/entropy.c index 5dc3f0b..958c8c4 100644 --- a/beecrypt/entropy.c +++ b/beecrypt/entropy.c @@ -24,9 +24,12 @@ #define BEECRYPT_DLL_EXPORT -#include "system.h" -#include "entropy.h" -#include "endianness.h" +#if HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/entropy.h" +#include "beecrypt/endianness.h" #if WIN32 # include @@ -36,8 +39,22 @@ # if HAVE_SYS_IOCTL_H # include # endif +# if HAVE_SYS_STAT_H +# include +# include +# endif +# if TIME_WITH_SYS_TIME +# include +# include +# else +# if HAVE_SYS_TIME_H +# include +# elif HAVE_TIME_H +# include +# endif +# endif # if HAVE_SYS_AUDIOIO_H -# include +# include # endif # if HAVE_SYS_SOUNDCARD_H # include @@ -47,69 +64,23 @@ # elif HAVE_TERMIO_H # include # endif -# if HAVE_SYNCH_H -# include -# elif HAVE_PTHREAD_H -# include +# ifdef _REENTRANT +# if HAVE_THREAD_H && HAVE_SYNCH_H +# include +# elif HAVE_PTHREAD_H +# include +# endif # endif # if HAVE_AIO_H # include -# if defined(__LCLINT__) -/*@-declundef -exportheader -incondefs -constuse -warnmissingglobs @*/ - extern int /*@unused@*/ -nanosleep (const struct timespec *__requested_time, - /*@out@*/ /*@null@*/ struct timespec *__remaining) - /*@modifies *__remaining, errno @*/; - - extern void -aio_init (const struct aioinit *__init) - /*@*/; - extern int -aio_read (struct aiocb *__aiocbp) - /*@modifies errno, fileSystem, systemState @*/; - extern int -aio_write (struct aiocb *__aiocbp) - /*@modifies errno, fileSystem, systemState @*/; - extern int -lio_listio (int __mode, - struct aiocb *const __list[], - int __nent, struct sigevent *__sig) - /*@modifies errno, fileSystem, systemState @*/; - extern int -aio_error (const struct aiocb *__aiocbp) - /*@modifies errno @*/; - extern __ssize_t -aio_return (struct aiocb *__aiocbp) - /*@modifies errno, systemState @*/; - extern int -aio_cancel (int __fildes, /*@null@*/ struct aiocb *__aiocbp) - /*@modifies errno, systemState @*/; - extern int -aio_suspend (/*@out@*/ const struct aiocb *const __list[], int __nent, - /*@out@*/ const struct timespec *__timeout) - /*@modifies errno, systemState @*/; - extern int -aio_fsync (int __operation, struct aiocb *__aiocbp) - /*@modifies errno, fileSystem, systemState @*/; - -/*@constant int AIO_CANCELED@*/ -/*@constant int AIO_NOTCANCELED@*/ -/*@constant int AIO_ALLDONE@*/ -/*@constant int LIO_READ@*/ -/*@constant int LIO_WRITE@*/ -/*@constant int LIO_NOP@*/ -/*@constant int LIO_WAIT@*/ -/*@constant int LIO_NOWAIT@*/ -/*@constant int SIGEV_SIGNAL@*/ -/*@constant int SIGEV_NONE@*/ -/*@constant int SIGEV_THREAD@*/ - -/*@=declundef =exportheader =incondefs =constuse =warnmissingglobs @*/ -# endif # endif #endif - -#include "debug.h" +#if HAVE_FCNTL_H +# include +#endif +#if HAVE_ERRNO_H +# include +#endif #if WIN32 static HINSTANCE entropy_instance = (HINSTANCE) 0; @@ -147,16 +118,13 @@ int entropy_provider_cleanup() #endif #if WIN32 || HAVE_DEV_AUDIO || HAVE_DEV_DSP -/** \ingroup ES_audio_m ES_dsp_m +/* * Mask the low-order bit of a bunch of sound samples, analyze them and * return an error in case they are all zeroes or ones. */ -static int entropy_noise_filter(void* sampledata, unsigned samplecount, int samplesize, int channels, int swap) - /*@globals errno @*/ - /*@modifies sampledata, errno @*/ +static int entropy_noise_filter(void* sampledata, int samplecount, int samplesize, int channels, int swap) { - register int rc = 0; - register unsigned i; + register int rc = 0, i; switch (samplesize) { @@ -173,7 +141,7 @@ static int entropy_noise_filter(void* sampledata, unsigned samplecount, int samp for (i = 0; i < samplecount; i++) { - if ((samples[i] & 0x1) != 0) + if (samples[i] &= 0x1) ones_count++; else zero_count++; @@ -187,7 +155,7 @@ static int entropy_noise_filter(void* sampledata, unsigned samplecount, int samp rc = -1; } } - /*@innerbreak@*/ break; + break; case 2: { @@ -198,16 +166,16 @@ static int entropy_noise_filter(void* sampledata, unsigned samplecount, int samp for (i = 0; i < samplecount; i++) { - if (i & 1U) + if (i & 1) { - if ((samples[i] & 0x1) != 0) + if (samples[i] &= 0x1) ones_count_left++; else zero_count_left++; } else { - if ((samples[i] & 0x1) != 0) + if (samples[i] &= 0x1) ones_count_right++; else zero_count_right++; @@ -223,7 +191,7 @@ static int entropy_noise_filter(void* sampledata, unsigned samplecount, int samp rc = -1; } } - /*@innerbreak@*/ break; + break; default: #if HAVE_ERRNO_H @@ -250,7 +218,7 @@ static int entropy_noise_filter(void* sampledata, unsigned samplecount, int samp if (swap) samples[i] = swapu16(samples[i]); - if ((samples[i] & 0x1) != 0) + if (samples[i] &= 0x1) ones_count++; else zero_count++; @@ -264,7 +232,7 @@ static int entropy_noise_filter(void* sampledata, unsigned samplecount, int samp rc = -1; } } - /*@innerbreak@*/ break; + break; case 2: { @@ -280,14 +248,14 @@ static int entropy_noise_filter(void* sampledata, unsigned samplecount, int samp if (i & 1) { - if ((samples[i] & 0x1) != 0) + if (samples[i] &= 0x1) ones_count_left++; else zero_count_left++; } else { - if ((samples[i] & 0x1) != 0) + if (samples[i] &= 0x1) ones_count_right++; else zero_count_right++; @@ -303,14 +271,13 @@ static int entropy_noise_filter(void* sampledata, unsigned samplecount, int samp rc = -1; } } - /*@innerbreak@*/ break; + break; default: #if HAVE_ERRNO_H errno = EINVAL; #endif rc = -1; - /*@innerbreak@*/ break; } } break; @@ -320,28 +287,23 @@ static int entropy_noise_filter(void* sampledata, unsigned samplecount, int samp errno = EINVAL; #endif rc = -1; - break; } return 0; } -/** - * Bit deskewing technique: the classical Von Neumann method. - * - only use the lsb bit of every sample - * - there is a chance of bias in 0 or 1 bits, so to deskew this: - * - look at two successive sampled bits - * - if they are the same, discard them - * - if they are different, they're either 0-1 or 1-0; use the first bit of the pair as output - */ +/* bit deskewing technique: the classical Von Neumann method + - only use the lsb bit of every sample + - there is a chance of bias in 0 or 1 bits, so to deskew this: + - look at two successive sampled bits + - if they are the same, discard them + - if they are different, they're either 0-1 or 1-0; use the first bit of the pair as output +*/ #if WIN32 static int entropy_noise_gather(HWAVEIN wavein, int samplesize, int channels, int swap, int timeout, byte* data, size_t size) #else -/*@-mustmod@*/ /* data is modified, annotations incorrect */ -static int entropy_noise_gather(int fd, int samplesize, int channels, int swap, /*@unused@*/ int timeout, /*@out@*/ byte* data, size_t size) - /*@globals errno, fileSystem @*/ - /*@modifies *data, errno, fileSystem @*/ +static int entropy_noise_gather(int fd, int samplesize, int channels, int swap, int timeout, byte* data, size_t size) #endif { size_t randombits = size << 3; @@ -373,11 +335,7 @@ static int entropy_noise_gather(int fd, int samplesize, int channels, int swap, # error # endif - /*@-nullderef@*/ - *sampledata = 0; - /*@=nullderef@*/ memset(&my_aiocb, 0, sizeof(struct aiocb)); - memset(&my_aiocb_timeout, 0, sizeof(struct timespec)); my_aiocb.aio_fildes = fd; my_aiocb.aio_sigevent.sigev_notify = SIGEV_NONE; @@ -392,7 +350,6 @@ static int entropy_noise_gather(int fd, int samplesize, int channels, int swap, return -1; } - /*@-infloops -infloopsuncon -branchstate @*/ while (randombits) { #if WIN32 @@ -415,9 +372,7 @@ static int entropy_noise_gather(int fd, int samplesize, int channels, int swap, } #else # if ENABLE_AIO - /*@-mustfree@*/ /* my_aiocb.aio_buf is OK */ my_aiocb.aio_buf = sampledata; - /*@=mustfree@*/ my_aiocb.aio_nbytes = 1024 * samplesize * channels; rc = aio_read(&my_aiocb); @@ -427,9 +382,7 @@ static int entropy_noise_gather(int fd, int samplesize, int channels, int swap, if (rc < 0) { - /*@-kepttrans@*/ free(sampledata); - /*@=kepttrans@*/ return -1; } @@ -445,7 +398,7 @@ static int entropy_noise_gather(int fd, int samplesize, int channels, int swap, if (errno == EAGAIN) { /* certain linux glibc versions are buggy and don't aio_suspend properly */ - (void) nanosleep(&my_aiocb_timeout, (struct timespec*) 0); + nanosleep(&my_aiocb_timeout, (struct timespec*) 0); my_aiocb_timeout.tv_sec = (timeout / 1000); my_aiocb_timeout.tv_nsec = (timeout % 1000) * 1000000; @@ -468,15 +421,13 @@ static int entropy_noise_gather(int fd, int samplesize, int channels, int swap, my_aiocb_timeout.tv_sec = (timeout / 1000); my_aiocb_timeout.tv_nsec = (timeout % 1000) * 1000000; - (void) nanosleep(&my_aiocb_timeout, (struct timespec*) 0); + nanosleep(&my_aiocb_timeout, (struct timespec*) 0); } if (rc < 0) - /*@innerbreak@*/ break; + break; } - /*@-kepttrans@*/ free(sampledata); - /*@=kepttrans@*/ return -1; } @@ -484,9 +435,7 @@ static int entropy_noise_gather(int fd, int samplesize, int channels, int swap, if (rc) { - /*@-kepttrans@*/ free(sampledata); - /*@=kepttrans@*/ return -1; } @@ -494,22 +443,16 @@ static int entropy_noise_gather(int fd, int samplesize, int channels, int swap, if (rc < 0) { - /*@-kepttrans@*/ free(sampledata); - /*@=kepttrans@*/ return -1; } # endif #endif -/*@-type@*/ if (entropy_noise_filter(sampledata, rc / samplesize, samplesize, channels, swap) < 0) -/*@=type@*/ { fprintf(stderr, "noise filter indicates too much bias in audio samples\n"); - /*@-kepttrans@*/ free(sampledata); - /*@=kepttrans@*/ return -1; } @@ -521,7 +464,7 @@ static int entropy_noise_gather(int fd, int samplesize, int channels, int swap, for (i = 0; randombits && (i < 1024); i += 2) { - if ((samples[i] ^ samples[i+1]) != 0) + if (samples[i] ^ samples[i+1]) { temp <<= 1; temp |= samples[i]; @@ -531,7 +474,7 @@ static int entropy_noise_gather(int fd, int samplesize, int channels, int swap, } } } - /*@switchbreak@*/ break; + break; case 2: { @@ -549,29 +492,22 @@ static int entropy_noise_gather(int fd, int samplesize, int channels, int swap, } } } - /*@switchbreak@*/ break; + break; default: - /*@-kepttrans@*/ free(sampledata); - /*@=kepttrans@*/ return -1; - /*@notreached@*/ /*@switchbreak@*/ break; } } - /*@=infloops =infloopsuncon =branchstate @*/ #if WIN32 waveInStop(wavein); waveInReset(wavein); #endif - /*@-usereleased -kepttrans@*/ free(sampledata); - /*@=usereleased =kepttrans@*/ return 0; } -/*@=mustmod@*/ #endif #if WIN32 @@ -678,7 +614,7 @@ int entropy_wavein(byte* data, size_t size) rc = waveInOpen(&wavein, WAVE_MAPPER, &waveformatex, (DWORD) entropy_wavein_event, (DWORD) 0, CALLBACK_EVENT); if (rc != MMSYSERR_NOERROR) { - fprintf(stderr, "waveInOpen failed!\n"); (void) fflush(stderr); + fprintf(stderr, "waveInOpen failed!\n"); fflush(stderr); ReleaseMutex(entropy_wavein_lock); return -1; } @@ -708,21 +644,21 @@ int entropy_console(byte* data, size_t size) return -1; } - printf("please press random keys on your keyboard\n"); (void) fflush(stdout); + printf("please press random keys on your keyboard\n"); fflush(stdout); while (randombits) { if (!ReadConsoleInput(hStdin, &inEvent, 1, &inRet)) { - fprintf(stderr, "ReadConsoleInput failed\n"); (void) fflush(stderr); + fprintf(stderr, "ReadConsoleInput failed\n"); fflush(stderr); return -1; } if ((inRet == 1) && (inEvent.EventType == KEY_EVENT) && inEvent.Event.KeyEvent.bKeyDown) { - printf("."); (void) fflush(stdout); + printf("."); fflush(stdout); if (!QueryPerformanceCounter(&hrtsample)) { - fprintf(stderr, "QueryPerformanceCounter failed\n"); (void) fflush(stderr); + fprintf(stderr, "QueryPerformanceCounter failed\n"); fflush(stderr); return -1; } @@ -739,7 +675,7 @@ int entropy_console(byte* data, size_t size) if (!FlushConsoleInputBuffer(hStdin)) { - fprintf(stderr, "FlushConsoleInputBuffer failed\n"); (void) fflush(stderr); + fprintf(stderr, "FlushConsoleInputBuffer failed\n"); fflush(stderr); return -1; } @@ -779,152 +715,102 @@ int entropy_wincrypt(byte* data, size_t size) #else #if HAVE_DEV_AUDIO -/** \ingroup ES_audio_m +/*!\addtogroup ES_audio_m + * \{ */ -/*@observer@*/ /*@unchecked@*/ static const char* name_dev_audio = "/dev/audio"; - -/** \ingroup ES_audio_m - */ -/*@unchecked@*/ static int dev_audio_fd = -1; - -/** \ingroup ES_audio_m - */ # ifdef _REENTRANT -# if HAVE_SYNCH_H -/*@unchecked@*/ +# if HAVE_THREAD_H && HAVE_SYNCH_H static mutex_t dev_audio_lock = DEFAULTMUTEX; # elif HAVE_PTHREAD_H -/*@unchecked@*/ static pthread_mutex_t dev_audio_lock = PTHREAD_MUTEX_INITIALIZER; # else # error Need locking mechanism # endif # endif +/*!\} + */ #endif #if HAVE_DEV_DSP -/** \ingroup ES_dsp_m +/*!\addtogroup ES_dsp_m + * \{ */ -/*@observer@*/ /*@unchecked@*/ static const char* name_dev_dsp = "/dev/dsp"; - -/** \ingroup ES_dsp_m - */ -/*@unchecked@*/ static int dev_dsp_fd = -1; - -/** \ingroup ES_dsp_m - */ # ifdef _REENTRANT -# if HAVE_SYNCH_H -/*@unchecked@*/ +# if HAVE_THREAD_H && HAVE_SYNCH_H static mutex_t dev_dsp_lock = DEFAULTMUTEX; # elif HAVE_PTHREAD_H -/*@-type@*/ -/*@unchecked@*/ static pthread_mutex_t dev_dsp_lock = PTHREAD_MUTEX_INITIALIZER; -/*@=type@*/ # else # error Need locking mechanism # endif # endif +/*!\} + */ #endif #if HAVE_DEV_RANDOM -/** \ingroup ES_random_m +/*!\addtogroup ES_random_m + * \{ */ -/*@observer@*/ /*@unchecked@*/ static const char* name_dev_random = "/dev/random"; - -/** \ingroup ES_random_m - */ -/*@unchecked@*/ static int dev_random_fd = -1; - -/** \ingroup ES_random_m - */ # ifdef _REENTRANT -# if HAVE_SYNCH_H -/*@unchecked@*/ +# if HAVE_THREAD_H && HAVE_SYNCH_H static mutex_t dev_random_lock = DEFAULTMUTEX; # elif HAVE_PTHREAD_H -/*@-type@*/ -/*@unchecked@*/ static pthread_mutex_t dev_random_lock = PTHREAD_MUTEX_INITIALIZER; -/*@=type@*/ # else # error Need locking mechanism # endif # endif +/*!\} + */ #endif #if HAVE_DEV_URANDOM -/** \ingroup ES_urandom_m +/*!\addtogroup ES_urandom_m + * \{ */ -/*@observer@*/ /*@unchecked@*/ static const char* name_dev_urandom = "/dev/urandom"; - -/** \ingroup ES_urandom_m - */ -/*@unchecked@*/ static int dev_urandom_fd = -1; - -/** \ingroup ES_urandom_m - */ # ifdef _REENTRANT -# if HAVE_SYNCH_H -/*@unchecked@*/ +# if HAVE_THREAD_H && HAVE_SYNCH_H static mutex_t dev_urandom_lock = DEFAULTMUTEX; # elif HAVE_PTHREAD_H -/*@-type@*/ -/*@unchecked@*/ static pthread_mutex_t dev_urandom_lock = PTHREAD_MUTEX_INITIALIZER; -/*@=type@*/ # else # error Need locking mechanism # endif # endif +/*!\} + */ #endif #if HAVE_DEV_TTY -/** \ingroup ES_tty_m +/*!\addtogroup ES_tty_m + * \{ */ -/*@observer@*/ /*@unchecked@*/ static const char *dev_tty_name = "/dev/tty"; - -/** \ingroup ES_tty_m - */ -/*@unchecked@*/ static int dev_tty_fd = -1; - -/** \ingroup ES_tty_m - * @todo hpux needs real locking mechanism. - */ -# if defined(_REENTRANT) && !defined(hpux) -# if HAVE_SYNCH_H -/*@unchecked@*/ +# ifdef _REENTRANT +# if HAVE_THREAD_H && HAVE_SYNCH_H static mutex_t dev_tty_lock = DEFAULTMUTEX; # elif HAVE_PTHREAD_H -/*@-type@*/ -/*@unchecked@*/ static pthread_mutex_t dev_tty_lock = PTHREAD_MUTEX_INITIALIZER; -/*@=type@*/ # else # error Need locking mechanism # endif # endif +/*!\} + */ #endif #if HAVE_SYS_STAT_H -/** - * @param device - * @return - */ static int statdevice(const char *device) - /*@globals fileSystem @*/ - /*@modifies fileSystem @*/ { struct stat s; @@ -944,13 +830,7 @@ static int statdevice(const char *device) } #endif -/** - * @param device - * @return - */ static int opendevice(const char *device) - /*@globals fileSystem @*/ - /*@modifies fileSystem @*/ { register int fd; @@ -966,15 +846,10 @@ static int opendevice(const char *device) } #if HAVE_DEV_RANDOM || HAVE_DEV_URANDOM -/** \ingroup ES_random_m ES_urandom_m - * @param fd - * @param timeout in milliseconds - * @retval data - * @param size - * @return +/* timeout is in milliseconds */ +/*!\ingroup ES_random_m ES_urandom_m */ -static int entropy_randombits(int fd, /*@unused@*/ int timeout, /*@out@*/ byte* data, size_t size) - /*@modifies *data @*/ +static int entropy_randombits(int fd, int timeout, byte* data, size_t size) { register int rc; @@ -988,19 +863,15 @@ static int entropy_randombits(int fd, /*@unused@*/ int timeout, /*@out@*/ byte* # endif memset(&my_aiocb, 0, sizeof(struct aiocb)); - memset(&my_aiocb_timeout, 0, sizeof(struct timespec)); my_aiocb.aio_fildes = fd; my_aiocb.aio_sigevent.sigev_notify = SIGEV_NONE; #endif - /*@-branchstate@*/ while (size) { #if ENABLE_AIO - /*@-mustfree@*/ /* my_aiocb.aio_buf is OK */ my_aiocb.aio_buf = data; - /*@=mustfree@*/ my_aiocb.aio_nbytes = size; rc = aio_read(&my_aiocb); @@ -1023,7 +894,7 @@ static int entropy_randombits(int fd, /*@unused@*/ int timeout, /*@out@*/ byte* if (errno == EAGAIN) { /* certain linux glibc versions are buggy and don't aio_suspend properly */ - (void) nanosleep(&my_aiocb_timeout, (struct timespec*) 0); + nanosleep(&my_aiocb_timeout, (struct timespec*) 0); my_aiocb_timeout.tv_sec = 0; my_aiocb_timeout.tv_nsec = 0; @@ -1046,11 +917,11 @@ static int entropy_randombits(int fd, /*@unused@*/ int timeout, /*@out@*/ byte* my_aiocb_timeout.tv_sec = (timeout / 1000); my_aiocb_timeout.tv_nsec = (timeout % 1000) * 1000000; - (void) nanosleep(&my_aiocb_timeout, (struct timespec*) 0); + nanosleep(&my_aiocb_timeout, (struct timespec*) 0); } if (rc < 0) - /*@innerbreak@*/ break; + break; } return -1; @@ -1070,21 +941,14 @@ static int entropy_randombits(int fd, /*@unused@*/ int timeout, /*@out@*/ byte* data += rc; size -= rc; } - /*@=branchstate@*/ return 0; } #endif #if HAVE_DEV_TTY -/** \ingroup ES_tty_m - * @param fd - * @retval data - * @param size - * @return +/*!\ingroup ES_tty_m */ -static int entropy_ttybits(int fd, /*@out@*/ byte* data, size_t size) - /*@globals fileSystem @*/ - /*@modifies fileSystem @*/ +static int entropy_ttybits(int fd, byte* data, size_t size) { byte dummy; @@ -1115,14 +979,10 @@ static int entropy_ttybits(int fd, /*@out@*/ byte* data, size_t size) } tio_set = tio_save; - /*@-noeffect -type @*/ /* LCL: dunno @*/ tio_set.c_cc[VMIN] = 1; /* read 1 tty character at a time */ tio_set.c_cc[VTIME] = 0; /* don't timeout the read */ - /*@=noeffect =type @*/ -/*@-bitwisesigned@*/ tio_set.c_iflag |= IGNBRK; /* ignore -c */ tio_set.c_lflag &= ~(ECHO|ICANON); /* don't echo characters */ -/*@=bitwisesigned@*/ /* change the tty settings, and flush input characters */ if (tcsetattr(fd, TCSAFLUSH, &tio_set) < 0) @@ -1168,18 +1028,17 @@ static int entropy_ttybits(int fd, /*@out@*/ byte* data, size_t size) #endif return -1; } - printf("."); (void) fflush(stdout); + printf("."); fflush(stdout); #if HAVE_GETHRTIME hrtsample = gethrtime(); /* discard the 10 lowest bits i.e. 1024 nanoseconds of a sample */ - temp |= (uint16_t)(hrtsample >> 10); *(data++) = (byte)(hrtsample >> 10); size--; #elif HAVE_GETTIMEOFDAY /* discard the 4 lowest bits i.e. 4 microseconds */ - (void) gettimeofday(&tvsample, 0); + gettimeofday(&tvsample, 0); /* get 8 bits from the sample */ - *(data++) = (byte)(((unsigned)tvsample.tv_usec) >> 2); + *(data) = (byte)(tvsample.tv_usec >> 2); size--; #else # error Need alternative high-precision timer sample @@ -1189,7 +1048,7 @@ static int entropy_ttybits(int fd, /*@out@*/ byte* data, size_t size) printf("\nthanks\n"); /* give the user 1 second to stop typing */ - (void) sleep(1U); + sleep(1); #if HAVE_TERMIOS_H /* change the tty settings, and flush input characters */ @@ -1218,14 +1077,16 @@ static int entropy_ttybits(int fd, /*@out@*/ byte* data, size_t size) #endif #if HAVE_DEV_AUDIO -int entropy_dev_audio(uint32 *data, int size) +/*!\ingroup ES_audio_m + */ +int entropy_dev_audio(byte* data, size_t size) { const char* timeout_env = getenv("BEECRYPT_ENTROPY_AUDIO_TIMEOUT"); register int rc; #ifdef _REENTRANT - # if HAVE_SYNCH_H + # if HAVE_THREAD_H && HAVE_SYNCH_H if (mutex_lock(&dev_audio_lock)) return -1; # elif HAVE_PTHREAD_H @@ -1271,7 +1132,7 @@ int entropy_dev_audio(uint32 *data, int size) #if HAVE_ERRNO_H perror("ioctl AUDIO_SETINFO failed"); #endif - (void) close(dev_audio_fd); + close(dev_audio_fd); goto dev_audio_end; } @@ -1281,7 +1142,7 @@ int entropy_dev_audio(uint32 *data, int size) #if HAVE_ERRNO_H perror("ioctl AUDIO_SETINFO failed"); #endif - (void) close(dev_audio_fd); + close(dev_audio_fd); goto dev_audio_end; } @@ -1293,11 +1154,11 @@ int entropy_dev_audio(uint32 *data, int size) # error Unknown type of /dev/audio interface #endif - (void) close(dev_audio_fd); + close(dev_audio_fd); dev_audio_end: #ifdef _REENTRANT - # if HAVE_SYNCH_H + # if HAVE_THREAD_H && HAVE_SYNCH_H mutex_unlock(&dev_audio_lock); # elif HAVE_PTHREAD_H pthread_mutex_unlock(&dev_audio_lock); @@ -1308,23 +1169,21 @@ dev_audio_end: #endif #if HAVE_DEV_DSP -int entropy_dev_dsp(byte *data, size_t size) - /*@globals dev_dsp_fd @*/ - /*@modifies dev_dsp_fd @*/ +/*!\ingroup ES_dsp_m + */ +int entropy_dev_dsp(byte* data, size_t size) { const char* timeout_env = getenv("BEECRYPT_ENTROPY_DSP_TIMEOUT"); register int rc; #ifdef _REENTRANT - # if HAVE_SYNCH_H + # if HAVE_THREAD_H && HAVE_SYNCH_H if (mutex_lock(&dev_dsp_lock)) return -1; # elif HAVE_PTHREAD_H - /*@-moduncon -noeffectuncon @*/ /* FIX: annotate */ if (pthread_mutex_lock(&dev_dsp_lock)) return -1; - /*@=moduncon =noeffectuncon @*/ # endif #endif @@ -1340,20 +1199,16 @@ int entropy_dev_dsp(byte *data, size_t size) { int mask, format, samplesize, stereo, speed, swap; - mask = 0; - /*@-bitwisesigned -shiftimplementation -sizeoftype -type @*/ if ((rc = ioctl(dev_dsp_fd, SNDCTL_DSP_GETFMTS, &mask)) < 0) - /*@=bitwisesigned =shiftimplementation =sizeoftype =type @*/ { #if HAVE_ERRNO_H perror("ioctl SNDCTL_DSP_GETFMTS failed"); #endif - (void) close (dev_dsp_fd); + close (dev_dsp_fd); goto dev_dsp_end; } -/*@-bitwisesigned@*/ #if WORDS_BIGENDIAN if (mask & AFMT_S16_BE) { @@ -1392,34 +1247,27 @@ int entropy_dev_dsp(byte *data, size_t size) /* No linear audio format available */ rc = -1; - (void) close(dev_dsp_fd); + close(dev_dsp_fd); goto dev_dsp_end; } -/*@=bitwisesigned@*/ - /*@-bitwisesigned -shiftimplementation -sizeoftype -type @*/ if ((rc = ioctl(dev_dsp_fd, SNDCTL_DSP_SETFMT, &format)) < 0) - /*@=bitwisesigned =shiftimplementation =sizeoftype =type @*/ { #if HAVE_ERRNO_H perror("ioctl SNDCTL_DSP_SETFMT failed"); #endif - (void) close(dev_dsp_fd); + close(dev_dsp_fd); goto dev_dsp_end; } /* the next two commands are not critical */ stereo = 1; - /*@-bitwisesigned -shiftimplementation -sizeoftype -type @*/ - (void) ioctl(dev_dsp_fd, SNDCTL_DSP_STEREO, &stereo); - /*@=bitwisesigned =shiftimplementation =sizeoftype =type @*/ + ioctl(dev_dsp_fd, SNDCTL_DSP_STEREO, &stereo); speed = 44100; - /*@-bitwisesigned -shiftimplementation -sizeoftype -type @*/ - (void) ioctl(dev_dsp_fd, SNDCTL_DSP_SPEED, &speed); - /*@=bitwisesigned =shiftimplementation =sizeoftype =type @*/ + ioctl(dev_dsp_fd, SNDCTL_DSP_SPEED, &speed); rc = entropy_noise_gather(dev_dsp_fd, samplesize, 2, swap, timeout_env ? atoi(timeout_env) : 1000, data, size); } @@ -1427,16 +1275,14 @@ int entropy_dev_dsp(byte *data, size_t size) # error Unknown type of /dev/dsp interface #endif - (void) close(dev_dsp_fd); + close(dev_dsp_fd); dev_dsp_end: #ifdef _REENTRANT - # if HAVE_SYNCH_H + # if HAVE_THREAD_H && HAVE_SYNCH_H mutex_unlock(&dev_dsp_lock); # elif HAVE_PTHREAD_H - /*@-moduncon -noeffectuncon @*/ /* FIX: annotate */ - (void) pthread_mutex_unlock(&dev_dsp_lock); - /*@=moduncon =noeffectuncon @*/ + pthread_mutex_unlock(&dev_dsp_lock); # endif #endif @@ -1445,23 +1291,21 @@ dev_dsp_end: #endif #if HAVE_DEV_RANDOM +/*!\ingroup ES_random_m + */ int entropy_dev_random(byte* data, size_t size) - /*@globals dev_random_fd @*/ - /*@modifies dev_random_fd @*/ { const char* timeout_env = getenv("BEECRYPT_ENTROPY_RANDOM_TIMEOUT"); int rc; #ifdef _REENTRANT - # if HAVE_SYNCH_H + # if HAVE_THREAD_H && HAVE_SYNCH_H if (mutex_lock(&dev_random_lock)) return -1; # elif HAVE_PTHREAD_H - /*@-moduncon -noeffectuncon @*/ /* FIX: annotate */ if (pthread_mutex_lock(&dev_random_lock)) return -1; - /*@=moduncon =noeffectuncon @*/ # endif #endif @@ -1476,16 +1320,14 @@ int entropy_dev_random(byte* data, size_t size) /* collect entropy, with timeout */ rc = entropy_randombits(dev_random_fd, timeout_env ? atoi(timeout_env) : 1000, data, size); - (void) close(dev_random_fd); + close(dev_random_fd); dev_random_end: #ifdef _REENTRANT - # if HAVE_SYNCH_H + # if HAVE_THREAD_H && HAVE_SYNCH_H mutex_unlock(&dev_random_lock); # elif HAVE_PTHREAD_H - /*@-moduncon -noeffectuncon @*/ /* FIX: annotate */ - (void) pthread_mutex_unlock(&dev_random_lock); - /*@=moduncon =noeffectuncon @*/ + pthread_mutex_unlock(&dev_random_lock); # endif #endif return rc; @@ -1493,23 +1335,21 @@ dev_random_end: #endif #if HAVE_DEV_URANDOM +/*!\ingroup ES_urandom_m + */ int entropy_dev_urandom(byte* data, size_t size) - /*@globals dev_urandom_fd @*/ - /*@modifies dev_urandom_fd @*/ { const char* timeout_env = getenv("BEECRYPT_ENTROPY_URANDOM_TIMEOUT"); register int rc; #ifdef _REENTRANT - # if HAVE_SYNCH_H + # if HAVE_THREAD_H && HAVE_SYNCH_H if (mutex_lock(&dev_urandom_lock)) return -1; # elif HAVE_PTHREAD_H - /*@-moduncon -noeffectuncon @*/ /* FIX: annotate */ if (pthread_mutex_lock(&dev_urandom_lock)) return -1; - /*@=moduncon =noeffectuncon @*/ # endif #endif @@ -1524,16 +1364,14 @@ int entropy_dev_urandom(byte* data, size_t size) /* collect entropy, with timeout */ rc = entropy_randombits(dev_urandom_fd, timeout_env ? atoi(timeout_env) : 1000, data, size); - (void) close(dev_urandom_fd); + close(dev_urandom_fd); dev_urandom_end: #ifdef _REENTRANT - # if HAVE_SYNCH_H + # if HAVE_THREAD_H && HAVE_SYNCH_H mutex_unlock(&dev_urandom_lock); # elif HAVE_PTHREAD_H - /*@-moduncon -noeffectuncon @*/ /* FIX: annotate */ - (void) pthread_mutex_unlock(&dev_urandom_lock); - /*@=moduncon =noeffectuncon @*/ + pthread_mutex_unlock(&dev_urandom_lock); # endif #endif return rc; @@ -1541,22 +1379,19 @@ dev_urandom_end: #endif #if HAVE_DEV_TTY +/*!\ingroup ES_tty_m + */ int entropy_dev_tty(byte* data, size_t size) - /*@globals dev_tty_fd @*/ - /*@modifies dev_tty_fd @*/ { register int rc; -/** @todo hpux needs real locking mechanism. */ - #if defined(_REENTRANT) && !defined(hpux) - # if HAVE_SYNCH_H + #ifdef _REENTRANT + # if HAVE_THREAD_H && HAVE_SYNCH_H if (mutex_lock(&dev_tty_lock)) return -1; # elif HAVE_PTHREAD_H - /*@-moduncon -noeffectuncon @*/ /* FIX: annotate */ if (pthread_mutex_lock(&dev_tty_lock)) return -1; - /*@=moduncon =noeffectuncon @*/ # endif #endif @@ -1570,17 +1405,14 @@ int entropy_dev_tty(byte* data, size_t size) rc = entropy_ttybits(dev_tty_fd, data, size); - (void) close(dev_tty_fd); + close(dev_tty_fd); dev_tty_end: -/** @todo hpux needs real locking mechanism. */ - #if defined(_REENTRANT) && !defined(hpux) - # if HAVE_SYNCH_H + #ifdef _REENTRANT + # if HAVE_THREAD_H && HAVE_SYNCH_H mutex_unlock(&dev_tty_lock); # elif HAVE_PTHREAD_H - /*@-moduncon -noeffectuncon @*/ /* FIX: annotate */ - (void) pthread_mutex_unlock(&dev_tty_lock); - /*@=moduncon =noeffectuncon @*/ + pthread_mutex_unlock(&dev_tty_lock); # endif #endif diff --git a/beecrypt/entropy.h b/beecrypt/entropy.h index 2d7c521..b425d96 100644 --- a/beecrypt/entropy.h +++ b/beecrypt/entropy.h @@ -26,7 +26,7 @@ #ifndef _ENTROPY_H #define _ENTROPY_H -#include "beecrypt.h" +#include "beecrypt/beecrypt.h" #if WIN32 #include @@ -40,54 +40,29 @@ extern "C" { BEECRYPTAPI int entropy_provider_setup(HINSTANCE); BEECRYPTAPI -int entropy_provider_cleanup(void); +int entropy_provider_cleanup(); BEECRYPTAPI -int entropy_wavein(byte* data, size_t size); +int entropy_wavein(byte*, size_t); BEECRYPTAPI -int entropy_console(byte* data, size_t size); +int entropy_console(byte*, size_t); BEECRYPTAPI -int entropy_wincrypt(byte* data, size_t size); +int entropy_wincrypt(byte*, size_t); #else - #if HAVE_DEV_AUDIO -/** \ingroup ES_audio_m ES_m - */ -int entropy_dev_audio (/*@out@*/ byte* data, size_t size) - /*@globals fileSystem, internalState @*/ - /*@modifies data, fileSystem, internalState @*/; +int entropy_dev_audio (byte*, size_t); #endif - #if HAVE_DEV_DSP -/** \ingroup ES_dsp_m ES_m - */ -int entropy_dev_dsp (/*@out@*/ byte* data, size_t size) - /*@globals fileSystem, internalState @*/ - /*@modifies data, fileSystem, internalState @*/; +int entropy_dev_dsp (byte*, size_t); #endif - #if HAVE_DEV_RANDOM -/** \ingroup ES_random_m ES_m - */ -int entropy_dev_random(/*@out@*/ byte* data, size_t size) - /*@globals fileSystem, internalState @*/ - /*@modifies data, fileSystem, internalState @*/; +int entropy_dev_random (byte*, size_t); #endif - #if HAVE_DEV_URANDOM -/** \ingroup ES_urandom_m ES_m - */ -int entropy_dev_urandom(/*@out@*/ byte* data, size_t size) - /*@globals fileSystem, internalState @*/ - /*@modifies data, fileSystem, internalState @*/; +int entropy_dev_urandom(byte*, size_t); #endif - #if HAVE_DEV_TTY -/** \ingroup ES_tty_m ES_m - */ -int entropy_dev_tty (/*@out@*/ byte* data, size_t size) - /*@globals fileSystem, internalState @*/ - /*@modifies data, fileSystem, internalState @*/; +int entropy_dev_tty (byte*, size_t); #endif #endif diff --git a/beecrypt/fips186.c b/beecrypt/fips186.c index c6ce94c..0fc1385 100644 --- a/beecrypt/fips186.c +++ b/beecrypt/fips186.c @@ -23,39 +23,32 @@ * \ingroup PRNG_m PRNG_fips186_m */ -#include "system.h" -#include "beecrypt.h" -#include "fips186.h" -#include "mpopt.h" -#include "mp.h" -#include "debug.h" +#define BEECRYPT_DLL_EXPORT + +#if HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/fips186.h" /*!\addtogroup PRNG_fips186_m * \{ */ -/** - */ -/*@observer@*/ /*@unchecked@*/ static uint32_t fips186hinit[5] = { 0xefcdab89U, 0x98badcfeU, 0x10325476U, 0xc3d2e1f0U, 0x67452301U }; -/*@-sizeoftype@*/ const randomGenerator fips186prng = { "FIPS 186", sizeof(fips186Param), - (const randomGeneratorSetup) fips186Setup, - (const randomGeneratorSeed) fips186Seed, - (const randomGeneratorNext) fips186Next, - (const randomGeneratorCleanup) fips186Cleanup + (randomGeneratorSetup) fips186Setup, + (randomGeneratorSeed) fips186Seed, + (randomGeneratorNext) fips186Next, + (randomGeneratorCleanup) fips186Cleanup }; -/*@=sizeoftype@*/ -/** - */ static int fips186init(register sha1Param* p) - /*@modifies p @*/ { - memcpy(p->h, fips186hinit, sizeof(p->h)); + memcpy(p->h, fips186hinit, 5 * sizeof(uint32_t)); return 0; } @@ -72,12 +65,8 @@ int fips186Setup(fips186Param* fp) if (mutex_init(&fp->lock, USYNC_THREAD, (void *) 0)) return -1; # elif HAVE_PTHREAD_H - /*@-nullpass@*/ - /*@-moduncon@*/ if (pthread_mutex_init(&fp->lock, (pthread_mutexattr_t *) 0)) return -1; - /*@=moduncon@*/ - /*@=nullpass@*/ # endif # endif #endif @@ -102,10 +91,8 @@ int fips186Seed(fips186Param* fp, const byte* data, size_t size) if (mutex_lock(&fp->lock)) return -1; # elif HAVE_PTHREAD_H - /*@-moduncon@*/ if (pthread_mutex_lock(&fp->lock)) return -1; - /*@=moduncon@*/ # endif # endif #endif @@ -119,7 +106,7 @@ int fips186Seed(fips186Param* fp, const byte* data, size_t size) /* convert to multi-precision integer, and add to the state */ if (os2ip(seed, FIPS186_STATE_SIZE, data, size) == 0) - (void) mpadd(FIPS186_STATE_SIZE, fp->state, seed); + mpadd(FIPS186_STATE_SIZE, fp->state, seed); } #ifdef _REENTRANT # if WIN32 @@ -130,10 +117,8 @@ int fips186Seed(fips186Param* fp, const byte* data, size_t size) if (mutex_unlock(&fp->lock)) return -1; # elif HAVE_PTHREAD_H - /*@-moduncon@*/ if (pthread_mutex_unlock(&fp->lock)) return -1; - /*@=moduncon@*/ # endif # endif #endif @@ -157,10 +142,8 @@ int fips186Next(fips186Param* fp, byte* data, size_t size) if (mutex_lock(&fp->lock)) return -1; # elif HAVE_PTHREAD_H - /*@-moduncon@*/ if (pthread_mutex_lock(&fp->lock)) return -1; - /*@=moduncon@*/ # endif # endif #endif @@ -171,12 +154,12 @@ int fips186Next(fips186Param* fp, byte* data, size_t size) if (fp->digestremain == 0) { - (void) fips186init(&fp->param); + fips186init(&fp->param); /* copy the 512 bits of state data into the sha1Param */ memcpy(fp->param.data, fp->state, MP_WORDS_TO_BYTES(FIPS186_STATE_SIZE)); /* process the data */ sha1Process(&fp->param); - + #if WORDS_BIGENDIAN memcpy(fp->digest, fp->param.h, 20); #else @@ -206,12 +189,12 @@ int fips186Next(fips186Param* fp, byte* data, size_t size) if (os2ip(dig, FIPS186_STATE_SIZE, fp->digest, 20) == 0) { /* set state to state + digest + 1 mod 2^512 */ - (void) mpadd (FIPS186_STATE_SIZE, fp->state, dig); - (void) mpaddw(FIPS186_STATE_SIZE, fp->state, 1); + mpadd (FIPS186_STATE_SIZE, fp->state, dig); + mpaddw(FIPS186_STATE_SIZE, fp->state, 1); } /* else shouldn't occur */ /* we now have 5 words of pseudo-random data */ - fp->digestremain = (unsigned char) 20; + fp->digestremain = 20; } copy = (size > fp->digestremain) ? fp->digestremain : size; memcpy(data, fp->digest+20-fp->digestremain, copy); @@ -228,10 +211,8 @@ int fips186Next(fips186Param* fp, byte* data, size_t size) if (mutex_unlock(&fp->lock)) return -1; # elif HAVE_PTHREAD_H - /*@-moduncon@*/ if (pthread_mutex_unlock(&fp->lock)) return -1; - /*@=moduncon@*/ # endif # endif #endif @@ -253,10 +234,8 @@ int fips186Cleanup(fips186Param* fp) if (mutex_destroy(&fp->lock)) return -1; # elif HAVE_PTHREAD_H - /*@-moduncon@*/ if (pthread_mutex_destroy(&fp->lock)) return -1; - /*@=moduncon@*/ # endif # endif #endif diff --git a/beecrypt/fips186.h b/beecrypt/fips186.h index 423e097..f4b012c 100644 --- a/beecrypt/fips186.h +++ b/beecrypt/fips186.h @@ -26,6 +26,15 @@ #ifndef _FIPS186_H #define _FIPS186_H +#include "beecrypt/beecrypt.h" + +#ifdef _REENTRANT +# if WIN32 +# include +# include +# endif +#endif + #include "beecrypt.h" #include "sha1.h" @@ -42,15 +51,11 @@ typedef struct { #ifdef _REENTRANT - # if WIN32 - HANDLE lock; - # else - bc_lock_t lock; - # endif + bc_mutex_t lock; #endif - sha1Param param; - mpw state[FIPS186_STATE_SIZE]; - byte digest[20]; + sha1Param param; + mpw state[FIPS186_STATE_SIZE]; + byte digest[20]; unsigned char digestremain; } fips186Param; @@ -58,42 +63,16 @@ typedef struct extern "C" { #endif -/** - */ -/*@observer@*/ /*@unchecked@*/ extern BEECRYPTAPI const randomGenerator fips186prng; -/** - */ -/*@-exportlocal@*/ BEECRYPTAPI -int fips186Setup (fips186Param* fp) - /*@modifies fp @*/; -/*@=exportlocal@*/ - -/** - */ -/*@-exportlocal@*/ +int fips186Setup (fips186Param*); BEECRYPTAPI -int fips186Seed (fips186Param* fp, const byte* data, size_t size) - /*@modifies fp @*/; -/*@=exportlocal@*/ - -/** - */ -/*@-exportlocal@*/ +int fips186Seed (fips186Param*, const byte*, size_t); BEECRYPTAPI -int fips186Next (fips186Param* fp, byte* data, size_t size) - /*@modifies fp, data @*/; -/*@=exportlocal@*/ - -/** - */ -/*@-exportlocal@*/ +int fips186Next (fips186Param*, byte*, size_t); BEECRYPTAPI -int fips186Cleanup(fips186Param* fp) - /*@modifies fp @*/; -/*@=exportlocal@*/ +int fips186Cleanup(fips186Param*); #ifdef __cplusplus } diff --git a/beecrypt/gas/.cvsignore b/beecrypt/gas/.cvsignore deleted file mode 100644 index 540cfea..0000000 --- a/beecrypt/gas/.cvsignore +++ /dev/null @@ -1,19 +0,0 @@ -.deps -.depend -.depend-done -.libs -Makefile -Makefile.in -config.cache -config.guess -config.log -config.status -config.sub -configure -libtool -ltconfig -ltmain.sh -*.o -*.lo -stamp-h -stamp-h.in diff --git a/beecrypt/gas/Makefile.am b/beecrypt/gas/Makefile.am index d63e000..9c1f01e 100644 --- a/beecrypt/gas/Makefile.am +++ b/beecrypt/gas/Makefile.am @@ -23,7 +23,7 @@ AUTOMAKE_OPTIONS = gnu no-dependencies EXTRA_DIST = \ - aesopt.i586.m4 \ + aesopt.x86.m4 \ aesopt.ppc.m4 \ alpha.m4 \ asmdefs.m4 \ diff --git a/beecrypt/gas/aesopt.i586.m4 b/beecrypt/gas/aesopt.i586.m4 deleted file mode 100644 index e8dbf1d..0000000 --- a/beecrypt/gas/aesopt.i586.m4 +++ /dev/null @@ -1,580 +0,0 @@ -dnl aesopt.i586.m4 -dnl -dnl Copyright (c) 2003 Bob Deblier -dnl -dnl Author: Bob Deblier -dnl -dnl This library is free software; you can redistribute it and/or -dnl modify it under the terms of the GNU Lesser General Public -dnl License as published by the Free Software Foundation; either -dnl version 2.1 of the License, or (at your option) any later version. -dnl -dnl This library is distributed in the hope that it will be useful, -dnl but WITHOUT ANY WARRANTY; without even the implied warranty of -dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -dnl Lesser General Public License for more details. -dnl -dnl You should have received a copy of the GNU Lesser General Public -dnl License along with this library; if not, write to the Free Software -dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -include(config.m4) -include(ASM_SRCDIR/x86.m4) - -define(`sxrk',` - movl (%esi),%eax - movl 4(%esi),%ebx - movl 8(%esi),%ecx - movl 12(%esi),%edx - bswap %eax - bswap %ebx - bswap %ecx - bswap %edx - xorl (%ebp),%eax - xorl 4(%ebp),%ebx - xorl 8(%ebp),%ecx - xorl 12(%ebp),%edx - movl %eax, (%esp) - movl %ebx, 4(%esp) - movl %ecx, 8(%esp) - movl %edx,12(%esp) -') - -define(`etfs',` - movl $1+0(%ebp),%ecx - movl $1+4(%ebp),%edx - - movzbl 3(%esp),%eax - movzbl 7(%esp),%ebx - xorl SYMNAME(_ae0)(,%eax,4),%ecx - xorl SYMNAME(_ae0)(,%ebx,4),%edx - - movzbl 6(%esp),%eax - movzbl 10(%esp),%ebx - xorl SYMNAME(_ae1)(,%eax,4),%ecx - xorl SYMNAME(_ae1)(,%ebx,4),%edx - - movzbl 9(%esp),%eax - movzbl 13(%esp),%ebx - xorl SYMNAME(_ae2)(,%eax,4),%ecx - xorl SYMNAME(_ae2)(,%ebx,4),%edx - - movzbl 12(%esp),%eax - movzbl (%esp),%ebx - xorl SYMNAME(_ae3)(,%eax,4),%ecx - xorl SYMNAME(_ae3)(,%ebx,4),%edx - - movl %ecx,16(%esp) - movl %edx,20(%esp) - - movl $1+ 8(%ebp),%ecx - movl $1+12(%ebp),%edx - - movzbl 11(%esp),%eax - movzbl 15(%esp),%ebx - xorl SYMNAME(_ae0)(,%eax,4),%ecx - xorl SYMNAME(_ae0)(,%ebx,4),%edx - - movzbl 14(%esp),%eax - movzbl 2(%esp),%ebx - xorl SYMNAME(_ae1)(,%eax,4),%ecx - xorl SYMNAME(_ae1)(,%ebx,4),%edx - - movzbl 1(%esp),%eax - movzbl 5(%esp),%ebx - xorl SYMNAME(_ae2)(,%eax,4),%ecx - xorl SYMNAME(_ae2)(,%ebx,4),%edx - - movzbl 4(%esp),%eax - movzbl 8(%esp),%ebx - xorl SYMNAME(_ae3)(,%eax,4),%ecx - xorl SYMNAME(_ae3)(,%ebx,4),%edx - - movl %ecx,24(%esp) - movl %edx,28(%esp) -') - -define(`esft',` - movl $1+0(%ebp),%ecx - movl $1+4(%ebp),%edx - - movzbl 19(%esp),%eax - movzbl 23(%esp),%ebx - xorl SYMNAME(_ae0)(,%eax,4),%ecx - xorl SYMNAME(_ae0)(,%ebx,4),%edx - - movzbl 22(%esp),%eax - movzbl 26(%esp),%ebx - xorl SYMNAME(_ae1)(,%eax,4),%ecx - xorl SYMNAME(_ae1)(,%ebx,4),%edx - - movzbl 25(%esp),%eax - movzbl 29(%esp),%ebx - xorl SYMNAME(_ae2)(,%eax,4),%ecx - xorl SYMNAME(_ae2)(,%ebx,4),%edx - - movzbl 28(%esp),%eax - movzbl 16(%esp),%ebx - xorl SYMNAME(_ae3)(,%eax,4),%ecx - xorl SYMNAME(_ae3)(,%ebx,4),%edx - - movl %ecx, (%esp) - movl %edx, 4(%esp) - - movl $1+ 8(%ebp),%ecx - movl $1+12(%ebp),%edx - - movzbl 27(%esp),%eax - movzbl 31(%esp),%ebx - xorl SYMNAME(_ae0)(,%eax,4),%ecx - xorl SYMNAME(_ae0)(,%ebx,4),%edx - - movzbl 30(%esp),%eax - movzbl 18(%esp),%ebx - xorl SYMNAME(_ae1)(,%eax,4),%ecx - xorl SYMNAME(_ae1)(,%ebx,4),%edx - - movzbl 17(%esp),%eax - movzbl 21(%esp),%ebx - xorl SYMNAME(_ae2)(,%eax,4),%ecx - xorl SYMNAME(_ae2)(,%ebx,4),%edx - - movzbl 20(%esp),%eax - movzbl 24(%esp),%ebx - xorl SYMNAME(_ae3)(,%eax,4),%ecx - xorl SYMNAME(_ae3)(,%ebx,4),%edx - - movl %ecx, 8(%esp) - movl %edx,12(%esp) -') - -define(`elr',` - movl 0(%ebp),%ecx - movl 4(%ebp),%edx - - movzbl 19(%esp),%eax - movzbl 23(%esp),%ebx - movl SYMNAME(_ae4)(,%eax,4),%eax - movl SYMNAME(_ae4)(,%ebx,4),%ebx - andl `$'0xff000000,%eax - andl `$'0xff000000,%ebx - xorl %eax,%ecx - xorl %ebx,%edx - - movzbl 22(%esp),%eax - movzbl 26(%esp),%ebx - movl SYMNAME(_ae4)(,%eax,4),%eax - movl SYMNAME(_ae4)(,%ebx,4),%ebx - andl `$'0xff0000,%eax - andl `$'0xff0000,%ebx - xorl %eax,%ecx - xorl %ebx,%edx - - movzbl 25(%esp),%eax - movzbl 29(%esp),%ebx - movl SYMNAME(_ae4)(,%eax,4),%eax - movl SYMNAME(_ae4)(,%ebx,4),%ebx - andl `$'0xff00,%eax - andl `$'0xff00,%ebx - xorl %eax,%ecx - xorl %ebx,%edx - - movzbl 28(%esp),%eax - movzbl 16(%esp),%ebx - movl SYMNAME(_ae4)(,%eax,4),%eax - movl SYMNAME(_ae4)(,%ebx,4),%ebx - andl `$'0xff,%eax - andl `$'0xff,%ebx - xorl %eax,%ecx - xorl %ebx,%edx - - movl %ecx, (%esp) - movl %edx, 4(%esp) - - movl 8(%ebp),%ecx - movl 12(%ebp),%edx - - movzbl 27(%esp),%eax - movzbl 31(%esp),%ebx - movl SYMNAME(_ae4)(,%eax,4),%eax - movl SYMNAME(_ae4)(,%ebx,4),%ebx - andl `$'0xff000000,%eax - andl `$'0xff000000,%ebx - xorl %eax,%ecx - xorl %ebx,%edx - - movzbl 30(%esp),%eax - movzbl 18(%esp),%ebx - movl SYMNAME(_ae4)(,%eax,4),%eax - movl SYMNAME(_ae4)(,%ebx,4),%ebx - andl `$'0xff0000,%eax - andl `$'0xff0000,%ebx - xorl %eax,%ecx - xorl %ebx,%edx - - movzbl 17(%esp),%eax - movzbl 21(%esp),%ebx - movl SYMNAME(_ae4)(,%eax,4),%eax - movl SYMNAME(_ae4)(,%ebx,4),%ebx - andl `$'0xff00,%eax - andl `$'0xff00,%ebx - xorl %eax,%ecx - xorl %ebx,%edx - - movzbl 20(%esp),%eax - movzbl 24(%esp),%ebx - movl SYMNAME(_ae4)(,%eax,4),%eax - movl SYMNAME(_ae4)(,%ebx,4),%ebx - andl `$'0xff,%eax - andl `$'0xff,%ebx - xorl %eax,%ecx - xorl %ebx,%edx - - movl %ecx, 8(%esp) - movl %edx,12(%esp) -') - -define(`eblock',` - sxrk - - etfs(16) - esft(32) - etfs(48) - esft(64) - etfs(80) - esft(96) - etfs(112) - esft(128) - etfs(144) - - movl 256(%ebp),%eax - cmp `$'10,%eax - je $1 - - esft(160) - etfs(176) - - movl 256(%ebp),%eax - cmp `$'12,%eax - je $1 - - esft(192) - etfs(208) - - movl 256(%ebp),%eax - - .align 4 -$1: - sall `$'4,%eax - addl %eax,%ebp - - elr -') - -define(`dtfs',` - movl $1+0(%ebp),%ecx - movl $1+4(%ebp),%edx - - movzbl 3(%esp),%eax - movzbl 7(%esp),%ebx - xorl SYMNAME(_ad0)(,%eax,4),%ecx - xorl SYMNAME(_ad0)(,%ebx,4),%edx - - movzbl 14(%esp),%eax - movzbl 2(%esp),%ebx - xorl SYMNAME(_ad1)(,%eax,4),%ecx - xorl SYMNAME(_ad1)(,%ebx,4),%edx - - movzbl 9(%esp),%eax - movzbl 13(%esp),%ebx - xorl SYMNAME(_ad2)(,%eax,4),%ecx - xorl SYMNAME(_ad2)(,%ebx,4),%edx - - movzbl 4(%esp),%eax - movzbl 8(%esp),%ebx - xorl SYMNAME(_ad3)(,%eax,4),%ecx - xorl SYMNAME(_ad3)(,%ebx,4),%edx - - movl %ecx,16(%esp) - movl %edx,20(%esp) - - movl $1+ 8(%ebp),%ecx - movl $1+12(%ebp),%edx - - movzbl 11(%esp),%eax - movzbl 15(%esp),%ebx - xorl SYMNAME(_ad0)(,%eax,4),%ecx - xorl SYMNAME(_ad0)(,%ebx,4),%edx - - movzbl 6(%esp),%eax - movzbl 10(%esp),%ebx - xorl SYMNAME(_ad1)(,%eax,4),%ecx - xorl SYMNAME(_ad1)(,%ebx,4),%edx - - movzbl 1(%esp),%eax - movzbl 5(%esp),%ebx - xorl SYMNAME(_ad2)(,%eax,4),%ecx - xorl SYMNAME(_ad2)(,%ebx,4),%edx - - movzbl 12(%esp),%eax - movzbl (%esp),%ebx - xorl SYMNAME(_ad3)(,%eax,4),%ecx - xorl SYMNAME(_ad3)(,%ebx,4),%edx - - movl %ecx,24(%esp) - movl %edx,28(%esp) -') - -define(`dsft',` - movl $1+0(%ebp),%ecx - movl $1+4(%ebp),%edx - - movzbl 19(%esp),%eax - movzbl 23(%esp),%ebx - xorl SYMNAME(_ad0)(,%eax,4),%ecx - xorl SYMNAME(_ad0)(,%ebx,4),%edx - - movzbl 30(%esp),%eax - movzbl 18(%esp),%ebx - xorl SYMNAME(_ad1)(,%eax,4),%ecx - xorl SYMNAME(_ad1)(,%ebx,4),%edx - - movzbl 25(%esp),%eax - movzbl 29(%esp),%ebx - xorl SYMNAME(_ad2)(,%eax,4),%ecx - xorl SYMNAME(_ad2)(,%ebx,4),%edx - - movzbl 20(%esp),%eax - movzbl 24(%esp),%ebx - xorl SYMNAME(_ad3)(,%eax,4),%ecx - xorl SYMNAME(_ad3)(,%ebx,4),%edx - - movl %ecx, (%esp) - movl %edx, 4(%esp) - - movl $1+ 8(%ebp),%ecx - movl $1+12(%ebp),%edx - - movzbl 27(%esp),%eax - movzbl 31(%esp),%ebx - xorl SYMNAME(_ad0)(,%eax,4),%ecx - xorl SYMNAME(_ad0)(,%ebx,4),%edx - - movzbl 22(%esp),%eax - movzbl 26(%esp),%ebx - xorl SYMNAME(_ad1)(,%eax,4),%ecx - xorl SYMNAME(_ad1)(,%ebx,4),%edx - - movzbl 17(%esp),%eax - movzbl 21(%esp),%ebx - xorl SYMNAME(_ad2)(,%eax,4),%ecx - xorl SYMNAME(_ad2)(,%ebx,4),%edx - - movzbl 28(%esp),%eax - movzbl 16(%esp),%ebx - xorl SYMNAME(_ad3)(,%eax,4),%ecx - xorl SYMNAME(_ad3)(,%ebx,4),%edx - - movl %ecx, 8(%esp) - movl %edx,12(%esp) -') - -define(`dlr',` - movl 0(%ebp),%ecx - movl 4(%ebp),%edx - - movzbl 19(%esp),%eax - movzbl 23(%esp),%ebx - movl SYMNAME(_ad4)(,%eax,4),%eax - movl SYMNAME(_ad4)(,%ebx,4),%ebx - andl `$'0xff000000,%eax - andl `$'0xff000000,%ebx - xorl %eax,%ecx - xorl %ebx,%edx - - movzbl 30(%esp),%eax - movzbl 18(%esp),%ebx - movl SYMNAME(_ad4)(,%eax,4),%eax - movl SYMNAME(_ad4)(,%ebx,4),%ebx - andl `$'0xff0000,%eax - andl `$'0xff0000,%ebx - xorl %eax,%ecx - xorl %ebx,%edx - - movzbl 25(%esp),%eax - movzbl 29(%esp),%ebx - movl SYMNAME(_ad4)(,%eax,4),%eax - movl SYMNAME(_ad4)(,%ebx,4),%ebx - andl `$'0xff00,%eax - andl `$'0xff00,%ebx - xorl %eax,%ecx - xorl %ebx,%edx - - movzbl 20(%esp),%eax - movzbl 24(%esp),%ebx - movl SYMNAME(_ad4)(,%eax,4),%eax - movl SYMNAME(_ad4)(,%ebx,4),%ebx - andl `$'0xff,%eax - andl `$'0xff,%ebx - xorl %eax,%ecx - xorl %ebx,%edx - - movl %ecx, (%esp) - movl %edx, 4(%esp) - - movl 8(%ebp),%ecx - movl 12(%ebp),%edx - - movzbl 27(%esp),%eax - movzbl 31(%esp),%ebx - movl SYMNAME(_ad4)(,%eax,4),%eax - movl SYMNAME(_ad4)(,%ebx,4),%ebx - andl `$'0xff000000,%eax - andl `$'0xff000000,%ebx - xorl %eax,%ecx - xorl %ebx,%edx - - movzbl 22(%esp),%eax - movzbl 26(%esp),%ebx - movl SYMNAME(_ad4)(,%eax,4),%eax - movl SYMNAME(_ad4)(,%ebx,4),%ebx - andl `$'0xff0000,%eax - andl `$'0xff0000,%ebx - xorl %eax,%ecx - xorl %ebx,%edx - - movzbl 17(%esp),%eax - movzbl 21(%esp),%ebx - movl SYMNAME(_ad4)(,%eax,4),%eax - movl SYMNAME(_ad4)(,%ebx,4),%ebx - andl `$'0xff00,%eax - andl `$'0xff00,%ebx - xorl %eax,%ecx - xorl %ebx,%edx - - movzbl 28(%esp),%eax - movzbl 16(%esp),%ebx - movl SYMNAME(_ad4)(,%eax,4),%eax - movl SYMNAME(_ad4)(,%ebx,4),%ebx - andl `$'0xff,%eax - andl `$'0xff,%ebx - xorl %eax,%ecx - xorl %ebx,%edx - - movl %ecx, 8(%esp) - movl %edx,12(%esp) -') - -define(`dblock',` - sxrk - - dtfs(16) - dsft(32) - dtfs(48) - dsft(64) - dtfs(80) - dsft(96) - dtfs(112) - dsft(128) - dtfs(144) - - movl 256(%ebp),%eax - cmp `$'10,%eax - je $1 - - dsft(160) - dtfs(176) - - movl 256(%ebp),%eax - cmp `$'12,%eax - je $1 - - dsft(192) - dtfs(208) - - movl 256(%ebp),%eax - - .align 4 -$1: - sall `$'4,%eax - addl %eax,%ebp - - dlr -') - -C_FUNCTION_BEGIN(aesEncrypt) - pushl %edi - pushl %esi - pushl %ebp - pushl %ebx - - movl 20(%esp),%ebp - movl 24(%esp),%edi - movl 28(%esp),%esi - - subl `$'32,%esp - - eblock(LOCAL(00)) - - movl (%esp),%eax - movl 4(%esp),%ebx - movl 8(%esp),%ecx - movl 12(%esp),%edx - bswap %eax - bswap %ebx - bswap %ecx - bswap %edx - movl %eax, (%edi) - movl %ebx, 4(%edi) - movl %ecx, 8(%edi) - movl %edx,12(%edi) - - addl `$'32,%esp - - xorl %eax,%eax - - popl %ebx - popl %ebp - popl %esi - popl %edi - ret -C_FUNCTION_END(aesEncrypt) - - -C_FUNCTION_BEGIN(aesDecrypt) - pushl %edi - pushl %esi - pushl %ebp - pushl %ebx - - movl 20(%esp),%ebp - movl 24(%esp),%edi - movl 28(%esp),%esi - - subl `$'32,%esp - - dblock(LOCAL(01)) - - movl (%esp),%eax - movl 4(%esp),%ebx - movl 8(%esp),%ecx - movl 12(%esp),%edx - bswap %eax - bswap %ebx - bswap %ecx - bswap %edx - movl %eax, (%edi) - movl %ebx, 4(%edi) - movl %ecx, 8(%edi) - movl %edx,12(%edi) - - addl `$'32,%esp - - xorl %eax,%eax - - popl %ebx - popl %ebp - popl %esi - popl %edi - ret -C_FUNCTION_END(aesDecrypt) diff --git a/beecrypt/gas/aesopt.ppc.m4 b/beecrypt/gas/aesopt.ppc.m4 index 9299405..998f0f2 100644 --- a/beecrypt/gas/aesopt.ppc.m4 +++ b/beecrypt/gas/aesopt.ppc.m4 @@ -21,6 +21,7 @@ dnl License along with this library; if not, write to the Free Software dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA include(config.m4) +include(ASM_SRCDIR/asmdefs.m4) include(ASM_SRCDIR/ppc.m4) define(`s0',`r24') @@ -33,21 +34,10 @@ define(`t2',`r30') define(`t3',`r31') define(`sxrk',` -ifelse(ASM_BIGENDIAN,yes,` lwz s0, 0($2) lwz s1, 4($2) lwz s2, 8($2) lwz s3,12($2) -',` - li r0,0 - lwbrx s0,$2,r0 - li r0,4 - lwbrx s1,$2,r0 - li r0,8 - lwbrx s2,$2,r0 - li r0,13 - lwbrx s0,$2,r0 -') lwz r7, 0($1) lwz r8, 4($1) lwz r9, 8($1) @@ -63,7 +53,7 @@ define(`etfs',` lwz t1,$2+ 4($1) lwz t2,$2+ 8($1) lwz t3,$2+12($1) - +ifelse(ASM_BIGENDIAN,yes,` rlwinm r7,s0,10,22,29 rlwinm r8,s1,10,22,29 rlwinm r9,s2,10,22,29 @@ -121,6 +111,9 @@ define(`etfs',` xor t1,t1,r8 xor t2,t2,r9 xor t3,t3,r10 +',` + dnl to be done +') la r12,-3072(r12) ') @@ -130,7 +123,7 @@ define(`esft',` lwz s1,$2+ 4($1) lwz s2,$2+ 8($1) lwz s3,$2+12($1) - +ifelse(ASM_BIGENDIAN,yes,` rlwinm r7,t0,10,22,29 rlwinm r8,t1,10,22,29 rlwinm r9,t2,10,22,29 @@ -188,7 +181,9 @@ define(`esft',` xor s1,s1,r8 xor s2,s2,r9 xor s3,s3,r10 - +',` + dnl to be done +') la r12,-3072(r12) ') @@ -199,7 +194,7 @@ define(`elr',` lwz s3,12($1) la r12,4096(r12) - +ifdef(ASM_BIGENDIAN,yes,` rlwinm r7,t0,10,22,29 rlwinm r8,t1,10,22,29 rlwinm r9,t2,10,22,29 @@ -267,7 +262,9 @@ define(`elr',` xor s1,s1,r8 xor s2,s2,r9 xor s3,s3,r10 - +',` +dnl to be done +') la r12,-4096(r12) ') @@ -556,30 +553,33 @@ EXTERNAL_VARIABLE(_ad0) C_FUNCTION_BEGIN(aesEncrypt) subi r1,r1,32 - stmw r24,0(r1) + stw r24, 0(r1) + stw r25, 4(r1) + stw r26, 8(r1) + stw r27,12(r1) + stw r28,16(r1) + stw r29,20(r1) + stw r30,24(r1) + stw r31,28(r1) LOAD_ADDRESS(_ae0,r12) eblock(r3,r5,LOCAL(00)) -ifelse(ASM_BIGENDIAN,yes,` stw s0, 0(r4) stw s1, 4(r4) stw s2, 8(r4) stw s3,12(r4) -',` - li r0,0 - stwbrx s0,r4,r0 - li r0,4 - stwbrx s1,r4,r0 - li r0,8 - stwbrx s2,r4,r0 - li r0,12 - stwbrx s3,r4,r0 -') li r3,0 - lmw r24,0(r1) + lwzx 28(r1),r31 + lwzx 24(r1),r30 + lwzx 20(r1),r29 + lwzx 16(r1),r28 + lwzx 12(r1),r27 + lwzx 8(r1),r26 + lwzx 4(r1),r25 + lwzx 0(r1),r24 addi r1,r1,32 blr C_FUNCTION_END(aesEncrypt) @@ -593,21 +593,10 @@ C_FUNCTION_BEGIN(aesDecrypt) dblock(r3,r5,LOCAL(01)) -ifelse(ASM_BIGENDIAN,yes,` stw s0, 0(r4) stw s1, 4(r4) stw s2, 8(r4) stw s3,12(r4) -',` - li r0,0 - stwbrx s0,r4,r0 - li r0,4 - stwbrx s1,r4,r0 - li r0,8 - stwbrx s2,r4,r0 - li r0,12 - stwbrx s3,r4,r0 -') li r3,0 lmw r24,0(r1) diff --git a/beecrypt/gas/aesopt.x86.m4 b/beecrypt/gas/aesopt.x86.m4 index 30cf0ed..bf422ae 100644 --- a/beecrypt/gas/aesopt.x86.m4 +++ b/beecrypt/gas/aesopt.x86.m4 @@ -1,4 +1,5 @@ include(config.m4) +include(ASM_SRCDIR/asmdefs.m4) include(ASM_SRCDIR/x86.m4) ifdef(`USE_MMX',` diff --git a/beecrypt/gas/blowfishopt.i586.m4 b/beecrypt/gas/blowfishopt.i586.m4 index 4233738..adc965b 100644 --- a/beecrypt/gas/blowfishopt.i586.m4 +++ b/beecrypt/gas/blowfishopt.i586.m4 @@ -19,6 +19,7 @@ dnl License along with this library; if not, write to the Free Software dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA include(config.m4) +include(ASM_SRCDIR/asmdefs.m4) include(ASM_SRCDIR/x86.m4) dnl during this macro we assume: diff --git a/beecrypt/gas/blowfishopt.ppc.m4 b/beecrypt/gas/blowfishopt.ppc.m4 index 09c64e6..9218500 100644 --- a/beecrypt/gas/blowfishopt.ppc.m4 +++ b/beecrypt/gas/blowfishopt.ppc.m4 @@ -21,6 +21,7 @@ dnl License along with this library; if not, write to the Free Software dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA include(config.m4) +include(ASM_SRCDIR/asmdefs.m4) include(ASM_SRCDIR/ppc.m4) define(`round',` diff --git a/beecrypt/gas/fips180opt.ia64.S b/beecrypt/gas/fips180opt.ia64.S deleted file mode 100644 index a9c6eda..0000000 --- a/beecrypt/gas/fips180opt.ia64.S +++ /dev/null @@ -1,213 +0,0 @@ -/* - * fips180opt.ia64.S - * - * Assembler optimized SHA-1 routines for ia64 (Intel Itanium) - * - * Warning: this code is incomplete and only contains a rough prototype! - * - * Compile target is GNU Assembler - * - * Copyright (c) 2001 Virtual Unlimited B.V. - * - * Author: Bob Deblier - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#include "config.gas.h" - -#define saved_pfs r14 -#define saved_lc r15 - -#define param r16 - - .file "fips180opt.ia64.S" - - .text - - .equ K00, 0x5a827999 - .equ K20, 0x6ed9eba1 - .equ K40, 0x8f1bbcdc - .equ K60, 0xca62c1d6 - - .equ PARAM_H, 0 - .equ PARAM_DATA, 20 - -/* for optimization, I have to see how I can parallellize the code - - e = ROTL32(a, 5) + ((b&(c^d))^d) + e + w + K - b = ROTR32(b, 2); - -step1: load w, tmp0 = mix a, tmp1 = c xor d, e += K;; -step2: tmp0 >>= 27, tmp1 &= b, e += w, b = mix b;; -step3: b >>= 2, e += tmp0, tmp1 ^= d;; -step4: e += tmp1, load next w, tmp0 = mix d, tmp1 = b xor d, d += K;; -step5: etc. - - d = ROTL32(d, 5) + ((a&(b^c))^c) + d + w + K - a = ROTR32(a, 2) -*/ - - .macro subround1 a b c d e w - ld4 r19 = [\w],4 - add \e = $K00,\e - xor r21 = \c,\d - mix4.r r20 = \a,\a;; - add \e = \e,r19 - and r21 = r21,\b - shr.u r20 = 27,r20 - mix4.r r22 = \b,\b;; - add \e = r20,\e - xor r21 = r21,\d - shr.u \b = 2,r22;; - add \e = r21,\e - .endm - - .macro subround2 a b c d e w - ld4 r19 = [\w],4 - add \e = $K20,\e - xor r21 = \b,\c - mix4.r r20 = \a,\a;; - add \e = \e,r19 - xor r21 = r21,\d - shr.u r20 = 27,r20 - mix4.r \b = \b,\b;; - add \e = r20,\e - shr.u \b = 2,\b;; - add \e = r21,\e - .endm - - .macro subround3 a b c d e w - ld4 r19 = [\w],4 - add \e = $K40,\e - xor r21 = \b,\c - and r22 = \b,\c - mix4.r r20 = \a,\a;; - add \e = \e,r19 - and r21 = r21,\d - shr.u r20 = 27,r20 - mix4.r \b = \b,\b;; - add \e = r20,\e - or r21 = r21,r22 - shr.u \b = 2,\b;; - add \e = r21,\e - .endm - - .macro subround4 a b c d e w - ld4 r19 = [\w],4 - add \e = $K60,\e - xor r21 = \b,\c - mix4.r r20 = \a,\a;; - add \e = \e,r19 - xor r21 = r21,\d - shr.u r20 = 27,r20 - mix4.r \b = \b,\b;; - add \e = r20,\e - shr.u \b = 2,\b;; - add \e = r21,\e - .endm - - .align 32 - .global sha1Process# - .proc sha1Process# - -sha1Process: - alloc saved_pfs = ar.pfs,2,0,0,0 - mov saved_lc = ar.lc - -/* r16 will be h */ -/* r17 will be pdata */ -/* There must be something neat I can do to speed up expansion (xor/rotate) - - The following should work, if we use 24 rotating registers; speedup should be dramatic - preload with swapped values 0-15 - - rought draft: have to translate this to more precise rotating registers and predicates. - - /----------\ - |xor[2],[0]| - +----------+----------\ - |xor[8] |xor[3],[1]| - +----------+----------+----------\ - |xor[13] |xor[9] |xor[4],[2]| - +----------+----------+----------+----------\ - |mix4.r[16]|xor[14] |xor[10] |xor[5],[3]| - +----------+----------+----------+----------+-----------\ - |shr[16] |mix4.r[17]|xor[15] |xor[11] |xor[6],[4] | - +----------+----------+----------+----------+-----------+----------\ - |store[16] |shr[17] |mix4.r[18]|xor[16] |xor[12] |xor[7],[5]| - \----------+----------+----------+----------+-----------+----------+----------\ - |store[17] |shr[18] |mix4.r[19]|xor[17] |xor[13] |xor[8],[6]| - \----------+----------+----------+-----------+----------+----------+----------\ - |store[18] |shr[19] |mix4.r[20] |xor[18] |xor[14] |xor[9],[7]| - \----------+----------+-----------+----------+----------+----------+----------\ - | | | | | | | -*/ - alloc saved_pfs = ar.pfs,3,21,0,24 - - /* look into big-endian loads, followed by little-endian stores */ -#if !WORD_BIGENDIAN - // save UM.be - // set UM.be to one -#endif - /* -.L00: - ld4 r32 = [ra],4 - -br.ctop.sptk .L00;; -#if !WORD_BIGENDIAN - // restore UM.be - /* - mov ra = rd - mov rb = rd;; - add rb = 4,rd;; - st4 [ra],8 = r48 - st4 [rb],8 = r47;; - st4 [ra],8 = r46 - st4 [rb],8 = r45;; - st4 [ra],8 = r44 - st4 [rb],8 = r43;; - st4 [ra],8 = r42 - st4 [rb],8 = r41;; - st4 [ra],8 = r40 - st4 [rb],8 = r39;; - st4 [ra],8 = r38 - st4 [rb],8 = r37;; - st4 [ra],8 = r36 - st4 [rb],8 = r35;; - st4 [ra],8 = r34 - st4 [rb],8 = r33;; - */ -#endif - /* also add a conditional which will save the original swapped words! */ - /* the expansion loop will translate to something like this: */ -.L01: - /* put three xors together */ - (p16) xor r32 = r46,r48 - (p17) xor r33 = r33,r41 - (p18) xor r34 = r34,r37 - (p19) mix4.r r35 = r35,r35 - (p20) shr.u r36 = 31,r36 - (p21) st4 [],4 = r37 - br.ctop.sptk .L01;; - - etc. -*/ - mov ar.lc = r15 - mov ar.pfs = r14 - br.ret.sptk b0 - .endp sha1Process# - diff --git a/beecrypt/gas/mpopt.alpha.m4 b/beecrypt/gas/mpopt.alpha.m4 index c4001ea..1bbfd15 100644 --- a/beecrypt/gas/mpopt.alpha.m4 +++ b/beecrypt/gas/mpopt.alpha.m4 @@ -19,6 +19,7 @@ dnl License along with this library; if not, write to the Free Software dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA include(config.m4) +include(ASM_SRCDIR/asmdefs.m4) include(ASM_SRCDIR/alpha.m4) diff --git a/beecrypt/gas/mpopt.arm.m4 b/beecrypt/gas/mpopt.arm.m4 index a7dc677..dd298cf 100644 --- a/beecrypt/gas/mpopt.arm.m4 +++ b/beecrypt/gas/mpopt.arm.m4 @@ -19,6 +19,7 @@ dnl License along with this library; if not, write to the Free Software dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA include(config.m4) +include(ASM_SRCDIR/asmdefs.m4) C_FUNCTION_BEGIN(mpsetmul) diff --git a/beecrypt/gas/mpopt.ia64.m4 b/beecrypt/gas/mpopt.ia64.m4 index e55eedf..290fdb6 100644 --- a/beecrypt/gas/mpopt.ia64.m4 +++ b/beecrypt/gas/mpopt.ia64.m4 @@ -19,6 +19,7 @@ dnl License along with this library; if not, write to the Free Software dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA include(config.m4) +include(ASM_SRCDIR/asmdefs.m4) include(ASM_SRCDIR/ia64.m4) define(`sze',`r14') diff --git a/beecrypt/gas/mpopt.m68k.m4 b/beecrypt/gas/mpopt.m68k.m4 index 0cb2d4c..defc8f1 100644 --- a/beecrypt/gas/mpopt.m68k.m4 +++ b/beecrypt/gas/mpopt.m68k.m4 @@ -19,6 +19,7 @@ dnl License along with this library; if not, write to the Free Software dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA include(config.m4) +include(ASM_SRCDIR/asmdefs.m4) include(ASM_SRCDIR/m68k.m4) dnl works diff --git a/beecrypt/gas/mpopt.ppc.m4 b/beecrypt/gas/mpopt.ppc.m4 index 3406f35..54bb32b 100644 --- a/beecrypt/gas/mpopt.ppc.m4 +++ b/beecrypt/gas/mpopt.ppc.m4 @@ -14,11 +14,12 @@ dnl but WITHOUT ANY WARRANTY; without even the implied warranty of dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU dnl Lesser General Public License for more details. dnl -dnl You shoulwz have received a copy of the GNU Lesser General Public +dnl You should have received a copy of the GNU Lesser General Public dnl License along with this library; if not, write to the Free Software dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA include(config.m4) +include(ASM_SRCDIR/asmdefs.m4) include(ASM_SRCDIR/ppc.m4) diff --git a/beecrypt/gas/mpopt.ppc64.m4 b/beecrypt/gas/mpopt.ppc64.m4 index 8fdbdb0..348b101 100644 --- a/beecrypt/gas/mpopt.ppc64.m4 +++ b/beecrypt/gas/mpopt.ppc64.m4 @@ -19,6 +19,7 @@ dnl License along with this library; if not, write to the Free Software dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA include(config.m4) +include(ASM_SRCDIR/asmdefs.m4) include(ASM_SRCDIR/ppc64.m4) diff --git a/beecrypt/gas/mpopt.s390x.m4 b/beecrypt/gas/mpopt.s390x.m4 index c80380e..80816db 100644 --- a/beecrypt/gas/mpopt.s390x.m4 +++ b/beecrypt/gas/mpopt.s390x.m4 @@ -1,8 +1,8 @@ dnl mpopt.s390x.m4 dnl -dnl Copyright (c) 2003 Bob Deblier +dnl Copyright (c) 2003, 2004 Bob Deblier dnl -dnl Author: Bob Deblier +dnl Author: Bob Deblier dnl dnl This library is free software; you can redistribute it and/or dnl modify it under the terms of the GNU Lesser General Public @@ -19,6 +19,7 @@ dnl License along with this library; if not, write to the Free Software dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA include(config.m4) +include(ASM_SRCDIR/asmdefs.m4) C_FUNCTION_BEGIN(mpsetmul) @@ -67,9 +68,6 @@ LOCAL(mpaddmul_loop): C_FUNCTION_END(mpaddmul) -divert(-1) -dnl function fails; illegal instruction on mlgr -dnl I've tried many alternative, but nothing seems to work so far C_FUNCTION_BEGIN(mpaddsqrtrc) stmg %r6,%r7,48(%r15) sllg %r5,%r2,3 @@ -81,7 +79,7 @@ C_FUNCTION_BEGIN(mpaddsqrtrc) LOCAL(mpaddsqrtrc_loop): lg %r1,0(%r4,%r5) - mlgr %r1,%r1 + mlg %r0,0(%r4,%r5) algr %r1,%r2 alcgr %r0,%r7 xgr %r2,%r2 @@ -91,9 +89,9 @@ LOCAL(mpaddsqrtrc_loop): stg %r1,8(%r3,%r6) stg %r0,0(%r3,%r6) aghi %r5,-8 + aghi %r6,-16 jhe LOCAL(mpaddsqrtrc_loop) lmg %r6,%r7,48(%r15) br %r14 C_FUNCTION_END(mpaddsqrtrc) -divert(0) diff --git a/beecrypt/gas/mpopt.sparcv8.m4 b/beecrypt/gas/mpopt.sparcv8.m4 index f21b356..b5306e8 100644 --- a/beecrypt/gas/mpopt.sparcv8.m4 +++ b/beecrypt/gas/mpopt.sparcv8.m4 @@ -19,6 +19,7 @@ dnl License along with this library; if not, write to the Free Software dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA include(config.m4) +include(ASM_SRCDIR/asmdefs.m4) include(ASM_SRCDIR/sparc.m4) diff --git a/beecrypt/gas/mpopt.sparcv8plus.m4 b/beecrypt/gas/mpopt.sparcv8plus.m4 index f021cfa..44962b8 100644 --- a/beecrypt/gas/mpopt.sparcv8plus.m4 +++ b/beecrypt/gas/mpopt.sparcv8plus.m4 @@ -19,6 +19,7 @@ dnl License along with this library; if not, write to the Free Software dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA include(config.m4) +include(ASM_SRCDIR/asmdefs.m4) include(ASM_SRCDIR/sparc.m4) diff --git a/beecrypt/gas/mpopt.x86.m4 b/beecrypt/gas/mpopt.x86.m4 index f6d9651..278848c 100644 --- a/beecrypt/gas/mpopt.x86.m4 +++ b/beecrypt/gas/mpopt.x86.m4 @@ -19,6 +19,7 @@ dnl License along with this library; if not, write to the Free Software dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA include(config.m4) +include(ASM_SRCDIR/asmdefs.m4) include(ASM_SRCDIR/x86.m4) @@ -29,7 +30,7 @@ C_FUNCTION_BEGIN(mpzero) movl 12(%esp),%edi xorl %eax,%eax - repz stosl + repz; stosl popl %edi ret @@ -43,7 +44,7 @@ C_FUNCTION_BEGIN(mpfill) movl 12(%esp),%edi movl 16(%esp),%eax - repz stosl + repz; stosl popl %edi ret diff --git a/beecrypt/gas/mpopt.x86_64.m4 b/beecrypt/gas/mpopt.x86_64.m4 index 5a50661..515c84d 100644 --- a/beecrypt/gas/mpopt.x86_64.m4 +++ b/beecrypt/gas/mpopt.x86_64.m4 @@ -21,6 +21,7 @@ dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA .file "mpopt.s" include(config.m4) +include(ASM_SRCDIR/asmdefs.m4) include(ASM_SRCDIR/x86_64.m4) @@ -36,7 +37,7 @@ C_FUNCTION_END(mpzero) C_FUNCTION_BEGIN(mpfill) movq %rdi,%rcx movq %rsi,%rdi - movq %rdx,%rdi + movq %rdx,%rax repz stosq ret C_FUNCTION_END(mpfill) @@ -57,6 +58,121 @@ C_FUNCTION_BEGIN(mpodd) C_FUNCTION_END(mpodd) +C_FUNCTION_BEGIN(mpaddw) + movq %rdx,%rax + xorq %rdx,%rdx + leaq -8(%rsi,%rdi,8),%rsi + addq %rax,(%rsi) + decq %rdi + jz LOCAL(mpaddw_skip) + leaq -8(%rsi),%rsi + + .align 4 +LOCAL(mpaddw_loop): + adcq %rdx,(%rsi) + leaq -8(%rsi),%rsi + decq %rdi + jnz LOCAL(mpaddw_loop) +LOCAL(mpaddw_skip): + sbbq %rax,%rax + negq %rax + ret +C_FUNCTION_END(mpaddw) + + +C_FUNCTION_BEGIN(mpsubw) + movq %rdx,%rax + xorq %rdx,%rdx + leaq -8(%rsi,%rdi,8),%rsi + subq %rax,(%rsi) + decq %rdi + jz LOCAL(mpsubw_skip) + leaq -8(%rsi),%rsi + + .align 4 +LOCAL(mpsubw_loop): + sbbq %rdx,(%rsi) + leaq -8(%rsi),%rsi + decq %rdi + jnz LOCAL(mpsubw_loop) +LOCAL(mpsubw_skip): + sbbq %rax,%rax + negq %rax + ret +C_FUNCTION_END(mpsubw) + + +C_FUNCTION_BEGIN(mpadd) + xorq %r8,%r8 + decq %rdi + + .align 4 +LOCAL(mpadd_loop): + movq (%rdx,%rdi,8),%rax + movq (%rsi,%rdi,8),%r8 + adcq %rax,%r8 + movq %r8,(%rsi,%rdi,8) + decq %rdi + jns LOCAL(mpadd_loop) + + sbbq %rax,%rax + negq %rax + ret +C_FUNCTION_END(mpadd) + + +C_FUNCTION_BEGIN(mpsub) + xorq %r8,%r8 + decq %rdi + + .align 4 +LOCAL(mpsub_loop): + movq (%rdx,%rdi,8),%rax + movq (%rsi,%rdi,8),%r8 + sbbq %rax,%r8 + movq %r8,(%rsi,%rdi,8) + decq %rdi + jns LOCAL(mpsub_loop) + + sbbq %rax,%rax + negq %rax + ret +C_FUNCTION_END(mpsub) + + +C_FUNCTION_BEGIN(mpdivtwo) + leaq (%rsi,%rdi,8),%rsi + negq %rdi + xorq %rax,%rax + + .align 4 +LOCAL(mpdivtwo_loop): + rcrq `$'1,(%rsi,%rdi,8) + inc %rdi + jnz LOCAL(mpdivtwo_loop) + + ret +C_FUNCTION_END(mpdivtwo) + + +C_FUNCTION_BEGIN(mpmultwo) + xorq %rdx,%rdx + decq %rdi + + .align 4 +LOCAL(mpmultwo_loop): + movq (%rsi,%rdi,8),%rax + adcq %rax,%rax + movq %rax,(%rsi,%rdi,8) + decq %rdi + jns LOCAL(mpmultwo_loop) + + sbbq %rax,%rax + negq %rax + ret +C_FUNCTION_END(mpmultwo) + + C_FUNCTION_BEGIN(mpsetmul) movq %rcx,%r8 movq %rdi,%rcx @@ -106,3 +222,33 @@ LOCAL(mpaddmul_loop): movq %rdx,%rax ret C_FUNCTION_END(mpaddmul) + + +C_FUNCTION_BEGIN(mpaddsqrtrc) + movq %rdi,%rcx + movq %rsi,%rdi + movq %rdx,%rsi + + xorq %r8,%r8 + decq %rcx + + leaq (%rdi,%rcx,8),%rdi + leaq (%rdi,%rcx,8),%rdi + + .align 4 +LOCAL(mpaddsqrtrc_loop): + movq (%rsi,%rcx,8),%rax + mulq %rax + addq %r8,%rax + adcq `$'0,%rdx + addq %rax,8(%rdi) + adcq %rdx,0(%rdi) + sbbq %r8,%r8 + negq %r8 + subq `$'16,%rdi + decq %rcx + jns LOCAL(mpaddsqrtrc_loop) + + movq %r8,%rax + ret +C_FUNCTION_END(mpaddsqrtrc) diff --git a/beecrypt/gas/ppc.m4 b/beecrypt/gas/ppc.m4 index e22be6f..33ba0cc 100644 --- a/beecrypt/gas/ppc.m4 +++ b/beecrypt/gas/ppc.m4 @@ -18,10 +18,6 @@ dnl You should have received a copy of the GNU Lesser General Public dnl License along with this library; if not, write to the Free Software dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -ifelse(substr(ASM_OS,0,5),linux,` -define(USE_NUMERIC_REGISTERS) -') - ifelse(substr(ASM_OS,0,3),aix,` define(USE_NUMERIC_REGISTERS) undefine(`C_FUNCTION_BEGIN') @@ -47,7 +43,18 @@ L$1: .tc $1[TC],$1[RW] ') .machine "ppc" -',` +') + +ifelse(substr(ASM_OS,0,6),darwin,` +define(LOAD_ADDRESS,` + lis $2,hi16($1) + la $2,lo16($1)($2) +') +define(EXTERNAL_VARIABLE) +') + +ifelse(substr(ASM_OS,0,5),linux,` +define(USE_NUMERIC_REGISTERS) define(LOAD_ADDRESS,` lis $2,$1@ha la $2,$1@l($2) @@ -55,6 +62,7 @@ define(LOAD_ADDRESS,` define(EXTERNAL_VARIABLE) ') + ifdef(`USE_NUMERIC_REGISTERS',` define(r0,0) define(r1,1) diff --git a/beecrypt/gas/ppc64.m4 b/beecrypt/gas/ppc64.m4 index 38bec0e..a0b4268 100644 --- a/beecrypt/gas/ppc64.m4 +++ b/beecrypt/gas/ppc64.m4 @@ -19,6 +19,7 @@ dnl License along with this library; if not, write to the Free Software dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ifelse(substr(ASM_OS,0,3),aix,` +define(USE_NUMERIC_REGISTERS) undefine(`C_FUNCTION_BEGIN') define(C_FUNCTION_BEGIN,` .toc @@ -35,37 +36,73 @@ define(C_FUNCTION_END,` ') .machine "ppc64" +') + +ifelse(substr(ASM_OS,0,5),linux,` +define(USE_NUMERIC_REGISTERS) +dnl trampoline definitions from glibc-2.3.2/sysdeps/powerpc/powerpc64/dl-machine.h +undefine(`C_FUNCTION_BEGIN') +define(C_FUNCTION_BEGIN,` + .section .text + .align 2 + .globl .$1 + .type .$1,@function + .section ".opd","aw" + .align 3 + .globl $1 + .size $1,24 +$1: + .quad .$1,.TOC.@tocbase,0 + .previous +.$1: +') +undefine(`C_FUNCTION_END') +define(C_FUNCTION_END,` +.LT_$1: + .long 0 + .byte 0x00,0x0c,0x24,0x40,0x00,0x00,0x00,0x00 + .long .LT_$1 - .$1 + .short .LT_$1_name_end-.LT_$1_name_start +.LT_$1_name_start: + .ascii "$1" +.LT_$1_name_end: + .align 2 + .size .$1,. - .$1 + .previous +') +') - .set r0,0 - .set r1,1 - .set r2,2 - .set r3,3 - .set r4,4 - .set r5,5 - .set r6,6 - .set r7,7 - .set r8,8 - .set r9,9 - .set r10,10 - .set r11,11 - .set r12,12 - .set r13,13 - .set r14,14 - .set r15,15 - .set r16,16 - .set r17,17 - .set r18,18 - .set r19,19 - .set r20,20 - .set r21,21 - .set r22,22 - .set r23,23 - .set r24,24 - .set r25,25 - .set r26,26 - .set r27,27 - .set r28,28 - .set r29,29 - .set r30,30 - .set r31,31 +ifdef(`USE_NUMERIC_REGISTERS',` +define(r0,0) +define(r1,1) +define(r2,2) +define(r3,3) +define(r4,4) +define(r5,5) +define(r6,6) +define(r7,7) +define(r8,8) +define(r9,9) +define(r10,10) +define(r11,11) +define(r12,12) +define(r13,13) +define(r14,14) +define(r15,15) +define(r16,16) +define(r17,17) +define(r18,18) +define(r19,19) +define(r20,20) +define(r21,21) +define(r22,22) +define(r23,23) +define(r24,24) +define(r25,25) +define(r26,26) +define(r27,27) +define(r28,28) +define(r29,29) +define(r30,30) +define(r31,31) ') diff --git a/beecrypt/gas/sha1opt.x86.m4 b/beecrypt/gas/sha1opt.x86.m4 index 1784f5f..b2d9a3d 100644 --- a/beecrypt/gas/sha1opt.x86.m4 +++ b/beecrypt/gas/sha1opt.x86.m4 @@ -19,15 +19,16 @@ dnl License along with this library; if not, write to the Free Software dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA include(config.m4) +include(ASM_SRCDIR/asmdefs.m4) include(ASM_SRCDIR/x86.m4) - .equ K00, 0x5a827999 - .equ K20, 0x6ed9eba1 - .equ K40, 0x8f1bbcdc - .equ K60, 0xca62c1d6 + .set K00, 0x5a827999 + .set K20, 0x6ed9eba1 + .set K40, 0x8f1bbcdc + .set K60, 0xca62c1d6 - .equ PARAM_H, 0 - .equ PARAM_DATA, 20 + .set PARAM_H, 0 + .set PARAM_DATA, 20 define(`subround1',` movl $2,%ecx diff --git a/beecrypt/gnu.h b/beecrypt/gnu.h new file mode 100644 index 0000000..59133f8 --- /dev/null +++ b/beecrypt/gnu.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2003 Bob Deblier + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#ifndef _BEECRYPT_GNU_H +#define _BEECRYPT_GNU_H + +#include +#include + + +#include +#include +#include + +#include +#include +#include + +typedef pthread_cond_t bc_cond_t; +typedef pthread_mutex_t bc_mutex_t; +typedef pthread_t bc_thread_t; + + + + + + + + + + + + + +/* WARNING: overriding this value is dangerous; some assembler routines + * make assumptions about the size set by the configure script + */ +#if !defined(MP_WBITS) +# define MP_WBITS 64U +#endif + +#endif diff --git a/beecrypt/beecrypt.gnu.h.in b/beecrypt/gnu.h.in similarity index 79% rename from beecrypt/beecrypt.gnu.h.in rename to beecrypt/gnu.h.in index 0b1afee..6afe788 100644 --- a/beecrypt/beecrypt.gnu.h.in +++ b/beecrypt/gnu.h.in @@ -23,14 +23,20 @@ @INCLUDE_INTTYPES_H@ @INCLUDE_STDINT_H@ @INCLUDE_SYNCH_H@ +@INCLUDE_THREAD_H@ @INCLUDE_PTHREAD_H@ @INCLUDE_STDIO_H@ -@INCLUDE_STDLIB_H@ +@INCLUDE_STDLIB_H@ @INCLUDE_MALLOC_H@ @INCLUDE_STRING_H@ @INCLUDE_UNISTD_H@ +@INCLUDE_DLFCN_H@ -@TYPEDEF_BC_LOCK_T@ +@TYPEDEF_BC_COND_T@ +@TYPEDEF_BC_MUTEX_T@ +@TYPEDEF_BC_THREAD_T@ + +@TYPEDEF_SIZE_T@ @TYPEDEF_INT8_T@ @TYPEDEF_INT16_T@ @@ -42,7 +48,10 @@ @TYPEDEF_UINT32_T@ @TYPEDEF_UINT64_T@ -#if !defined(MP_WBITS) /* dangerous; some assembler routines make assumptions */ +/* WARNING: overriding this value is dangerous; some assembler routines + * make assumptions about the size set by the configure script + */ +#if !defined(MP_WBITS) # define MP_WBITS @MP_WBITS@ #endif diff --git a/beecrypt/hmac.c b/beecrypt/hmac.c index 448d86f..c28770a 100644 --- a/beecrypt/hmac.c +++ b/beecrypt/hmac.c @@ -27,11 +27,14 @@ * \ingroup HMAC_m */ -#include "system.h" -#include "hmac.h" -#include "mp.h" -#include "endianness.h" -#include "debug.h" +#define BEECRYPT_DLL_EXPORT + +#if HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/hmac.h" +#include "beecrypt/endianness.h" /*!\addtogroup HMAC_m * \{ @@ -43,6 +46,7 @@ int hmacSetup(byte* kxi, byte* kxo, const hashFunction* hash, hashFunctionParam* param, const byte* key, size_t keybits) { register unsigned int i; + size_t keybytes = keybits >> 3; /* if the key is too large, hash it first */ @@ -61,16 +65,12 @@ int hmacSetup(byte* kxi, byte* kxo, const hashFunction* hash, hashFunctionParam* if (hash->digest(param, kxi)) return -1; -/*@-mayaliasunique@*/ memcpy(kxo, kxi, keybytes = hash->digestsize); -/*@=mayaliasunique@*/ } else if (keybytes > 0) { -/*@-mayaliasunique@*/ memcpy(kxi, key, keybytes); memcpy(kxo, key, keybytes); -/*@=mayaliasunique@*/ } else return -1; diff --git a/beecrypt/hmac.h b/beecrypt/hmac.h index 6d18281..709bb07 100644 --- a/beecrypt/hmac.h +++ b/beecrypt/hmac.h @@ -26,7 +26,7 @@ #ifndef _HMAC_H #define _HMAC_H -#include "beecrypt.h" +#include "beecrypt/beecrypt.h" /*!\ingroup HMAC_m */ @@ -35,29 +35,16 @@ extern "C" { #endif -/** - */ -BEECRYPTAPI -int hmacSetup (byte* kxi, byte* kxo, const hashFunction* hash, hashFunctionParam* param, const byte* key, size_t keybits) - /*@modifies kxi, kxo, param @*/; +/* not used directly as keyed hash function, but instead used as generic methods */ -/** - */ BEECRYPTAPI -int hmacReset (const byte* kxi, const hashFunction* hash, hashFunctionParam* param) - /*@modifies param @*/; - -/** - */ +int hmacSetup ( byte*, byte*, const hashFunction*, hashFunctionParam*, const byte*, size_t); BEECRYPTAPI -int hmacUpdate(const hashFunction* hash, hashFunctionParam* param, const byte* data, size_t size) - /*@modifies param @*/; - -/** - */ +int hmacReset (const byte*, const hashFunction*, hashFunctionParam*); +BEECRYPTAPI +int hmacUpdate( const hashFunction*, hashFunctionParam*, const byte*, size_t); BEECRYPTAPI -int hmacDigest(const byte* kxo, const hashFunction* hash, hashFunctionParam* param, /*@out@*/ byte* data) - /*@modifies data @*/; +int hmacDigest( const byte*, const hashFunction*, hashFunctionParam*, byte*); #ifdef __cplusplus } diff --git a/beecrypt/hmacmd5.c b/beecrypt/hmacmd5.c index b953e6d..8977ef4 100644 --- a/beecrypt/hmacmd5.c +++ b/beecrypt/hmacmd5.c @@ -27,31 +27,32 @@ * \ingroup HMAC_m HMAC_md5_m */ -#include "system.h" -#include "hmacmd5.h" -#include "debug.h" +#define BEECRYPT_DLL_EXPORT + +#if HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/hmacmd5.h" /*!\addtogroup HMAC_md5_m * \{ */ -/*@-sizeoftype@*/ const keyedHashFunction hmacmd5 = { "HMAC-MD5", sizeof(hmacmd5Param), - 64U, - 4U * sizeof(uint32_t), - 64U, - 512U, - 32U, - (const keyedHashFunctionSetup) hmacmd5Setup, - (const keyedHashFunctionReset) hmacmd5Reset, - (const keyedHashFunctionUpdate) hmacmd5Update, - (const keyedHashFunctionDigest) hmacmd5Digest + 64, + 16, + 64, + 512, + 32, + (keyedHashFunctionSetup) hmacmd5Setup, + (keyedHashFunctionReset) hmacmd5Reset, + (keyedHashFunctionUpdate) hmacmd5Update, + (keyedHashFunctionDigest) hmacmd5Digest }; -/*@=sizeoftype@*/ -/*@-type@*/ /* fix: cast to (hashFunctionParam*) */ int hmacmd5Setup (hmacmd5Param* sp, const byte* key, size_t keybits) { return hmacSetup(sp->kxi, sp->kxo, &md5, &sp->mparam, key, keybits); @@ -71,7 +72,6 @@ int hmacmd5Digest(hmacmd5Param* sp, byte* data) { return hmacDigest(sp->kxo, &md5, &sp->mparam, data); } -/*@=type@*/ /*!\} */ diff --git a/beecrypt/hmacmd5.h b/beecrypt/hmacmd5.h index eafa7e7..fb151f1 100644 --- a/beecrypt/hmacmd5.h +++ b/beecrypt/hmacmd5.h @@ -26,8 +26,8 @@ #ifndef _HMACMD5_H #define _HMACMD5_H -#include "hmac.h" -#include "md5.h" +#include "beecrypt/hmac.h" +#include "beecrypt/md5.h" /*!\ingroup HMAC_md5_m */ @@ -42,46 +42,16 @@ typedef struct extern "C" { #endif -/** \ingroup HMAC_md5_m - */ -/*@observer@*/ /*@unchecked@*/ extern BEECRYPTAPI const keyedHashFunction hmacmd5; -/** \ingroup HMAC_md5_m - */ -/*@-exportlocal@*/ BEECRYPTAPI -int hmacmd5Setup (hmacmd5Param* sp, const byte* key, size_t keybits) - /*@globals md5 @*/ - /*@modifies sp @*/; -/*@=exportlocal@*/ - -/** \ingroup HMAC_md5_m - */ -/*@-exportlocal@*/ +int hmacmd5Setup (hmacmd5Param*, const byte*, size_t); BEECRYPTAPI -int hmacmd5Reset (hmacmd5Param* sp) - /*@globals md5 @*/ - /*@modifies sp @*/; -/*@=exportlocal@*/ - -/** \ingroup HMAC_md5_m - */ -/*@-exportlocal@*/ +int hmacmd5Reset (hmacmd5Param*); BEECRYPTAPI -int hmacmd5Update(hmacmd5Param* sp, const byte* data, size_t size) - /*@globals md5 @*/ - /*@modifies sp @*/; -/*@=exportlocal@*/ - -/** \ingroup HMAC_md5_m - */ -/*@-exportlocal@*/ +int hmacmd5Update(hmacmd5Param*, const byte*, size_t); BEECRYPTAPI -int hmacmd5Digest(hmacmd5Param* sp, byte* data) - /*@globals md5 @*/ - /*@modifies sp, data @*/; -/*@=exportlocal@*/ +int hmacmd5Digest(hmacmd5Param*, byte*); #ifdef __cplusplus } diff --git a/beecrypt/hmacsha1.c b/beecrypt/hmacsha1.c index ad8796a..f201a45 100644 --- a/beecrypt/hmacsha1.c +++ b/beecrypt/hmacsha1.c @@ -27,31 +27,32 @@ * \ingroup HMAC_m HMAC_sha1_m */ -#include "system.h" -#include "hmacsha1.h" -#include "debug.h" +#define BEECRYPT_DLL_EXPORT + +#if HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/hmacsha1.h" /*!\addtogroup HMAC_sha1_m * \{ */ -/*@-sizeoftype@*/ const keyedHashFunction hmacsha1 = { "HMAC-SHA-1", sizeof(hmacsha1Param), - 64U, - 5U * sizeof(uint32_t), - 64U, - 512U, - 32U, + 64, + 20, + 64, + 512, + 32, (keyedHashFunctionSetup) hmacsha1Setup, (keyedHashFunctionReset) hmacsha1Reset, (keyedHashFunctionUpdate) hmacsha1Update, (keyedHashFunctionDigest) hmacsha1Digest }; -/*@=sizeoftype@*/ -/*@-type@*/ /* fix: cast to (hashFunctionParam*) */ int hmacsha1Setup (hmacsha1Param* sp, const byte* key, size_t keybits) { return hmacSetup(sp->kxi, sp->kxo, &sha1, &sp->sparam, key, keybits); @@ -71,7 +72,6 @@ int hmacsha1Digest(hmacsha1Param* sp, byte* data) { return hmacDigest(sp->kxo, &sha1, &sp->sparam, data); } -/*@=type@*/ /*!\} */ diff --git a/beecrypt/hmacsha1.h b/beecrypt/hmacsha1.h index c710309..207f5df 100644 --- a/beecrypt/hmacsha1.h +++ b/beecrypt/hmacsha1.h @@ -26,8 +26,8 @@ #ifndef _HMACSHA1_H #define _HMACSHA1_H -#include "hmac.h" -#include "sha1.h" +#include "beecrypt/hmac.h" +#include "beecrypt/sha1.h" /*!\ingroup HMAC_sha1_m */ @@ -42,46 +42,16 @@ typedef struct extern "C" { #endif -/** \ingroup HMAC_sha1_m - */ -/*@observer@*/ /*@unchecked@*/ extern BEECRYPTAPI const keyedHashFunction hmacsha1; -/** \ingroup HMAC_sha1_m - */ -/*@-exportlocal@*/ BEECRYPTAPI -int hmacsha1Setup (hmacsha1Param* sp, const byte* key, size_t keybits) - /*@globals sha1 @*/ - /*@modifies sp @*/; -/*@=exportlocal@*/ - -/** \ingroup HMAC_sha1_m - */ -/*@-exportlocal@*/ +int hmacsha1Setup (hmacsha1Param*, const byte*, size_t); BEECRYPTAPI -int hmacsha1Reset (hmacsha1Param* sp) - /*@globals sha1 @*/ - /*@modifies sp @*/; -/*@=exportlocal@*/ - -/** \ingroup HMAC_sha1_m - */ -/*@-exportlocal@*/ +int hmacsha1Reset (hmacsha1Param*); BEECRYPTAPI -int hmacsha1Update(hmacsha1Param* sp, const byte* data, size_t size) - /*@globals sha1 @*/ - /*@modifies sp @*/; -/*@=exportlocal@*/ - -/** \ingroup HMAC_sha1_m - */ -/*@-exportlocal@*/ +int hmacsha1Update(hmacsha1Param*, const byte*, size_t); BEECRYPTAPI -int hmacsha1Digest(hmacsha1Param* sp, byte* data) - /*@globals sha1 @*/ - /*@modifies sp, data @*/; -/*@=exportlocal@*/ +int hmacsha1Digest(hmacsha1Param*, byte*); #ifdef __cplusplus } diff --git a/beecrypt/hmacsha256.c b/beecrypt/hmacsha256.c index 4c6a321..c20b95c 100644 --- a/beecrypt/hmacsha256.c +++ b/beecrypt/hmacsha256.c @@ -23,31 +23,32 @@ * \ingroup HMAC_m HMAC_sha256_m */ -#include "system.h" -#include "hmacsha256.h" -#include "debug.h" +#define BEECRYPT_DLL_EXPORT + +#if HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/hmacsha256.h" /*!\addtogroup HMAC_sha256_m * \{ */ -/*@-sizeoftype@*/ const keyedHashFunction hmacsha256 = { "HMAC-SHA-256", sizeof(hmacsha256Param), - 64U, - 8U * sizeof(uint32_t), - 64U, - 512U, - 32U, + 64, + 32, + 64, + 512, + 32, (keyedHashFunctionSetup) hmacsha256Setup, (keyedHashFunctionReset) hmacsha256Reset, (keyedHashFunctionUpdate) hmacsha256Update, (keyedHashFunctionDigest) hmacsha256Digest }; -/*@=sizeoftype@*/ -/*@-type@*/ /* fix: cast to (hashFunctionParam*) */ int hmacsha256Setup (hmacsha256Param* sp, const byte* key, size_t keybits) { return hmacSetup(sp->kxi, sp->kxo, &sha256, &sp->sparam, key, keybits); @@ -67,7 +68,6 @@ int hmacsha256Digest(hmacsha256Param* sp, byte* data) { return hmacDigest(sp->kxo, &sha256, &sp->sparam, data); } -/*@=type@*/ /*!\} */ diff --git a/beecrypt/hmacsha256.h b/beecrypt/hmacsha256.h index ee2f7f3..6ee6010 100644 --- a/beecrypt/hmacsha256.h +++ b/beecrypt/hmacsha256.h @@ -26,8 +26,8 @@ #ifndef _HMACSHA256_H #define _HMACSHA256_H -#include "hmac.h" -#include "sha256.h" +#include "beecrypt/hmac.h" +#include "beecrypt/sha256.h" /*!\ingroup HMAC_sha256_m */ @@ -42,46 +42,16 @@ typedef struct extern "C" { #endif -/** \ingroup HMAC_sha256_m - */ -/*@observer@*/ /*@checked@*/ extern BEECRYPTAPI const keyedHashFunction hmacsha256; -/** \ingroup HMAC_sha256_m - */ -/*@-exportlocal@*/ BEECRYPTAPI -int hmacsha256Setup (hmacsha256Param* sp, const byte* key, size_t keybits) - /*@globals sha256 @*/ - /*@modifies sp @*/; -/*@=exportlocal@*/ - -/** \ingroup HMAC_sha256_m - */ -/*@-exportlocal@*/ +int hmacsha256Setup (hmacsha256Param*, const byte*, size_t); BEECRYPTAPI -int hmacsha256Reset (hmacsha256Param* sp) - /*@globals sha256 @*/ - /*@modifies sp @*/; -/*@=exportlocal@*/ - -/** \ingroup HMAC_sha256_m - */ -/*@-exportlocal@*/ +int hmacsha256Reset (hmacsha256Param*); BEECRYPTAPI -int hmacsha256Update(hmacsha256Param* sp, const byte* data, size_t size) - /*@globals sha256 @*/ - /*@modifies sp @*/; -/*@=exportlocal@*/ - -/** \ingroup HMAC_sha256_m - */ -/*@-exportlocal@*/ +int hmacsha256Update(hmacsha256Param*, const byte*, size_t); BEECRYPTAPI -int hmacsha256Digest(hmacsha256Param* sp, byte* data) - /*@globals sha256 @*/ - /*@modifies sp, data @*/; -/*@=exportlocal@*/ +int hmacsha256Digest(hmacsha256Param*, byte*); #ifdef __cplusplus } diff --git a/beecrypt/java/.cvsignore b/beecrypt/java/.cvsignore deleted file mode 100644 index da7b481..0000000 --- a/beecrypt/java/.cvsignore +++ /dev/null @@ -1,5 +0,0 @@ -.deps -.libs -Makefile -Makefile.in -*.lo diff --git a/beecrypt/java/Makefile.am b/beecrypt/java/Makefile.am index ebdea22..6d51a66 100644 --- a/beecrypt/java/Makefile.am +++ b/beecrypt/java/Makefile.am @@ -18,20 +18,20 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # -LIBBEECRYPT_LT_CURRENT = 6 -LIBBEECRYPT_LT_AGE = 0 -LIBBEECRYPT_LT_REVISION = 0 - AUTOMAKE_OPTIONS = gnu no-dependencies -BEECRYPT_JAVA_OBJECTS = javaglue.lo +LIBBEECRYPT_JAVA_LT_CURRENT = 8 +LIBBEECRYPT_JAVA_LT_AGE = 2 +LIBBEECRYPT_JAVA_LT_REVISION = 0 -lib_LTLIBRARIES = libbeecrypt_java.la +INCLUDES = -I$(top_srcdir)/.. @JAVAINC@ -noinst_HEADERS = javaglue.h +libaltdir=$(prefix)/lib@LIBALT@ -libbeecrypt_java_la_SOURCES = javaglue.c +libalt_LTLIBRARIES = libbeecrypt_java.la -libbeecrypt_java_la_DEPENDENCIES = $(BEECRYPT_JAVA_OBJECTS) +noinst_HEADERS = javaglue.h -libbeecrypt_java_la_LDFLAGS = -no-undefined -version-info $(LIBBEECRYPT_LT_CURRENT):$(LIBBEECRYPT_LT_REVISION):$(LIBBEECRYPT_LT_AGE) +libbeecrypt_java_la_SOURCES = javaglue.c +libbeecrypt_java_la_LIBADD = $(top_builddir)/libbeecrypt.la +libbeecrypt_java_la_LDFLAGS = -no-undefined -version $(LIBBEECRYPT_JAVA_LT_CURRENT):$(LIBBEECRYPT_JAVA_LT_REVISION):$(LIBBEECRYPT_JAVA_LT_AGE) diff --git a/beecrypt/java/javaglue.c b/beecrypt/java/javaglue.c index f7ee9cb..316550e 100644 --- a/beecrypt/java/javaglue.c +++ b/beecrypt/java/javaglue.c @@ -4,8 +4,10 @@ # include "config.h" #endif -#include "beecrypt.h" -#include "blockmode.h" +#include "beecrypt/beecrypt.h" +#include "beecrypt/blockmode.h" +#include "beecrypt/mpnumber.h" +#include "beecrypt/mpbarrett.h" #if JAVAGLUE @@ -18,10 +20,6 @@ #include "javaglue.h" -#ifndef WORDS_BIGENDIAN -# define WORDS_BIGENDIAN 0 -#endif - static const char* JAVA_OUT_OF_MEMORY_ERROR = "java/lang/OutOfMemoryError"; static const char* JAVA_PROVIDER_EXCEPTION = "java/security/ProviderException"; static const char* JAVA_INVALID_KEY_EXCEPTION = "java/security/InvalidKeyException"; @@ -30,6 +28,46 @@ static const char* MSG_NO_SUCH_ALGORITHM = "algorithm not available"; static const char* MSG_NO_ENTROPY_SOURCE = "no entropy source"; static const char* MSG_INVALID_KEY = "invalid key"; +/* Utility functions */ + +static void jba_to_mpnumber(JNIEnv* env, jbyteArray input, mpnumber* n) +{ + jbyte* data = (*env)->GetByteArrayElements(env, input, (jboolean*) 0); + if (data == (jbyte*) 0) + { + jclass ex = (*env)->FindClass(env, JAVA_OUT_OF_MEMORY_ERROR); + if (ex) + (*env)->ThrowNew(env, ex, MSG_OUT_OF_MEMORY); + } + else + { + jsize len = (*env)->GetArrayLength(env, input); + size_t size = MP_BYTES_TO_WORDS(len + MP_WBYTES - 1); + + mpnsetbin(n, data, len); + } + (*env)->ReleaseByteArrayElements(env, input, data, JNI_ABORT); +} + +static void jba_to_mpbarrett(JNIEnv* env, jbyteArray input, mpbarrett* b) +{ + jbyte* data = (*env)->GetByteArrayElements(env, input, (jboolean*) 0); + if (data == (jbyte*) 0) + { + jclass ex = (*env)->FindClass(env, JAVA_OUT_OF_MEMORY_ERROR); + if (ex) + (*env)->ThrowNew(env, ex, MSG_OUT_OF_MEMORY); + } + else + { + jsize len = (*env)->GetArrayLength(env, input); + size_t size = MP_BYTES_TO_WORDS(len + MP_WBYTES - 1); + + mpbsetbin(b, data, len); + } + (*env)->ReleaseByteArrayElements(env, input, data, JNI_ABORT); +} + /* NativeMessageDigest */ jlong JNICALL Java_beecrypt_security_NativeMessageDigest_find(JNIEnv* env, jclass dummy, jstring algorithm) @@ -103,7 +141,6 @@ jbyteArray JNICALL Java_beecrypt_security_NativeMessageDigest_digest(JNIEnv* env jbyte* digest; int digestsize = (jsize) ((const hashFunction*) hash)->digestsize; - int digestwords = digestsize >> 2; digestArray = (*env)->NewByteArray(env, digestsize); digest = (*env)->GetByteArrayElements(env, digestArray, (jboolean*) 0); diff --git a/beecrypt/masm/.cvsignore b/beecrypt/masm/.cvsignore deleted file mode 100644 index 540cfea..0000000 --- a/beecrypt/masm/.cvsignore +++ /dev/null @@ -1,19 +0,0 @@ -.deps -.depend -.depend-done -.libs -Makefile -Makefile.in -config.cache -config.guess -config.log -config.status -config.sub -configure -libtool -ltconfig -ltmain.sh -*.o -*.lo -stamp-h -stamp-h.in diff --git a/beecrypt/md5.c b/beecrypt/md5.c index 88c226a..dd76607 100644 --- a/beecrypt/md5.c +++ b/beecrypt/md5.c @@ -23,35 +23,35 @@ * \ingroup HASH_m HASH_md5_m */ -#include "system.h" -#include "md5.h" -#include "mp.h" -#include "endianness.h" -#include "debug.h" +#define BEECRYPT_DLL_EXPORT + +#if HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/md5.h" +#include "beecrypt/endianness.h" /*!\addtogroup HASH_md5_m * \{ */ -/*@observer@*/ /*@unchecked@*/ -static uint32_t md5hinit[4] = { 0x67452301U, 0xefcdab89U, 0x98badcfeU, 0x10325476U }; +static uint32_t md5hinit[4] = { 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476 }; -/*@-sizeoftype@*/ const hashFunction md5 = { "MD5", sizeof(md5Param), - 64U, - 16U, + 64, + 16, (hashFunctionReset) md5Reset, (hashFunctionUpdate) md5Update, (hashFunctionDigest) md5Digest }; -/*@=sizeoftype@*/ int md5Reset(register md5Param* mp) { - memcpy(mp->h, md5hinit, sizeof(mp->h)); - memset(mp->data, 0, sizeof(mp->data)); + memcpy(mp->h, md5hinit, 4 * sizeof(uint32_t)); + memset(mp->data, 0, 16 * sizeof(uint32_t)); #if (MP_WBITS == 64) mpzero(1, mp->length); #elif (MP_WBITS == 32) @@ -188,21 +188,20 @@ int md5Update(md5Param* mp, const byte* data, size_t size) mpw add[1]; mpsetw(1, add, size); mplshift(1, add, 3); - (void) mpadd(1, mp->length, add); + mpadd(1, mp->length, add); #elif (MP_WBITS == 32) mpw add[2]; mpsetw(2, add, size); mplshift(2, add, 3); - (void) mpadd(2, mp->length, add); + mpadd(2, mp->length, add); #else # error #endif -/*@-type@*/ while (size > 0) { proclength = ((mp->offset + size) > 64U) ? (64U - mp->offset) : size; - memmove(((byte *) mp->data) + mp->offset, data, proclength); + memcpy(((byte *) mp->data) + mp->offset, data, proclength); size -= proclength; data += proclength; mp->offset += proclength; @@ -213,20 +212,15 @@ int md5Update(md5Param* mp, const byte* data, size_t size) mp->offset = 0; } } -/*@=type@*/ return 0; } -/** - */ static void md5Finish(md5Param* mp) - /*@modifies mp @*/ { register byte *ptr = ((byte *) mp->data) + mp->offset++; *(ptr++) = 0x80; -/*@-type@*/ if (mp->offset > 56) { while (mp->offset++ < 64) @@ -239,7 +233,6 @@ static void md5Finish(md5Param* mp) ptr = ((byte *) mp->data) + mp->offset; while (mp->offset++ < 56) *(ptr++) = 0; -/*@=type@*/ #if (MP_WBITS == 64) ptr[0] = (byte)(mp->length[0] ); @@ -268,29 +261,29 @@ static void md5Finish(md5Param* mp) mp->offset = 0; } -int md5Digest(md5Param* mp, byte* digest) +int md5Digest(md5Param* mp, byte* data) { md5Finish(mp); /* encode 4 integers little-endian style */ - digest[ 0] = (byte)(mp->h[0] ); - digest[ 1] = (byte)(mp->h[0] >> 8); - digest[ 2] = (byte)(mp->h[0] >> 16); - digest[ 3] = (byte)(mp->h[0] >> 24); - digest[ 4] = (byte)(mp->h[1] ); - digest[ 5] = (byte)(mp->h[1] >> 8); - digest[ 6] = (byte)(mp->h[1] >> 16); - digest[ 7] = (byte)(mp->h[1] >> 24); - digest[ 8] = (byte)(mp->h[2] ); - digest[ 9] = (byte)(mp->h[2] >> 8); - digest[10] = (byte)(mp->h[2] >> 16); - digest[11] = (byte)(mp->h[2] >> 24); - digest[12] = (byte)(mp->h[3] ); - digest[13] = (byte)(mp->h[3] >> 8); - digest[14] = (byte)(mp->h[3] >> 16); - digest[15] = (byte)(mp->h[3] >> 24); - - (void) md5Reset(mp); + data[ 0] = (byte)(mp->h[0] ); + data[ 1] = (byte)(mp->h[0] >> 8); + data[ 2] = (byte)(mp->h[0] >> 16); + data[ 3] = (byte)(mp->h[0] >> 24); + data[ 4] = (byte)(mp->h[1] ); + data[ 5] = (byte)(mp->h[1] >> 8); + data[ 6] = (byte)(mp->h[1] >> 16); + data[ 7] = (byte)(mp->h[1] >> 24); + data[ 8] = (byte)(mp->h[2] ); + data[ 9] = (byte)(mp->h[2] >> 8); + data[10] = (byte)(mp->h[2] >> 16); + data[11] = (byte)(mp->h[2] >> 24); + data[12] = (byte)(mp->h[3] ); + data[13] = (byte)(mp->h[3] >> 8); + data[14] = (byte)(mp->h[3] >> 16); + data[15] = (byte)(mp->h[3] >> 24); + + md5Reset(mp); return 0; } diff --git a/beecrypt/md5.h b/beecrypt/md5.h index 91f7177..2e5a6ff 100644 --- a/beecrypt/md5.h +++ b/beecrypt/md5.h @@ -20,20 +20,29 @@ /*!\file md5.h * \brief MD5 hash function. * \author Bob Deblier - * \ingroup HASH_m HASH_md5_m + * \ingroup HASH_m HASH_md5_m */ #ifndef _MD5_H #define _MD5_H -#include "beecrypt.h" +#include "beecrypt/beecrypt.h" -/*!\ingroup HASH_md5_m +/*!\brief Holds all the parameters necessary for the MD5 algorithm. + * \ingroup HASH_md5_h */ typedef struct { + /*!\var h + */ uint32_t h[4]; + /*!\var data + */ uint32_t data[16]; + /*!\var length + * \brief Multi-precision integer counter for the bits that have been + * processed so far. + */ #if (MP_WBITS == 64) mpw length[1]; #elif (MP_WBITS == 32) @@ -41,6 +50,10 @@ typedef struct #else # error #endif + /*!\var offset + * \brief Offset into \a data; points to the place where new data will be + * copied before it is processed. + */ uint32_t offset; } md5Param; @@ -48,58 +61,49 @@ typedef struct extern "C" { #endif -/** \ingroup HASH_md5_m - * Holds the full API description of the MD5 algorithm. +/*!\var sha1 + * \brief Holds the full API description of the MD5 algorithm. */ -/*@observer@*/ /*@checked@*/ extern BEECRYPTAPI const hashFunction md5; -/** \ingroup HASH_md5_m - * This function performs the MD5 hash algorithm on 64 byte blocks of data. - * @param mp hash parameter block +/*!\fn int md5Reset(md5Param* mp) + * \brief This function resets the parameter block so that it's ready for a + * new hash. + * \param mp The hash function's parameter block. + * \retval 0 on success. */ -/*@-exportlocal@*/ BEECRYPTAPI -void md5Process(md5Param* mp) - /*@modifies mp @*/; -/*@=exportlocal@*/ +void md5Process(md5Param* mp); -/** \ingroup HASH_md5_m - * This function resets the parameter block so that it's ready for a new hash. - * @param mp hash parameter block - * @return 0 on success +/*!\fn int md5Reset(md5Param* mp) + * \brief This function resets the parameter block so that it's ready for a + * new hash. + * \param mp The hash function's parameter block. + * \retval 0 on success. */ -/*@-exportlocal@*/ BEECRYPTAPI -int md5Reset (md5Param* mp) - /*@modifies mp @*/; -/*@=exportlocal@*/ +int md5Reset (md5Param* mp); -/** \ingroup HASH_md5_m - * This function should be used to pass successive blocks of data to be hashed. - * @param mp hash parameter block - * @param *data bytes to hash - * @param size no. of bytes to hash - * @return 0 on success +/*!\fn int md5Update(md5Param* mp, const byte* data, size_t size) + * \brief This function should be used to pass successive blocks of data + * to be hashed. + * \param mp The hash function's parameter block. + * \param data + * \param size + * \retval 0 on success. */ -/*@-exportlocal@*/ BEECRYPTAPI -int md5Update (md5Param* mp, const byte* data, size_t size) - /*@modifies mp @*/; -/*@=exportlocal@*/ +int md5Update (md5Param* mp, const byte* data, size_t size); -/** \ingroup HASH_md5_m - * This function finishes the current hash computation, returning the digest - * value in \a digest. - * @param mp hash parameter block - * @retval *digest 16 byte MD5 digest - * @return 0 on success +/*!\fn int md5Digest(md5Param* mp, byte* digest) + * \brief This function finishes the current hash computation and copies + * the digest value into \a digest. + * \param mp The hash function's parameter block. + * \param digest The place to store the 16-byte digest. + * \retval 0 on success. */ -/*@-exportlocal@*/ BEECRYPTAPI -int md5Digest (md5Param* mp, /*@out@*/ byte* digest) - /*@modifies mp, digest @*/; -/*@=exportlocal@*/ +int md5Digest (md5Param* mp, byte* digest); #ifdef __cplusplus } diff --git a/beecrypt/memchunk.c b/beecrypt/memchunk.c index a6dc139..c182957 100644 --- a/beecrypt/memchunk.c +++ b/beecrypt/memchunk.c @@ -1,6 +1,4 @@ /* - * memchunk.c - * * Copyright (c) 2001 Virtual Unlimited B.V. * * This library is free software; you can redistribute it and/or @@ -23,21 +21,22 @@ * \author Bob Deblier */ -#include "system.h" -#include "memchunk.h" -#include "debug.h" +#define BEECRYPT_DLL_EXPORT + +#if HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/memchunk.h" -/*@-compdef@*/ /* tmp->data is undefined */ memchunk* memchunkAlloc(size_t size) { - memchunk* tmp = (memchunk*) calloc(1, sizeof(*tmp)); + memchunk* tmp = (memchunk*) calloc(1, sizeof(memchunk)); if (tmp) { tmp->size = size; - /*@-mustfree@*/ /* tmp->data is OK */ tmp->data = (byte*) malloc(size); - /*@=mustfree@*/ if (tmp->data == (byte*) 0) { @@ -48,7 +47,23 @@ memchunk* memchunkAlloc(size_t size) return tmp; } -/*@=compdef@*/ + +void memchunkInit(memchunk* m) +{ + m->data = (byte*) 0; + m->size = 0; +} + +void memchunkWipe(memchunk* m) +{ + if (m) + { + if (m->data) + { + memset(m->data, 0, m->size); + } + } +} void memchunkFree(memchunk* m) { @@ -67,7 +82,6 @@ void memchunkFree(memchunk* m) memchunk* memchunkResize(memchunk* m, size_t size) { - /*@-branchstate@*/ if (m) { if (m->data) @@ -81,15 +95,10 @@ memchunk* memchunkResize(memchunk* m, size_t size) m = (memchunk*) 0; } else - /*@-nullderef@*/ m->size = size; - /*@=nullderef@*/ } - /*@=branchstate@*/ - /*@-nullret -compdef @*/ /* LCL: m->data might be NULL */ return m; - /*@=nullret =compdef@*/ } memchunk* memchunkClone(const memchunk* m) diff --git a/beecrypt/memchunk.h b/beecrypt/memchunk.h index 75e4f8f..4778b7c 100644 --- a/beecrypt/memchunk.h +++ b/beecrypt/memchunk.h @@ -23,12 +23,11 @@ #ifndef _MEMCHUNK_H #define _MEMCHUNK_H -#include "beecrypt.api.h" +#include "beecrypt/api.h" typedef struct { size_t size; -/*@only@*/ byte* data; } memchunk; @@ -36,28 +35,16 @@ typedef struct extern "C" { #endif -/** - */ -BEECRYPTAPI /*@only@*/ /*@null@*/ -memchunk* memchunkAlloc(size_t size) - /*@*/; - -/** - */ BEECRYPTAPI -/*@unused@*/ void memchunkFree(/*@only@*/ /*@null@*/memchunk* m) - /*@*/; - -/** - */ -BEECRYPTAPI /*@only@*/ /*@null@*/ -memchunk* memchunkResize(/*@only@*/ /*@null@*/memchunk* m, size_t size) - /*@*/; - -/** - */ -BEECRYPTAPI /*@only@*/ /*@null@*/ /*@unused@*/ -memchunk* memchunkClone(const memchunk* m); +memchunk* memchunkAlloc(size_t); +BEECRYPTAPI +void memchunkWipe(memchunk*); +BEECRYPTAPI +void memchunkFree(memchunk*); +BEECRYPTAPI +memchunk* memchunkResize(memchunk*, size_t); +BEECRYPTAPI +memchunk* memchunkClone(const memchunk*); #ifdef __cplusplus } diff --git a/beecrypt/mp.c b/beecrypt/mp.c index 2653638..82d272c 100644 --- a/beecrypt/mp.c +++ b/beecrypt/mp.c @@ -23,11 +23,14 @@ * \ingroup MP_m */ -#include "system.h" -#include "beecrypt.h" -#include "mpopt.h" -#include "mp.h" -#include "debug.h" +#define BEECRYPT_DLL_EXPORT + +#if HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/mp.h" +#include "beecrypt/mpopt.h" #ifndef ASM_MPZERO void mpzero(size_t size, mpw* data) @@ -269,7 +272,7 @@ int mplex(size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata) if (xsize > ysize) { register size_t diff = xsize - ysize; - return mpz(diff, xdata) && mple(ysize, xdata+diff, ydata); + return mpz(diff, xdata) && mple(ysize, xdata+ diff, ydata); } else if (xsize < ysize) { @@ -281,7 +284,6 @@ int mplex(size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata) } #endif - #ifndef ASM_MPISONE int mpisone(size_t size, const mpw* data) { @@ -346,7 +348,7 @@ int mpleone(size_t size, const mpw* data) #endif #ifndef ASM_MPMSBSET -int mpmsbset(/*@unused@*/ size_t size, const mpw* data) +int mpmsbset(size_t size, const mpw* data) { return (int)((*data) >> (MP_WBITS-1)); } @@ -360,7 +362,7 @@ int mplsbset(size_t size, const mpw* data) #endif #ifndef ASM_MPSETMSB -void mpsetmsb(/*@unused@*/ size_t size, mpw* data) +void mpsetmsb(size_t size, mpw* data) { *data |= MP_MSBMASK; } @@ -374,7 +376,7 @@ void mpsetlsb(size_t size, mpw* data) #endif #ifndef ASM_MPCLRMSB -void mpclrmsb(/*@unused@*/ size_t size, mpw* data) +void mpclrmsb(size_t size, mpw* data) { *data &= ~ MP_MSBMASK; } @@ -464,7 +466,7 @@ int mpaddw(size_t size, mpw* xdata, mpw y) load = *xdata; temp = load + 1; *(xdata--) = temp; - carry = (load > temp); + carry = (load > temp); } return carry; } @@ -497,9 +499,7 @@ int mpaddx(size_t xsize, mpw* xdata, size_t ysize, const mpw* ydata) if (xsize > ysize) { register size_t diff = xsize - ysize; -/*@-evalorder@*/ return mpaddw(diff, xdata, (mpw) mpadd(ysize, xdata+diff, ydata)); -/*@=evalorder@*/ } else { @@ -560,9 +560,7 @@ int mpsubx(size_t xsize, mpw* xdata, size_t ysize, const mpw* ydata) if (xsize > ysize) { register size_t diff = xsize - ysize; -/*@-evalorder@*/ return mpsubw(diff, xdata, (mpw) mpsub(ysize, xdata+diff, ydata)); -/*@=evalorder@*/ } else { @@ -576,7 +574,7 @@ int mpsubx(size_t xsize, mpw* xdata, size_t ysize, const mpw* ydata) void mpneg(size_t size, mpw* data) { mpnot(size, data); - (void) mpaddw(size, data, 1); + mpaddw(size, data, 1); } #endif @@ -822,9 +820,9 @@ void mpsqr(mpw* result, size_t size, const mpw* data) *(--result) = 0; - (void) mpmultwo(size << 1, result); + mpmultwo(size << 1, result); - (void) mpaddsqrtrc(size, result, data); + mpaddsqrtrc(size, result, data); } #endif @@ -954,13 +952,13 @@ void mplshift(size_t size, mpw* data, size_t count) if (words < size) { - register unsigned short lbits = (unsigned short) (count & (MP_WBITS-1)); + register short lbits = (short) (count & (MP_WBITS-1)); /* first do the shifting, then do the moving */ - if (lbits != 0) + if (lbits) { register mpw temp, carry = 0; - register unsigned int rbits = MP_WBITS - lbits; + register short rbits = MP_WBITS - lbits; register size_t i = size; while (i > words) @@ -988,13 +986,13 @@ void mprshift(size_t size, mpw* data, size_t count) if (words < size) { - register unsigned short rbits = (unsigned short) (count & (MP_WBITS-1)); + register short rbits = (short) (count & (MP_WBITS-1)); /* first do the shifting, then do the moving */ - if (rbits != 0) + if (rbits) { register mpw temp, carry = 0; - register unsigned int lbits = MP_WBITS - rbits; + register short lbits = MP_WBITS - rbits; register size_t i = 0; while (i < size-words) @@ -1020,7 +1018,7 @@ size_t mprshiftlsz(size_t size, mpw* data) { register mpw* slide = data+size-1; register size_t zwords = 0; /* counter for 'all zero bit' words */ - register unsigned int lbits, rbits = 0; /* counter for 'least significant zero' bits */ + register short lbits, rbits = 0; /* counter for 'least significant zero' bits */ register mpw temp, carry = 0; data = slide; @@ -1045,10 +1043,6 @@ size_t mprshiftlsz(size_t size, mpw* data) if ((rbits == 0) && (zwords == 0)) return 0; - /* shouldn't happen, but let's test anyway */ - if (size == 0) - return 0; - /* prepare right-shifting of data */ lbits = MP_WBITS - rbits; @@ -1077,13 +1071,13 @@ size_t mprshiftlsz(size_t size, mpw* data) /* try an alternate version here, with descending sizes */ /* also integrate lszcnt and rshift properly into one function */ #ifndef ASM_MPGCD_W -/** +/* * mpgcd_w * need workspace of (size) words */ void mpgcd_w(size_t size, const mpw* xdata, const mpw* ydata, mpw* result, mpw* wksp) { - register size_t shift = 0, temp; + register size_t shift, temp; if (mpge(size, xdata, ydata)) { @@ -1106,13 +1100,13 @@ void mpgcd_w(size_t size, const mpw* xdata, const mpw* ydata, mpw* result, mpw* while (mpnz(size, wksp)) { - (void) mprshiftlsz(size, wksp); - (void) mprshiftlsz(size, result); + mprshiftlsz(size, wksp); + mprshiftlsz(size, result); if (mpge(size, wksp, result)) - (void) mpsub(size, wksp, result); + mpsub(size, wksp, result); else - (void) mpsub(size, result, wksp); + mpsub(size, result, wksp); /* slide past zero words in both operands by increasing pointers and decreasing size */ if ((*wksp == 0) && (*result == 0)) @@ -1137,14 +1131,14 @@ void mpgcd_w(size_t size, const mpw* xdata, const mpw* ydata, mpw* result, mpw* #ifndef ASM_MPEXTGCD_W /* needs workspace of (6*size+6) words */ /* used to compute the modular inverse */ -int mpextgcd_w(size_t size, const mpw* xdata, const mpw* ndata, mpw* result, mpw* wksp) +int mpextgcd_w(size_t size, const mpw* xdata, const mpw* ydata, mpw* result, mpw* wksp) { /* - * For computing a modular inverse, pass the modulus as ndata and the number - * to be inverted as xdata. + * For computing a modular inverse, pass the modulus as xdata and the number + * to be inverted as ydata. * * Fact: if a element of Zn, then a is invertible if and only if gcd(a,n) = 1 - * Hence: if ndata is even, then x must be odd, otherwise the gcd(x,n) >= 2 + * Hence: if n is even, then a must be odd, otherwise the gcd(a,n) >= 2 * * The calling routine must guarantee this condition. */ @@ -1159,8 +1153,8 @@ int mpextgcd_w(size_t size, const mpw* xdata, const mpw* ndata, mpw* result, mpw mpw* cdata = bdata+sizep; mpw* ddata = cdata+sizep; - mpsetx(sizep, udata, size, ndata); - mpsetx(sizep, vdata, size, xdata); + mpsetx(sizep, udata, size, xdata); + mpsetx(sizep, vdata, size, ydata); mpzero(sizep, bdata); mpsetw(sizep, ddata, 1); @@ -1178,8 +1172,8 @@ int mpextgcd_w(size_t size, const mpw* xdata, const mpw* ndata, mpw* result, mpw if (mpodd(sizep, bdata) || (full && mpodd(sizep, adata))) { - if (full) (void) mpaddx(sizep, adata, size, xdata); - (void) mpsubx(sizep, bdata, size, ndata); + if (full) mpaddx(sizep, adata, size, ydata); + mpsubx(sizep, bdata, size, xdata); } if (full) mpsdivtwo(sizep, adata); @@ -1191,8 +1185,8 @@ int mpextgcd_w(size_t size, const mpw* xdata, const mpw* ndata, mpw* result, mpw if (mpodd(sizep, ddata) || (full && mpodd(sizep, cdata))) { - if (full) (void) mpaddx(sizep, cdata, size, xdata); - (void) mpsubx(sizep, ddata, size, ndata); + if (full) mpaddx(sizep, cdata, size, ydata); + mpsubx(sizep, ddata, size, xdata); } if (full) mpsdivtwo(sizep, cdata); @@ -1200,15 +1194,15 @@ int mpextgcd_w(size_t size, const mpw* xdata, const mpw* ndata, mpw* result, mpw } if (mpge(sizep, udata, vdata)) { - (void) mpsub(sizep, udata, vdata); - if (full) (void) mpsub(sizep, adata, cdata); - (void) mpsub(sizep, bdata, ddata); + mpsub(sizep, udata, vdata); + if (full) mpsub(sizep, adata, cdata); + mpsub(sizep, bdata, ddata); } else { - (void) mpsub(sizep, vdata, udata); - if (full) (void) mpsub(sizep, cdata, adata); - (void) mpsub(sizep, ddata, bdata); + mpsub(sizep, vdata, udata); + if (full) mpsub(sizep, cdata, adata); + mpsub(sizep, ddata, bdata); } if (mpz(sizep, udata)) { @@ -1216,13 +1210,20 @@ int mpextgcd_w(size_t size, const mpw* xdata, const mpw* ndata, mpw* result, mpw { if (result) { - mpsetx(size, result, sizep, ddata); if (*ddata & MP_MSBMASK) { /* keep adding the modulus until we get a carry */ - while (!mpadd(size, result, ndata)) - {}; + while (!mpaddx(sizep, ddata, size, xdata)); } + else + { + /* in some computations, d ends up > x, hence: + * keep subtracting n from d until d < x + */ + while (mpgtx(sizep, ddata, size, xdata)) + mpsubx(sizep, ddata, size, xdata); + } + mpsetx(size, result, sizep, ddata); } return 1; } @@ -1236,12 +1237,12 @@ int mpextgcd_w(size_t size, const mpw* xdata, const mpw* ndata, mpw* result, mpw mpw mppndiv(mpw xhi, mpw xlo, mpw y) { register mpw result = 0; - register unsigned int count = MP_WBITS; - register unsigned int carry = 0; + register short count = MP_WBITS; + register int carry = 0; while (count--) { - if (((unsigned)carry) | (unsigned)(xhi >= y)) + if (carry | (xhi >= y)) { xhi -= y; result++; @@ -1252,7 +1253,7 @@ mpw mppndiv(mpw xhi, mpw xlo, mpw y) xlo <<= 1; result <<= 1; } - if (((unsigned)carry) | (unsigned)(xhi >= y)) + if (carry | (xhi >= y)) { xhi -= y; result++; @@ -1275,22 +1276,20 @@ void mpmod(mpw* result, size_t xsize, const mpw* xdata, size_t ysize, const mpw* msw = *ynorm; mpcopy(xsize, rdata, xdata); if (mpge(ysize, rdata, ynorm)) - (void) mpsub(ysize, rdata, ynorm); + mpsub(ysize, rdata, ynorm); while (qsize--) { q = mppndiv(rdata[0], rdata[1], msw); -/*@-evalorder@*/ *workspace = mpsetmul(ysize, workspace+1, ynorm, q); -/*@=evalorder@*/ while (mplt(ysize+1, rdata, workspace)) { - (void) mpsubx(ysize+1, workspace, ysize, ynorm); + mpsubx(ysize+1, workspace, ysize, ynorm); q--; } - (void) mpsub(ysize+1, rdata, workspace); + mpsub(ysize+1, rdata, workspace); rdata++; } /* de-normalization steps */ @@ -1298,13 +1297,13 @@ void mpmod(mpw* result, size_t xsize, const mpw* xdata, size_t ysize, const mpw* { mpdivtwo(ysize, ynorm); if (mpge(ysize, rdata, ynorm)) - (void) mpsub(ysize, rdata, ynorm); + mpsub(ysize, rdata, ynorm); } } #endif #ifndef ASM_MPNDIVMOD -void mpndivmod(mpw* result, size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata, mpw* workspace) +void mpndivmod(mpw* result, size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata, register mpw* workspace) { /* result must be xsize+1 in length */ /* workspace must be ysize+1 in length */ @@ -1325,16 +1324,14 @@ void mpndivmod(mpw* result, size_t xsize, const mpw* xdata, size_t ysize, const { q = mppndiv(result[0], result[1], msw); -/*@-evalorder@*/ *workspace = mpsetmul(ysize, workspace+1, ydata, q); -/*@=evalorder@*/ while (mplt(ysize+1, result, workspace)) { - (void) mpsubx(ysize+1, workspace, ysize, ydata); + mpsubx(ysize+1, workspace, ysize, ydata); q--; } - (void) mpsub(ysize+1, result, workspace); + mpsub(ysize+1, result, workspace); *(result++) = q; } } @@ -1350,12 +1347,13 @@ void mpprintln(size_t size, const mpw* data) mpfprintln(stdout, size, data); } -void mpfprint(FILE * f, size_t size, const mpw* data) +void mpfprint(FILE* f, size_t size, const mpw* data) { if (data == (mpw*) 0) - return; + return; + if (f == (FILE*) 0) - f = stderr; + return; while (size--) { @@ -1373,20 +1371,21 @@ void mpfprint(FILE * f, size_t size, const mpw* data) # error #endif } - (void) fflush(f); + fflush(f); } -void mpfprintln(FILE * f, size_t size, const mpw* data) +void mpfprintln(FILE* f, size_t size, const mpw* data) { if (data == (mpw*) 0) - return; + return; + if (f == (FILE*) 0) - f = stderr; + return; while (size--) { #if (MP_WBITS == 32) - fprintf(f, "%08x", (unsigned) *(data++)); + fprintf(f, "%08x", *(data++)); #elif (MP_WBITS == 64) # if WIN32 fprintf(f, "%016I64x", *(data++)); @@ -1400,39 +1399,45 @@ void mpfprintln(FILE * f, size_t size, const mpw* data) #endif } fprintf(f, "\n"); - (void) fflush(f); + fflush(f); } int i2osp(byte *osdata, size_t ossize, const mpw* idata, size_t isize) { - size_t required = MP_WORDS_TO_BYTES(isize); + #if WORDS_BIGENDIAN + size_t max_bytes = MP_WORDS_TO_BYTES(isize); + #endif + size_t significant_bytes = (mpbits(isize, idata) + 7) >> 3; - /* check if size is large enough */ - if (ossize >= required) + /* verify that ossize is large enough to contain the significant bytes */ + if (ossize >= significant_bytes) { - /* yes, we can proceed */ - if (ossize > required) - { /* fill initial bytes with zero */ - memset(osdata, 0, ossize-required); - osdata += ossize-required; + /* looking good; check if we have more space than significant bytes */ + if (ossize > significant_bytes) + { /* fill most significant bytes with zero */ + memset(osdata, 0, ossize - significant_bytes); + osdata += ossize - significant_bytes; } - if (required) + if (significant_bytes) { /* fill remaining bytes with endian-adjusted data */ #if !WORDS_BIGENDIAN - while (required) - { - mpw w = *(idata++); - byte shift = MP_WBITS; + mpw w = idata[--isize]; + byte shift = 0; - while (shift != 0) + /* fill right-to-left; much easier than left-to-right */ + do + { + osdata[--significant_bytes] = (byte)(w >> shift); + shift += 8; + if (shift == MP_WBITS) { - shift -= 8; - *(osdata++) = (byte)(w >> shift); + shift = 0; + w = idata[--isize]; } - required -= MP_WBYTES; - } + } while (significant_bytes); #else - memcpy(osdata, idata, required); + /* just copy data past zero bytes */ + memcpy(osdata, ((byte*) idata) + (max_bytes - significant_bytes), significant_bytes); #endif } return 0; @@ -1440,38 +1445,51 @@ int i2osp(byte *osdata, size_t ossize, const mpw* idata, size_t isize) return -1; } -int os2ip(mpw* idata, size_t isize, const byte* osdata, /*@unused@*/ size_t ossize) +int os2ip(mpw* idata, size_t isize, const byte* osdata, size_t ossize) { - size_t required = MP_BYTES_TO_WORDS(isize + MP_WBYTES - 1); + size_t required; + + /* skip non-significant leading zero bytes */ + while (!(*osdata) && ossize) + { + osdata++; + ossize--; + } + + required = MP_BYTES_TO_WORDS(ossize + MP_WBYTES - 1); if (isize >= required) { - /* yes, we can proceed */ + /* yes, we have enough space and can proceed */ + mpw w = 0; + /* adjust counter so that the loop will start by skipping the proper + * amount of leading bytes in the first significant word + */ + byte b = (ossize % MP_WBYTES); + if (isize > required) { /* fill initials words with zero */ mpzero(isize-required, idata); idata += isize-required; } - if (required) - { /* fill remaining words with endian-adjusted data */ - #if !WORDS_BIGENDIAN - while (required) - { - mpw w = 0; - byte b = MP_WBYTES; - while (b--) - { - w <<= 8; - w |= *(osdata++); - } + if (b == 0) + b = MP_WBYTES; + + while (ossize--) + { + w <<= 8; + w |= *(osdata++); + b--; + + if (b == 0) + { *(idata++) = w; - required--; + w = 0; + b = MP_WBYTES; } - #else - memcpy(idata, osdata, MP_WORDS_TO_BYTES(required)); - #endif } + return 0; } return -1; diff --git a/beecrypt/mp.h b/beecrypt/mp.h index d0b765e..57a3e6c 100644 --- a/beecrypt/mp.h +++ b/beecrypt/mp.h @@ -41,8 +41,8 @@ #ifndef _MP_H #define _MP_H -#include "beecrypt.api.h" -#include "mpopt.h" +#include "beecrypt/api.h" +#include "beecrypt/mpopt.h" #define MP_HWBITS (MP_WBITS >> 1) #define MP_WBYTES (MP_WBITS >> 3) @@ -74,650 +74,615 @@ extern "C" { #endif -/** - */ -BEECRYPTAPI /*@unused@*/ -void mpcopy(size_t size, /*@out@*/ mpw* dst, const mpw* src) - /*@modifies dst @*/; #ifndef ASM_MPCOPY -# define mpcopy(size, dst, src) \ - /*@-aliasunique -mayaliasunique @*/ \ - memcpy(dst, src, MP_WORDS_TO_BYTES((unsigned)size)) \ - /*@=aliasunique =mayaliasunique @*/ +# define mpcopy(size, dst, src) memcpy(dst, src, MP_WORDS_TO_BYTES(size)) +#else +BEECRYPTAPI +void mpcopy(size_t size, mpw* dest, const mpw* src); #endif -/** - */ -BEECRYPTAPI /*@unused@*/ -void mpmove(size_t size, /*@out@*/ mpw* dst, const mpw* src) - /*@modifies dst @*/; #ifndef ASM_MPMOVE -# define mpmove(size, dst, src) memmove(dst, src, MP_WORDS_TO_BYTES((unsigned)size)) +# define mpmove(size, dst, src) memmove(dst, src, MP_WORDS_TO_BYTES(size)) +#else +BEECRYPTAPI +void mpmove(size_t size, mpw* dest, const mpw* src); #endif -/** - * This function zeroes a multi-precision integer of a given size. - * @param size The size of the multi-precision integer. - * @param data The multi-precision integer data. +/*!\fn void mpzero(size_t size, mpw* data) + * \brief This function zeroes a multi-precision integer of a given size. + * \param size The size of the multi-precision integer. + * \param data The multi-precision integer data. */ BEECRYPTAPI -void mpzero(size_t size, /*@out@*/ mpw* data) - /*@modifies data @*/; +void mpzero(size_t size, mpw* data); -/** - * This function fills each word of a multi-precision integer with a +/*!\fn void mpfill(size_t size, mpw* data, mpw fill) + * \brief This function fills each word of a multi-precision integer with a * given value. - * @param size The size of the multi-precision integer. - * @param data The multi-precision integer data. - * @param fill The value fill the data with. + * \param size The size of the multi-precision integer. + * \param data The multi-precision integer data. + * \param fill The value fill the data with. */ -BEECRYPTAPI /*@unused@*/ -void mpfill(size_t size, /*@out@*/ mpw* data, mpw fill) - /*@modifies data @*/; +BEECRYPTAPI +void mpfill(size_t size, mpw* data, mpw fill); -/** - * This function tests if a multi-precision integer is odd. - * @param size The size of the multi-precision integer. - * @param data The multi-precision integer data. - * @return 1 if odd, 0 if even +/*!\fn int mpodd(size_t size, const mpw* data) + * \brief This functions tests if a multi-precision integer is odd. + * \param size The size of the multi-precision integer. + * \param data The multi-precision integer data. + * \retval 1 if odd + * \retval 0 if even */ BEECRYPTAPI -int mpodd (size_t size, const mpw* data) - /*@*/; +int mpodd (size_t size, const mpw* data); -/** - * This function tests if a multi-precision integer is even. - * @param size The size of the multi-precision integer. - * @param data The multi-precision integer data. - * @return 1 if even, 0 if odd +/*!\fn int mpeven(size_t size, const mpw* data) + * \brief This function tests if a multi-precision integer is even. + * \param size The size of the multi-precision integer. + * \param data The multi-precision integer data. + * \retval 1 if even + * \retval 0 if odd */ BEECRYPTAPI -int mpeven(size_t size, const mpw* data) - /*@*/; +int mpeven(size_t size, const mpw* data); -/** - * This function tests if a multi-precision integer is zero. - * @param size The size of the multi-precision integer. - * @param data The multi-precision integer data. - * @return 1 if zero, 0 if not zero +/*!\fn int mpz(size_t size, const mpw* data) + * \brief This function tests if a multi-precision integer is zero. + * \param size The size of the multi-precision integer. + * \param data The multi-precision integer data. + * \retval 1 if zero + * \retval 0 if not zero */ BEECRYPTAPI -int mpz (size_t size, const mpw* data) - /*@*/; +int mpz (size_t size, const mpw* data); -/** - * This function tests if a multi-precision integer is not zero. - * @param size The size of the multi-precision integer. - * @param data The multi-precision integer data. - * @return 1 if not zero, 0 if zero +/*!\fn int mpnz(size_t size, const mpw* data) + * \brief This function tests if a multi-precision integer is not zero. + * \param size The size of the multi-precision integer. + * \param data The multi-precision integer data. + * \retval 1 if not zero + * \retval 0 if zero */ -/*@-exportlocal@*/ BEECRYPTAPI -int mpnz (size_t size, const mpw* data) - /*@*/; -/*@=exportlocal@*/ +int mpnz (size_t size, const mpw* data); -/** - * This function tests if two multi-precision integers of the same size +/*!\fn int mpeq(size_t size, const mpw* xdata, const mpw* ydata) + * \brief This function tests if two multi-precision integers of the same size * are equal. - * @param size The size of the multi-precision integers. - * @param xdata The first multi-precision integer. - * @param ydata The second multi-precision integer. - * @return 1 if equal, 0 if not equal + * \param size The size of the multi-precision integers. + * \param xdata The first multi-precision integer. + * \param ydata The second multi-precision integer. + * \retval 1 if equal + * \retval 0 if not equal */ BEECRYPTAPI -int mpeq (size_t size, const mpw* xdata, const mpw* ydata) - /*@*/; +int mpeq (size_t size, const mpw* xdata, const mpw* ydata); -/** - * This function tests if two multi-precision integers of the same size +/*!\fn int mpne(size_t size, const mpw* xdata, const mpw* ydata) + * \brief This function tests if two multi-precision integers of the same size * differ. - * @param size The size of the multi-precision integers. - * @param xdata The first multi-precision integer. - * @param ydata The second multi-precision integer. - * @return 1 if not equal, 0 if equal + * \param size The size of the multi-precision integers. + * \param xdata The first multi-precision integer. + * \param ydata The second multi-precision integer. + * \retval 1 if not equal + * \retval 0 if equal */ -/*@-exportlocal@*/ BEECRYPTAPI -int mpne (size_t size, const mpw* xdata, const mpw* ydata) - /*@*/; -/*@=exportlocal@*/ +int mpne (size_t size, const mpw* xdata, const mpw* ydata); -/** - * This function tests if the first of two multi-precision integers +/*!\fn int mpgt(size_t size, const mpw* xdata, const mpw* ydata) + * \brief This function tests if the first of two multi-precision integers * of the same size is greater than the second. - * @note The comparison treats the arguments as unsigned. - * @param size The size of the multi-precision integers. - * @param xdata The first multi-precision integer. - * @param ydata The second multi-precision integer. - * @return 1 if greater, 0 if less or equal + * \note The comparison treats the arguments as unsigned. + * \param size The size of the multi-precision integers. + * \param xdata The first multi-precision integer. + * \param ydata The second multi-precision integer. + * \retval 1 if greater + * \retval 0 if less or equal */ -/*@-exportlocal@*/ BEECRYPTAPI -int mpgt (size_t size, const mpw* xdata, const mpw* ydata) - /*@*/; -/*@=exportlocal@*/ +int mpgt (size_t size, const mpw* xdata, const mpw* ydata); -/** - * This function tests if the first of two multi-precision integers +/*!\fn int mplt(size_t size, const mpw* xdata, const mpw* ydata) + * \brief This function tests if the first of two multi-precision integers * of the same size is less than the second. - * @note The comparison treats the arguments as unsigned. - * @param size The size of the multi-precision integers. - * @param xdata The first multi-precision integer. - * @param ydata The second multi-precision integer. - * @return 1 if less, 0 if greater or equal + * \note The comparison treats the arguments as unsigned. + * \param size The size of the multi-precision integers. + * \param xdata The first multi-precision integer. + * \param ydata The second multi-precision integer. + * \retval 1 if less + * \retval 0 if greater or equal */ -/*@-exportlocal@*/ BEECRYPTAPI -int mplt (size_t size, const mpw* xdata, const mpw* ydata) - /*@*/; -/*@=exportlocal@*/ +int mplt (size_t size, const mpw* xdata, const mpw* ydata); -/** - * This function tests if the first of two multi-precision integers +/*!\fn int mpge(size_t size, const mpw* xdata, const mpw* ydata) + * \brief This function tests if the first of two multi-precision integers * of the same size is greater than or equal to the second. - * @note The comparison treats the arguments as unsigned. - * @param size The size of the multi-precision integers. - * @param xdata The first multi-precision integer. - * @param ydata The second multi-precision integer. - * @return 1 if greater or equal, 0 if less + * \note The comparison treats the arguments as unsigned. + * \param size The size of the multi-precision integers. + * \param xdata The first multi-precision integer. + * \param ydata The second multi-precision integer. + * \retval 1 if greater or equal + * \retval 0 if less */ BEECRYPTAPI -int mpge (size_t size, const mpw* xdata, const mpw* ydata) - /*@*/; +int mpge (size_t size, const mpw* xdata, const mpw* ydata); -/** - * This function tests if the first of two multi-precision integers +/*!\fn int mple(size_t size, const mpw* xdata, const mpw* ydata) + * \brief This function tests if the first of two multi-precision integers * of the same size is less than or equal to the second. - * @note The comparison treats the arguments as unsigned. - * @param size The size of the multi-precision integers. - * @param xdata The first multi-precision integer. - * @param ydata The second multi-precision integer. - * @return 1 if less or equal, 0 if greater + * \note The comparison treats the arguments as unsigned. + * \param size The size of the multi-precision integers. + * \param xdata The first multi-precision integer. + * \param ydata The second multi-precision integer. + * \retval 1 if less or equal + * \retval 0 if greater */ BEECRYPTAPI -int mple (size_t size, const mpw* xdata, const mpw* ydata) - /*@*/; +int mple (size_t size, const mpw* xdata, const mpw* ydata); -/** - * This function tests if two multi-precision integers of different +/*!\fn int mpeqx(size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata) + * \brief This function tests if two multi-precision integers of different * size are equal. - * @param xsize The size of the first multi-precision integer. - * @param xdata The first multi-precision integer. - * @param ysize The size of the first multi-precision integer. - * @param ydata The second multi-precision integer. - * @return 1 if equal, 0 if not equal - */ -BEECRYPTAPI -int mpeqx(size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata) - /*@*/; - -/** - * This function tests if two multi-precision integers of different - * size differ. - * @param xsize The size of the first multi-precision integer. - * @param xdata The first multi-precision integer. - * @param ysize The size of the first multi-precision integer. - * @param ydata The second multi-precision integer. - * @return 1 if not equal, 0 if equal - */ -BEECRYPTAPI /*@unused@*/ -int mpnex(size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata) - /*@*/; - -/** - * This function tests if the first of two multi-precision integers + * \param xsize The size of the first multi-precision integer. + * \param xdata The first multi-precision integer. + * \param ysize The size of the first multi-precision integer. + * \param ydata The second multi-precision integer. + * \retval 1 if equal + * \retval 0 if not equal + */ +BEECRYPTAPI +int mpeqx(size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata); + +/*!\fn int mpnex(size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata) + * \brief This function tests if two multi-precision integers of different + * size are equal. + * \param xsize The size of the first multi-precision integer. + * \param xdata The first multi-precision integer. + * \param ysize The size of the first multi-precision integer. + * \param ydata The second multi-precision integer. + * \retval 1 if equal + * \retval 0 if not equal +*/ +BEECRYPTAPI +int mpnex(size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata); + +/*!\fn int mpgtx(size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata) + * \brief This function tests if the first of two multi-precision integers * of different size is greater than the second. - * @note The comparison treats the arguments as unsigned. - * @param xsize The size of the first multi-precision integer. - * @param xdata The first multi-precision integer. - * @param ysize The size of the second multi-precision integer. - * @param ydata The second multi-precision integer. - * @return 1 if greater, 0 if less or equal - */ -BEECRYPTAPI /*@unused@*/ -int mpgtx(size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata) - /*@*/; - -/** - * This function tests if the first of two multi-precision integers + * \note The comparison treats the arguments as unsigned. + * \param xsize The size of the first multi-precision integer. + * \param xdata The first multi-precision integer. + * \param ysize The size of the second multi-precision integer. + * \param ydata The second multi-precision integer. + * \retval 1 if greater + * \retval 0 if less or equal + */ +BEECRYPTAPI +int mpgtx(size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata); + +/*!\fn int mpltx(size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata) + * \brief This function tests if the first of two multi-precision integers * of different size is less than the second. - * @note The comparison treats the arguments as unsigned. - * @param xsize The size of the first multi-precision integer. - * @param xdata The first multi-precision integer. - * @param ysize The size of the second multi-precision integer. - * @param ydata The second multi-precision integer. - * @return 1 if less, 0 if greater or equal - */ -BEECRYPTAPI /*@unused@*/ -int mpltx(size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata) - /*@*/; - -/** - * This function tests if the first of two multi-precision integers + * \note The comparison treats the arguments as unsigned. + * \param xsize The size of the first multi-precision integer. + * \param xdata The first multi-precision integer. + * \param ysize The size of the second multi-precision integer. + * \param ydata The second multi-precision integer. + * \retval 1 if less + * \retval 0 if greater or equal + */ +BEECRYPTAPI +int mpltx(size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata); + +/*!\fn int mpgex(size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata) + * \brief This function tests if the first of two multi-precision integers * of different size is greater than or equal to the second. - * @note The comparison treats the arguments as unsigned. - * @param xsize The size of the first multi-precision integer. - * @param xdata The first multi-precision integer. - * @param ysize The size of the second multi-precision integer. - * @param ydata The second multi-precision integer. - * @return 1 if greater or equal, 0 if less + * \note The comparison treats the arguments as unsigned. + * \param xsize The size of the first multi-precision integer. + * \param xdata The first multi-precision integer. + * \param ysize The size of the second multi-precision integer. + * \param ydata The second multi-precision integer. + * \retval 1 if greater or equal + * \retval 0 if less */ BEECRYPTAPI -int mpgex(size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata) - /*@*/; +int mpgex(size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata); -/** - * This function tests if the first of two multi-precision integers +/*!\fn int mplex(size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata) + * \brief This function tests if the first of two multi-precision integers * of different size is less than or equal to the second. - * @note The comparison treats the arguments as unsigned. - * @param xsize The size of the first multi-precision integer. - * @param xdata The first multi-precision integer. - * @param ysize The size of the second multi-precision integer. - * @param ydata The second multi-precision integer. - * @return 1 if less or equal, 0 if greater + * \note The comparison treats the arguments as unsigned. + * \param xsize The size of the first multi-precision integer. + * \param xdata The first multi-precision integer. + * \param ysize The size of the second multi-precision integer. + * \param ydata The second multi-precision integer. + * \retval 1 if less or equal + * \retval 0 if greater */ BEECRYPTAPI -int mplex(size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata) - /*@*/; +int mplex(size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata); -/** - * This function tests if the value of a multi-precision integer is +/*!\fn int mpisone(size_t size, const mpw* data) + * \brief This functions tests if the value of a multi-precision integer is * equal to one. - * @param size The size of the multi-precision integer. - * @param data The multi-precision integer data. - * @return 1 if equal to one, 0 otherwise. + * \param size The size of the multi-precision integer. + * \param data The multi-precision integer data. + * \retval 1 if one + * \retval 0 if not one */ BEECRYPTAPI -int mpisone(size_t size, const mpw* data) - /*@*/; +int mpisone(size_t size, const mpw* data); -/** - * This function tests if the value of a multi-precision integer is +/*!\fn int mpistwo(size_t size, const mpw* data) + * \brief This function tests if the value of a multi-precision integer is * equal to two. - * @param size The size of the multi-precision integer. - * @param data The multi-precision integer data. - * @return 1 if equal to two, 0 otherwise. + * \param size The size of the multi-precision integer. + * \param data The multi-precision integer data. + * \retval 1 if two + * \retval 0 if not two */ BEECRYPTAPI -int mpistwo(size_t size, const mpw* data) - /*@*/; +int mpistwo(size_t size, const mpw* data); -/** - * This function tests if the value of a multi-precision integer is +/*!\fn int mpleone(size_t size, const mpw* data); + * \brief This function tests if the value of a multi-precision integer is * less than or equal to one. - * @param size The size of the multi-precision integer. - * @param data The multi-precision integer data. - * @return 1 if less than or equal to one, 0 otherwise. + * \param size The size of the multi-precision integer. + * \param data The multi-precision integer data. + * \retval 1 if less than or equal to one. + * \retval 0 if greater than one. */ BEECRYPTAPI -int mpleone(size_t size, const mpw* data) - /*@*/; +int mpleone(size_t size, const mpw* data); -/** - * This function tests if multi-precision integer x is equal to y minus one. - * @param size The size of the multi-precision integers. - * @param xdata The first multi-precision integer. - * @param ydata The second multi-precision integer. - * @return 1 if less than or equal to (y-1), 0 otherwise. +/*!\fn int mpeqmone(size_t size, const mpw* xdata, const mpw* ydata); + * \brief This function tests if multi-precision integer x is equal to y + * minus one. + * \param size The size of the multi-precision integers. + * \param xdata The first multi-precision integer. + * \param ydata The second multi-precision integer. + * \retval 1 if less than or equal to one. + * \retval 0 if greater than one. */ -BEECRYPTAPI /*@unused@*/ -int mpeqmone(size_t size, const mpw* xdata, const mpw* ydata) - /*@*/; +BEECRYPTAPI +int mpeqmone(size_t size, const mpw* xdata, const mpw* ydata); -/** - * This function tests the most significant bit of a multi-precision integer. - * @param size The size of the multi-precision integer. - * @param data The multi-precision integer data. - * @return 1 if set, 0 if not set +/*!\fn int mpmsbset(size_t size, const mpw* data) + * \brief This function tests if the most significant bit of a multi-precision + * integer is set. + * \param size The size of the multi-precision integer. + * \param data The multi-precision integer data. + * \retval 1 if set + * \retval 0 if not set */ BEECRYPTAPI -int mpmsbset(size_t size, const mpw* data) - /*@*/; +int mpmsbset(size_t size, const mpw* data); -/** - * This function tests the least significant bit of a multi-precision integer. - * @param size The size of the multi-precision integer. - * @param data The multi-precision integer data. - * @return 1 if set, 0 if not set +/*!\fn int mplsbset(size_t size, const mpw* data) + * \brief This function tests if the leiast significant bit of a multi-precision + * integer is set. + * \param size The size of the multi-precision integer. + * \param data The multi-precision integer data. + * \retval 1 if set + * \retval 0 if not set */ -BEECRYPTAPI /*@unused@*/ -int mplsbset(size_t size, const mpw* data) - /*@*/; +BEECRYPTAPI +int mplsbset(size_t size, const mpw* data); -/** - * This function sets the most significant bit of a multi-precision integer. - * @param size The size of the multi-precision integer. - * @param data The multi-precision integer data. +/*!\fn void mpsetmsb(size_t size, mpw* data) + * \brief This function sets the most significant bit of a multi-precision + * integer. + * \param size The size of the multi-precision integer. + * \param data The multi-precision integer data. */ -BEECRYPTAPI /*@unused@*/ -void mpsetmsb(size_t size, mpw* data) - /*@modifies data @*/; +BEECRYPTAPI +void mpsetmsb(size_t size, mpw* data); -/** - * This function sets the least significant bit of a multi-precision integer. - * @param size The size of the multi-precision integer. - * @param data The multi-precision integer data. +/*!\fn void mpsetlsb(size_t size, mpw* data) + * \brief This function sets the least significant bit of a multi-precision + * integer. + * \param size The size of the multi-precision integer. + * \param data The multi-precision integer data. */ BEECRYPTAPI -void mpsetlsb(size_t size, mpw* data) - /*@modifies data @*/; +void mpsetlsb(size_t size, mpw* data); -/** - * This function clears the most significant bit of a multi-precision integer. - * @param size The size of the multi-precision integer. - * @param data The multi-precision integer data. +/*!\fn void mpclrmsb(size_t size, mpw* data) + * \brief This function clears the most significant bit of a multi-precision + * integer. + * \param size The size of the multi-precision integer. + * \param data The multi-precision integer data. */ -BEECRYPTAPI /*@unused@*/ -void mpclrmsb(size_t size, mpw* data) - /*@modifies data @*/; +BEECRYPTAPI +void mpclrmsb(size_t size, mpw* data); -/** - * This function clears the least significant bit of a multi-precision integer. - * @param size The size of the multi-precision integer. - * @param data The multi-precision integer data. +/*!\fn void mpclrlsb(size_t size, mpw* data) + * \brief This function clears the least significant bit of a multi-precision + * integer. + * \param size The size of the multi-precision integer. + * \param data The multi-precision integer data. */ -BEECRYPTAPI /*@unused@*/ -void mpclrlsb(size_t size, mpw* data) - /*@modifies data @*/; +BEECRYPTAPI +void mpclrlsb(size_t size, mpw* data); -/** +/*!\fn mpand(size_t size, mpw* xdata, const mpw* ydata) + * \brief This function computes the bit-wise AND of two multi-precision + * integers. Modifies xdata. + * \param size The size of the multi-precision integers. + * \param xdata The multi-precision integer data. + * \param ydata The multi-precision integer data. */ -BEECRYPTAPI /*@unused@*/ -void mpand(size_t size, mpw* xdata, const mpw* ydata) - /*@modifies xdata @*/; +BEECRYPTAPI +void mpand(size_t size, mpw* xdata, const mpw* ydata); -/** +/*!\fn void mpor(size_t size, mpw* xdata, const mpw* ydata) + * \brief This function computes the bit-wise OR of two multi-precision + * integers. Modifies xdata. + * \param size The size of the multi-precision integer. + * \param xdata The multi-precision integer data. + * \param ydata The multi-precision integer data. */ -BEECRYPTAPI /*@unused@*/ -void mpxor(size_t size, mpw* xdata, const mpw* ydata) - /*@modifies xdata @*/; +BEECRYPTAPI +void mpor(size_t size, mpw* xdata, const mpw* ydata); -/** +/*!\fn void mpxor(size_t size, mpw* xdata, const mpw* ydata) + * \brief This function computes the bit-wise XOR of two multi-precision + * integers. Modifies xdata. + * \param size The size of the multi-precision integer. + * \param xdata The multi-precision integer data. + * \param ydata The multi-precision integer data. */ -BEECRYPTAPI /*@unused@*/ -void mpor(size_t size, mpw* xdata, const mpw* ydata) - /*@modifies xdata @*/; +BEECRYPTAPI +void mpxor(size_t size, mpw* xdata, const mpw* ydata); -/** - * This function flips all bits of a multi-precision integer. - * @param size The size of the multi-precision integer. - * @param data The multi-precision integer data. +/*!\fn mpnot(size_t size, mpw* data) + * \brief This function flips all bits of a multi-precision integer. + * \param size The size of the multi-precision integer. + * \param data The multi-precision integer data. */ -/*@-exportlocal@*/ BEECRYPTAPI -void mpnot(size_t size, mpw* data) - /*@modifies data @*/; -/*@=exportlocal@*/ +void mpnot(size_t size, mpw* data); -/** +/*!\fn void mpsetw(size_t size, mpw* xdata, mpw y) + * \brief This function sets the value of a multi-precision integer to the + * given word. The given value is copied into the least significant word, + * while the most significant words are zeroed. + * \param size The size of the multi-precision integer. + * \param xdata The first multi-precision integer. + * \param y The multi-precision word. */ BEECRYPTAPI -void mpsetw(size_t size, /*@out@*/ mpw* xdata, mpw y) - /*@modifies xdata @*/; +void mpsetw(size_t size, mpw* xdata, mpw y); -/** +/*!\fn void mpsetx(size_t xsize, mpw* xdata, size_t ysize, const mpw* ydata) + * \brief This function set the value of the first multi-precision integer + * to the second, truncating the most significant words if ysize > xsize, or + * zeroing the most significant words if ysize < xsize. + * \param xsize The size of the first multi-precision integer. + * \param xdata The first multi-precision integer. + * \param ysize The size of the second multi-precision integer. + * \param ydata The second multi-precision integer. */ -BEECRYPTAPI -void mpsetx(size_t xsize, /*@out@*/ mpw* xdata, size_t ysize, const mpw* ydata) - /*@modifies xdata @*/; +void mpsetx(size_t xsize, mpw* xdata, size_t ysize, const mpw* ydata); -/** +/*!\fn int mpaddw(size_t size, mpw* xdata, mpw y) + * \brief This function adds one word to a multi-precision integer. + * The performed operation is in pseudocode: x += y. + * \param size The size of the multi-precision integer. + * \param xdata The first multi-precision integer. + * \param y The multi-precision word. + * \return The carry-over value of the operation; this value is either 0 or 1. */ BEECRYPTAPI -int mpaddw(size_t size, mpw* xdata, mpw y) - /*@modifies xdata @*/; +int mpaddw(size_t size, mpw* xdata, mpw y); -/** - * This function adds two multi-precision integers of equal size. - * The performed operation is in pseudocode: x += y - * @param size The size of the multi-precision integers. - * @param xdata The first multi-precision integer. - * @param ydata The second multi-precision integer. - * @return The carry-over value of the operation (either 0 or 1). +/*!\fn int mpadd(size_t size, mpw* xdata, const mpw* ydata) + * \brief This function adds two multi-precision integers of equal size. + * The performed operation is in pseudocode: x += y. + * \param size The size of the multi-precision integers. + * \param xdata The first multi-precision integer. + * \param ydata The second multi-precision integer. + * \return The carry-over value of the operation; this value is either 0 or 1. */ BEECRYPTAPI -int mpadd (size_t size, mpw* xdata, const mpw* ydata) - /*@modifies xdata @*/; +int mpadd (size_t size, mpw* xdata, const mpw* ydata); -/** +/*!\fn int mpaddx(size_t xsize, mpw* xdata, size_t ysize, const mpw* ydata) + * \brief This function adds two multi-precision integers of different size. + * The performed operation in pseudocode: x += y. + * \param xsize The size of the first multi-precision integer. + * \param xdata The first multi-precision integer. + * \param ysize The size of the second multi-precision integer. + * \param ydata The second multi-precision integer. + * \return The carry-over value of the operation; this value is either 0 or 1. */ BEECRYPTAPI -int mpaddx(size_t xsize, mpw* xdata, size_t ysize, const mpw* ydata) - /*@modifies xdata @*/; +int mpaddx(size_t xsize, mpw* xdata, size_t ysize, const mpw* ydata); -/** +/*!\fn int mpsubw(size_t size, mpw* xdata, mpw y) + * \brief This function subtracts one word to a multi-precision integer. + * The performed operation in pseudocode: x -= y + * \param size The size of the multi-precision integers. + * \param xdata The first multi-precision integer. + * \param y The multi-precision word. + * \return The carry-over value of the operation; this value is either 0 or 1. */ BEECRYPTAPI -int mpsubw(size_t size, mpw* xdata, mpw y) - /*@modifies xdata @*/; +int mpsubw(size_t size, mpw* xdata, mpw y); -/** +/*!\fn int mpsub(size_t size, mpw* xdata, const mpw* ydata) + * \brief This function subtracts two multi-precision integers of equal size. + * The performed operation in pseudocode: x -= y + * \param size The size of the multi-precision integers. + * \param xdata The first multi-precision integer. + * \param ydata The second multi-precision integer. + * \return The carry-over value of the operation; this value is either 0 or 1. */ BEECRYPTAPI -int mpsub (size_t size, mpw* xdata, const mpw* ydata) - /*@modifies xdata @*/; +int mpsub (size_t size, mpw* xdata, const mpw* ydata); -/** +/*!\fn int mpsubx(size_t xsize, mpw* xdata, size_t ysize, const mpw* ydata) + * \brief This function subtracts two multi-precision integers of different + * size. The performed operation in pseudocode: x -= y. + * \param xsize The size of the first multi-precision integer. + * \param xdata The first multi-precision integer. + * \param ysize The size of the second multi-precision integer. + * \param ydata The second multi-precision integer. + * \return The carry-over value of the operation; this value is either 0 or 1. */ BEECRYPTAPI -int mpsubx(size_t xsize, mpw* xdata, size_t ysize, const mpw* ydata) - /*@modifies xdata @*/; +int mpsubx(size_t xsize, mpw* xdata, size_t ysize, const mpw* ydata); -/** - */ BEECRYPTAPI -int mpmultwo(size_t size, mpw* data) - /*@modifies data @*/; +int mpmultwo(size_t size, mpw* data); -/** +/*!\fn void mpneg(size_t size, mpw* data) + * \brief This function negates a multi-precision integer. + * \param size The size of the multi-precision integer. + * \param data The multi-precision integer data. */ BEECRYPTAPI -void mpneg(size_t size, mpw* data) - /*@modifies data @*/; +void mpneg(size_t size, mpw* data); -/** +/*!\fn size_t mpsize(size_t size, const mpw* data) + * \brief This function returns the true size of a multi-precision + * integer, after stripping leading zero words. + * \param size The size of the multi-precision integer. + * \param data The multi-precision integer data. */ -BEECRYPTAPI /*@unused@*/ -size_t mpsize(size_t size, const mpw* data) - /*@*/; +BEECRYPTAPI +size_t mpsize(size_t size, const mpw* data); -/** +/*!\fn size_t mpbits(size_t size, const mpw* data) + * \brief This function returns the number of significant bits + * in a multi-precision integer. + * \param size The size of the multi-precision integer. + * \param data The multi-precision integer data. */ BEECRYPTAPI -size_t mpbits(size_t size, const mpw* data) - /*@*/; +size_t mpbits(size_t size, const mpw* data); -/** - */ BEECRYPTAPI -size_t mpmszcnt(size_t size, const mpw* data) - /*@*/; +size_t mpmszcnt(size_t size, const mpw* data); -/** - */ -/*@-exportlocal@*/ -BEECRYPTAPI /*@unused@*/ -size_t mplszcnt(size_t size, const mpw* data) - /*@*/; -/*@=exportlocal@*/ +BEECRYPTAPI +size_t mplszcnt(size_t size, const mpw* data); -/** - */ BEECRYPTAPI -void mplshift(size_t size, mpw* data, size_t count) - /*@modifies data @*/; +void mplshift(size_t size, mpw* data, size_t count); -/** - */ BEECRYPTAPI -void mprshift(size_t size, mpw* data, size_t count) - /*@modifies data @*/; +void mprshift(size_t size, mpw* data, size_t count); -/** - */ BEECRYPTAPI -size_t mprshiftlsz(size_t size, mpw* data) - /*@modifies data @*/; +size_t mprshiftlsz(size_t size, mpw* data); -/** - */ BEECRYPTAPI -size_t mpnorm(size_t size, mpw* data) - /*@modifies data @*/; +size_t mpnorm(size_t size, mpw* data); -/** - */ BEECRYPTAPI -void mpdivtwo (size_t size, mpw* data) - /*@modifies data @*/; +void mpdivtwo (size_t size, mpw* data); -/** - */ -/*@-exportlocal@*/ BEECRYPTAPI -void mpsdivtwo(size_t size, mpw* data) - /*@modifies data @*/; -/*@=exportlocal@*/ +void mpsdivtwo(size_t size, mpw* data); -/** - * This function performs a multi-precision multiply-setup. +/*!\fn mpw mpsetmul(size_t size, mpw* result, const mpw* data, mpw y) + * \brief This function performs a multi-precision multiply-setup. * * This function is used in the computation of a full multi-precision * multiplication. By using it we can shave off a few cycles; otherwise we'd * have to zero the least significant half of the result first and use * another call to the slightly slower mpaddmul function. * - * @param size The size of multi-precision integer multiplier. - * @param result The place where result will be accumulated. - * @param data The multi-precision integer multiplier. - * @param y The multiplicand. - * @return The carry-over multi-precision word. + * \param size The size of multi-precision integer multiplier. + * \param result The place where result will be accumulated. + * \param data The multi-precision integer multiplier. + * \param y The multiplicand. + * \return The carry-over multi-precision word. */ BEECRYPTAPI -mpw mpsetmul (size_t size, /*@out@*/ mpw* result, const mpw* data, mpw y) - /*@modifies result @*/; +mpw mpsetmul (size_t size, mpw* result, const mpw* data, mpw y); -/** - * This function performs a mult-precision multiply-accumulate. +/*!\fn mpw mpaddmul(size_t size, mpw* result, const mpw* data, mpw y) + * \brief This function performs a mult-precision multiply-accumulate. * * This function is used in the computation of a full multi-precision * multiplication. It computes the product-by-one-word and accumulates it with * the previous result. * - * @param size The size of multi-precision integer multiplier. - * @param result The place where result will be accumulated. - * @param data The multi-precision integer multiplier. - * @param y The multiplicand. - * @return The carry-over multi-precision word. + * \param size The size of multi-precision integer multiplier. + * \param result The place where result will be accumulated. + * \param data The multi-precision integer multiplier. + * \param y The multiplicand. + * \retval The carry-over multi-precision word. */ BEECRYPTAPI -mpw mpaddmul (size_t size, /*@out@*/ mpw* result, const mpw* data, mpw y) - /*@modifies result @*/; +mpw mpaddmul (size_t size, mpw* result, const mpw* data, mpw y); -/** - * This function is used in the calculation of a multi-precision +/*!\fn void mpaddsqrtrc(size_t size, mpw* result, const mpw* data) + * \brief This function is used in the calculation of a multi-precision * squaring. */ -/*@-exportlocal@*/ BEECRYPTAPI -void mpaddsqrtrc(size_t size, /*@out@*/ mpw* result, const mpw* data) - /*@modifies result @*/; -/*@=exportlocal@*/ +void mpaddsqrtrc(size_t size, mpw* result, const mpw* data); -/** - * This function computes a full multi-precision product. +/*!\fn void mpmul(mpw* result, size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata) + * \brief This function computes a full multi-precision product. */ BEECRYPTAPI -void mpmul(/*@out@*/ mpw* result, size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata) - /*@modifies result @*/; +void mpmul(mpw* result, size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata); -/** - * This function computes a full multi-precision square. +/*!\fn void mpsqr(mpw* result, size_t size, const mpw* data) + * \brief This function computes a full multi-precision square. */ BEECRYPTAPI -void mpsqr(/*@out@*/ mpw* result, size_t size, const mpw* data) - /*@modifies result @*/; +void mpsqr(mpw* result, size_t size, const mpw* data); -/** - */ BEECRYPTAPI -void mpgcd_w(size_t size, const mpw* xdata, const mpw* ydata, /*@out@*/ mpw* result, /*@out@*/ mpw* wksp) - /*@modifies result, wksp @*/; +void mpgcd_w(size_t size, const mpw* xdata, const mpw* ydata, mpw* result, mpw* wksp); -/** - */ BEECRYPTAPI -int mpextgcd_w(size_t size, const mpw* xdata, const mpw* ndata, /*@out@*/ mpw* result, /*@out@*/ mpw* wksp) - /*@modifies result, wksp @*/; +int mpextgcd_w(size_t size, const mpw* xdata, const mpw* ydata, mpw* result, mpw* wksp); -/** - */ -/*@-exportlocal@*/ BEECRYPTAPI -mpw mppndiv(mpw xhi, mpw xlo, mpw y) - /*@*/; -/*@=exportlocal@*/ +mpw mppndiv(mpw xhi, mpw xlo, mpw y); -/** - */ -BEECRYPTAPI /*@unused@*/ -void mpmod(/*@out@*/ mpw* result, size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata, /*@out@*/ mpw* workspace) - /*@modifies result, workspace @*/; +BEECRYPTAPI +void mpmod (mpw* result, size_t xsize, const mpw* xdata, size_t ysize, const mpw*ydata, mpw* wksp); -/** - */ BEECRYPTAPI -void mpndivmod(/*@out@*/ mpw* result, size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata, /*@out@*/ mpw* workspace) - /*@modifies result, workspace @*/; +void mpndivmod(mpw* result, size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata, mpw* wksp); -/** +/* + * Output Routines */ -BEECRYPTAPI /*@unused@*/ -void mpprint(size_t size, /*@null@*/ const mpw* data) - /*@globals stdout, fileSystem @*/ - /*@modifies stdout, fileSystem @*/; -/** - */ -BEECRYPTAPI /*@unused@*/ -void mpprintln(size_t size, /*@null@*/ const mpw* data) - /*@globals stdout, fileSystem @*/ - /*@modifies stdout, fileSystem @*/; +BEECRYPTAPI +void mpprint(size_t size, const mpw* data); -/** - */ -BEECRYPTAPI /*@unused@*/ -void mpfprint(/*@null@*/ FILE * f, size_t size, /*@null@*/ const mpw* data) - /*@globals fileSystem @*/ - /*@modifies *f, fileSystem @*/; +BEECRYPTAPI +void mpprintln(size_t size, const mpw* data); -/** - */ -/*@-exportlocal@*/ BEECRYPTAPI -void mpfprintln(/*@null@*/ FILE * f, size_t size, /*@null@*/ const mpw* data) - /*@globals fileSystem @*/ - /*@modifies *f, fileSystem @*/; -/*@=exportlocal@*/ +void mpfprint(FILE* f, size_t size, const mpw* data); -/** - */ BEECRYPTAPI -int i2osp(/*@out@*/ byte *osdata, size_t ossize, const mpw* idata, size_t isize) - /*@modifies osdata @*/; +void mpfprintln(FILE* f, size_t size, const mpw* data); -/** +/* + * Conversion Routines */ + BEECRYPTAPI -int os2ip(/*@out@*/ mpw *idata, size_t isize, const byte* osdata, size_t ossize) - /*@modifies idata @*/; +int os2ip(mpw* idata, size_t isize, const byte* osdata, size_t ossize); + +BEECRYPTAPI +int i2osp(byte* osdata, size_t ossize, const mpw* idata, size_t isize); -/** - */ BEECRYPTAPI -int hs2ip(/*@out@*/ mpw* idata, size_t isize, const char* hsdata, size_t hssize) - /*@modifies idata @*/; +int hs2ip(mpw* idata, size_t isize, const char* hsdata, size_t hssize); #ifdef __cplusplus } diff --git a/beecrypt/mpbarrett.c b/beecrypt/mpbarrett.c index ad56494..6a92b23 100644 --- a/beecrypt/mpbarrett.c +++ b/beecrypt/mpbarrett.c @@ -27,43 +27,43 @@ * \ingroup MP__m */ -#include "system.h" -#include "mp.h" -#include "mpprime.h" -#include "mpnumber.h" -#include "mpbarrett.h" -#include "debug.h" - -/** +#define BEECRYPT_DLL_EXPORT + +#if HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/beecrypt.h" +#include "beecrypt/mpprime.h" +#include "beecrypt/mpnumber.h" +#include "beecrypt/mpbarrett.h" + +/* * mpbzero */ void mpbzero(mpbarrett* b) { b->size = 0; - b->modl = (mpw*) 0; - b->mu = (mpw*) 0; + b->modl = b->mu = (mpw*) 0; } -/*@-nullstate@*/ /* b->modl may be null @*/ -/** - * Allocates the data words for an mpbarrett structure. - * will allocate 2*size+1 words +/* + * mpbinit + * \brief allocates the data words for an mpbarrett structure + * will allocate 2*size+1 words */ void mpbinit(mpbarrett* b, size_t size) { b->size = size; - if (b->modl) - free(b->modl); - b->modl = (mpw*) calloc(2*size+1, sizeof(*b->modl)); + b->modl = (mpw*) calloc(2*size+1, sizeof(mpw)); if (b->modl != (mpw*) 0) b->mu = b->modl+size; else b->mu = (mpw*) 0; } -/*@=nullstate@*/ -/** +/* * mpbfree */ void mpbfree(mpbarrett* b) @@ -71,13 +71,11 @@ void mpbfree(mpbarrett* b) if (b->modl != (mpw*) 0) { free(b->modl); - b->modl = (mpw*) 0; - b->mu = (mpw*) 0; + b->modl = b->mu = (mpw*) 0; } b->size = 0; } -/*@-nullstate -compdef @*/ /* b->modl may be null @*/ void mpbcopy(mpbarrett* b, const mpbarrett* copy) { register size_t size = copy->size; @@ -87,10 +85,10 @@ void mpbcopy(mpbarrett* b, const mpbarrett* copy) if (b->modl) { if (b->size != size) - b->modl = (mpw*) realloc(b->modl, (2*size+1) * sizeof(*b->modl)); + b->modl = (mpw*) realloc(b->modl, (2*size+1) * sizeof(mpw)); } else - b->modl = (mpw*) malloc((2*size+1) * sizeof(*b->modl)); + b->modl = (mpw*) malloc((2*size+1) * sizeof(mpw)); if (b->modl) { @@ -108,33 +106,35 @@ void mpbcopy(mpbarrett* b, const mpbarrett* copy) { free(b->modl); b->size = 0; - b->modl = (mpw*) 0; - b->mu = (mpw*) 0; + b->modl = b->mu = (mpw*) 0; } } -/*@=nullstate =compdef @*/ -/*@-nullstate -compdef @*/ /* b->modl may be null @*/ -/** +void mpbwipe(mpbarrett* b) +{ + if (b->modl != (mpw*) 0) + mpzero(2*(b->size)+1, b->modl); +} + +/* * mpbset */ -void mpbset(mpbarrett* b, size_t size, const mpw* data) +void mpbset(mpbarrett* b, size_t size, const mpw *data) { if (size > 0) { if (b->modl) { if (b->size != size) - b->modl = (mpw*) realloc(b->modl, (2*size+1) * sizeof(*b->modl)); + b->modl = (mpw*) realloc(b->modl, (2*size+1) * sizeof(mpw)); } else - b->modl = (mpw*) malloc((2*size+1) * sizeof(*b->modl)); + b->modl = (mpw*) malloc((2*size+1) * sizeof(mpw)); if (b->modl) { - mpw* temp = (mpw*) malloc((6*size+4) * sizeof(*temp)); + mpw* temp = (mpw*) malloc((6*size+4) * sizeof(mpw)); - assert(temp != NULL); b->size = size; b->mu = b->modl+size; mpcopy(size, b->modl, data); @@ -149,31 +149,68 @@ void mpbset(mpbarrett* b, size_t size, const mpw* data) } } } -/*@=nullstate =compdef @*/ -/*@-nullstate -compdef @*/ /* b->modl may be null @*/ -void mpbsethex(mpbarrett* b, const char* hex) +int mpbsetbin(mpbarrett* b, const byte* osdata, size_t ossize) { + int rc = -1; + size_t size; + + /* skip zero bytes */ + while (!(*osdata) && ossize) + { + osdata++; + ossize--; + } + + size = MP_BYTES_TO_WORDS(ossize + MP_WBYTES - 1); + + if (b->modl) + { + if (b->size != size) + b->modl = (mpw*) realloc(b->modl, (2*size+1) * sizeof(mpw)); + } + else + b->modl = (mpw*) malloc((2*size+1) * sizeof(mpw)); + + if (b->modl) + { + register mpw* temp = (mpw*) malloc((6*size+4) * sizeof(mpw)); + + b->size = size; + b->mu = b->modl+size; + + rc = os2ip(b->modl, size, osdata, ossize); + + mpbmu_w(b, temp); + + free(temp); + } + + return rc; +} + +int mpbsethex(mpbarrett* b, const char* hex) +{ + int rc = -1; size_t len = strlen(hex); size_t size = MP_NIBBLES_TO_WORDS(len + MP_WNIBBLES - 1); if (b->modl) { if (b->size != size) - b->modl = (mpw*) realloc(b->modl, (2*size+1) * sizeof(*b->modl)); + b->modl = (mpw*) realloc(b->modl, (2*size+1) * sizeof(mpw)); } else - b->modl = (mpw*) malloc((2*size+1) * sizeof(*b->modl)); + b->modl = (mpw*) malloc((2*size+1) * sizeof(mpw)); - if (b->modl != (mpw*) 0) + if (b->modl) { - register mpw* temp = (mpw*) malloc((6*size+4) * sizeof(*temp)); + register mpw* temp = (mpw*) malloc((6*size+4) * sizeof(mpw)); - assert(temp != NULL); b->size = size; b->mu = b->modl+size; - (void) hs2ip(b->modl, size, hex, len); + rc = hs2ip(b->modl, size, hex, len); mpbmu_w(b, temp); @@ -184,11 +221,13 @@ void mpbsethex(mpbarrett* b, const char* hex) b->size = 0; b->mu = 0; } + + return rc; } -/*@=nullstate =compdef @*/ -/** - * Computes the Barrett 'mu' coefficient. +/* + * mpbmu_w + * computes the Barrett 'mu' coefficient * needs workspace of (6*size+4) words */ void mpbmu_w(mpbarrett* b, mpw* wksp) @@ -205,15 +244,14 @@ void mpbmu_w(mpbarrett* b, mpw* wksp) *dividend = ((mpw) MP_LSBMASK << shift); mpzero(size*2, dividend+1); mpndivmod(divmod, size*2+1, dividend, size, b->modl, workspace); - /*@-nullpass@*/ /* b->mu may be NULL */ mpcopy(size+1, b->mu, divmod+1); - /*@=nullpass@*/ /* de-normalize */ mprshift(size, b->modl, shift); } -/** - * Generates a random number in the range 1 < r < b-1. +/* + * mpbrnd_w + * generates a random number in the range 1 < r < b-1 * need workspace of (size) words */ void mpbrnd_w(const mpbarrett* b, randomGeneratorContext* rc, mpw* result, mpw* wksp) @@ -221,25 +259,22 @@ void mpbrnd_w(const mpbarrett* b, randomGeneratorContext* rc, mpw* result, mpw* size_t msz = mpmszcnt(b->size, b->modl); mpcopy(b->size, wksp, b->modl); - (void) mpsubw(b->size, wksp, 1); + mpsubw(b->size, wksp, 1); do { - /*@-noeffectuncon@*/ /* LCL: ??? */ - (void) rc->rng->next(rc->param, (byte*) result, MP_WORDS_TO_BYTES(b->size)); - /*@=noeffectuncon@*/ + rc->rng->next(rc->param, (byte*) result, MP_WORDS_TO_BYTES(b->size)); - /*@-shiftimplementation -usedef@*/ result[0] &= (MP_ALLMASK >> msz); - /*@=shiftimplementation =usedef@*/ while (mpge(b->size, result, wksp)) - (void) mpsub(b->size, result, wksp); + mpsub(b->size, result, wksp); } while (mpleone(b->size, result)); } -/** - * Generates a random odd number in the range 1 < r < b-1. +/* + * mpbrndodd_w + * generates a random odd number in the range 1 < r < b-1 * needs workspace of (size) words */ void mpbrndodd_w(const mpbarrett* b, randomGeneratorContext* rc, mpw* result, mpw* wksp) @@ -247,29 +282,26 @@ void mpbrndodd_w(const mpbarrett* b, randomGeneratorContext* rc, mpw* result, mp size_t msz = mpmszcnt(b->size, b->modl); mpcopy(b->size, wksp, b->modl); - (void) mpsubw(b->size, wksp, 1); + mpsubw(b->size, wksp, 1); do { - /*@-noeffectuncon@*/ /* LCL: ??? */ - (void) rc->rng->next(rc->param, (byte*) result, MP_WORDS_TO_BYTES(b->size)); - /*@=noeffectuncon@*/ + rc->rng->next(rc->param, (byte*) result, MP_WORDS_TO_BYTES(b->size)); - /*@-shiftimplementation -usedef@*/ result[0] &= (MP_ALLMASK >> msz); - /*@=shiftimplementation =usedef@*/ mpsetlsb(b->size, result); while (mpge(b->size, result, wksp)) { - (void) mpsub(b->size, result, wksp); + mpsub(b->size, result, wksp); mpsetlsb(b->size, result); } } while (mpleone(b->size, result)); } -/** - * Generates a random invertible (modulo b) in the range 1 < r < b-1. +/* + * mpbrndinv_w + * generates a random invertible (modulo b) in the range 1 < r < b-1 * needs workspace of (6*size+6) words */ void mpbrndinv_w(const mpbarrett* b, randomGeneratorContext* rc, mpw* result, mpw* inverse, mpw* wksp) @@ -283,11 +315,12 @@ void mpbrndinv_w(const mpbarrett* b, randomGeneratorContext* rc, mpw* result, mp else mpbrnd_w(b, rc, result, wksp); - } while (mpextgcd_w(size, result, b->modl, inverse, wksp) == 0); + } while (mpextgcd_w(size, b->modl, result, inverse, wksp) == 0); } -/** - * Computes the barrett modular reduction of a number x, which has twice the size of b. +/* + * mpbmod_w + * computes the barrett modular reduction of a number x, which has twice the size of b * needs workspace of (2*size+2) words */ void mpbmod_w(const mpbarrett* b, const mpw* data, mpw* result, mpw* wksp) @@ -297,7 +330,6 @@ void mpbmod_w(const mpbarrett* b, const mpw* data, mpw* result, mpw* wksp) register const mpw* src = data+b->size+1; register mpw* dst = wksp+b->size+1; - /*@-nullpass@*/ /* b->mu may be NULL */ rc = mpsetmul(sp, dst, b->mu, *(--src)); *(--dst) = rc; @@ -319,7 +351,6 @@ void mpbmod_w(const mpbarrett* b, const mpw* data, mpw* result, mpw* wksp) } else *(--dst) = 0; - /*@=nullpass@*/ sp = b->size; rc = 0; @@ -327,35 +358,35 @@ void mpbmod_w(const mpbarrett* b, const mpw* data, mpw* result, mpw* wksp) dst = wksp+b->size+1; src = dst; - /*@-evalorder@*/ /* --src side effect, dst/src aliases */ *dst = mpsetmul(sp, dst+1, b->modl, *(--src)); - /*@=evalorder@*/ while (sp > 0) - (void) mpaddmul(sp--, dst, b->modl+(rc++), *(--src)); + mpaddmul(sp--, dst, b->modl+(rc++), *(--src)); mpsetx(b->size+1, wksp, b->size*2, data); - (void) mpsub(b->size+1, wksp, wksp+b->size+1); + mpsub(b->size+1, wksp, wksp+b->size+1); while (mpgex(b->size+1, wksp, b->size, b->modl)) - (void) mpsubx(b->size+1, wksp, b->size, b->modl); + mpsubx(b->size+1, wksp, b->size, b->modl); mpcopy(b->size, result, wksp+1); } -/** - * Copies (b-1) into result. +/* + * mpbsubone + * copies (b-1) into result */ void mpbsubone(const mpbarrett* b, mpw* result) { register size_t size = b->size; mpcopy(size, result, b->modl); - (void) mpsubw(size, result, 1); + mpsubw(size, result, 1); } -/** - * Computes the negative (modulo b) of x, where x must contain a value between 0 and b-1. +/* + * mpbneg + * computes the negative (modulo b) of x, where x must contain a value between 0 and b-1 */ void mpbneg(const mpbarrett* b, const mpw* data, mpw* result) { @@ -363,11 +394,12 @@ void mpbneg(const mpbarrett* b, const mpw* data, mpw* result) mpcopy(size, result, data); mpneg(size, result); - (void) mpadd(size, result, b->modl); + mpadd(size, result, b->modl); } -/** - * Computes the sum (modulo b) of x and y. +/* + * mpbaddmod_w + * computes the sum (modulo b) of x and y * needs a workspace of (4*size+2) words */ void mpbaddmod_w(const mpbarrett* b, size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata, mpw* result, mpw* wksp) @@ -377,13 +409,14 @@ void mpbaddmod_w(const mpbarrett* b, size_t xsize, const mpw* xdata, size_t ysiz register mpw* temp = wksp + size*2+2; mpsetx(2*size, temp, xsize, xdata); - (void) mpaddx(2*size, temp, ysize, ydata); + mpaddx(2*size, temp, ysize, ydata); mpbmod_w(b, temp, result, wksp); } -/** - * Computes the difference (modulo b) of x and y. +/* + * mpbsubmod_w + * computes the difference (modulo b) of x and y * needs a workspace of (4*size+2) words */ void mpbsubmod_w(const mpbarrett* b, size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata, mpw* result, mpw* wksp) @@ -391,16 +424,17 @@ void mpbsubmod_w(const mpbarrett* b, size_t xsize, const mpw* xdata, size_t ysiz /* xsize and ysize must be less than or equal to b->size */ register size_t size = b->size; register mpw* temp = wksp + size*2+2; - + mpsetx(2*size, temp, xsize, xdata); if (mpsubx(2*size, temp, ysize, ydata)) /* if there's carry, i.e. the result would be negative, add the modulus */ - (void) mpaddx(2*size, temp, size, b->modl); + mpaddx(2*size, temp, size, b->modl); mpbmod_w(b, temp, result, wksp); } -/** - * Computes the product (modulo b) of x and y. +/* + * mpmulmod_w + * computes the product (modulo b) of x and y * needs a workspace of (4*size+2) words */ void mpbmulmod_w(const mpbarrett* b, size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata, mpw* result, mpw* wksp) @@ -414,13 +448,12 @@ void mpbmulmod_w(const mpbarrett* b, size_t xsize, const mpw* xdata, size_t ysiz mpzero(fill, temp); mpmul(temp+fill, xsize, xdata, ysize, ydata); - /*@-compdef@*/ /* *temp undefined */ mpbmod_w(b, temp, result, wksp); - /*@=compdef@*/ } -/** - * Computes the square (modulo b) of x. +/* + * mpbsqrmod_w + * computes the square (modulo b) of x * needs a workspace of (4*size+2) words */ void mpbsqrmod_w(const mpbarrett* b, size_t xsize, const mpw* xdata, mpw* result, mpw* wksp) @@ -434,15 +467,10 @@ void mpbsqrmod_w(const mpbarrett* b, size_t xsize, const mpw* xdata, mpw* result mpzero(fill, temp); mpsqr(temp+fill, xsize, xdata); - /*@-compdef@*/ /* *temp undefined */ mpbmod_w(b, temp, result, wksp); - /*@=compdef@*/ } -/** - * Precomputes the sliding window table for computing powers of x modulo b. - * needs workspace (4*size+2) - * +/* * Sliding Window Exponentiation technique, slightly altered from the method Applied Cryptography: * * First of all, the table with the powers of g can be reduced by about half; the even powers don't @@ -454,30 +482,32 @@ void mpbsqrmod_w(const mpbarrett* b, size_t xsize, const mpw* xdata, mpw* result * and finally do the number of squarings in column three. * * This table can be used for K=2,3,4 and can be extended - * - * -\verbatim - 0 : - | - | - - 1 : 1 | g1 @ 0 | 0 - 10 : 1 | g1 @ 0 | 1 - 11 : 2 | g3 @ 1 | 0 - 100 : 1 | g1 @ 0 | 2 - 101 : 3 | g5 @ 2 | 0 - 110 : 2 | g3 @ 1 | 1 - 111 : 3 | g7 @ 3 | 0 - 1000 : 1 | g1 @ 0 | 3 - 1001 : 4 | g9 @ 4 | 0 - 1010 : 3 | g5 @ 2 | 1 - 1011 : 4 | g11 @ 5 | 0 - 1100 : 2 | g3 @ 1 | 2 - 1101 : 4 | g13 @ 6 | 0 - 1110 : 3 | g7 @ 3 | 1 - 1111 : 4 | g15 @ 7 | 0 -\endverbatim + * + * 0 : - | - | - + * 1 : 1 | g1 @ 0 | 0 + * 10 : 1 | g1 @ 0 | 1 + * 11 : 2 | g3 @ 1 | 0 + * 100 : 1 | g1 @ 0 | 2 + * 101 : 3 | g5 @ 2 | 0 + * 110 : 2 | g3 @ 1 | 1 + * 111 : 3 | g7 @ 3 | 0 + * 1000 : 1 | g1 @ 0 | 3 + * 1001 : 4 | g9 @ 4 | 0 + * 1010 : 3 | g5 @ 2 | 1 + * 1011 : 4 | g11 @ 5 | 0 + * 1100 : 2 | g3 @ 1 | 2 + * 1101 : 4 | g13 @ 6 | 0 + * 1110 : 3 | g7 @ 3 | 1 + * 1111 : 4 | g15 @ 7 | 0 * */ -static void mpbslide_w(const mpbarrett* b, size_t xsize, const mpw* xdata, /*@out@*/ mpw* slide, /*@out@*/ mpw* wksp) - /*@modifies slide, wksp @*/ + +/* + * mpbslide_w + * precomputes the sliding window table for computing powers of x modulo b + * needs workspace (4*size+2) + */ +void mpbslide_w(const mpbarrett* b, size_t xsize, const mpw* xdata, mpw* slide, mpw* wksp) { register size_t size = b->size; mpbsqrmod_w(b, xsize, xdata, slide , wksp); /* x^2 mod b, temp */ @@ -491,20 +521,16 @@ static void mpbslide_w(const mpbarrett* b, size_t xsize, const mpw* xdata, /*@ou mpsetx(size, slide, xsize, xdata); /* x^1 mod b */ } -/*@observer@*/ /*@unchecked@*/ -static byte mpbslide_presq[16] = +static byte mpbslide_presq[16] = { 0, 1, 1, 2, 1, 3, 2, 3, 1, 4, 3, 4, 2, 4, 3, 4 }; -/*@observer@*/ /*@unchecked@*/ static byte mpbslide_mulg[16] = { 0, 0, 0, 1, 0, 2, 1, 3, 0, 4, 2, 5, 1, 6, 3, 7 }; -/*@observer@*/ /*@unchecked@*/ static byte mpbslide_postsq[16] = { 0, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0 }; -/** - * mpbpowmod_w +/* * needs workspace of 4*size+2 words */ void mpbpowmod_w(const mpbarrett* b, size_t xsize, const mpw* xdata, size_t psize, const mpw* pdata, mpw* result, mpw* wksp) @@ -517,9 +543,9 @@ void mpbpowmod_w(const mpbarrett* b, size_t xsize, const mpw* xdata, size_t psiz */ /* K == 4 for the first try */ - + size_t size = b->size; - mpw temp = 0; + mpw temp; while (psize) { @@ -531,14 +557,11 @@ void mpbpowmod_w(const mpbarrett* b, size_t xsize, const mpw* xdata, size_t psiz /* if temp is still zero, then we're trying to raise x to power zero, and result stays one */ if (temp) { - mpw* slide = (mpw*) malloc((8*size)*sizeof(*slide)); + mpw* slide = (mpw*) malloc((8*size)*sizeof(mpw)); - assert(slide != NULL); mpbslide_w(b, xsize, xdata, slide, wksp); - /*@-internalglobs -mods@*/ /* noisy */ mpbpowmodsld_w(b, slide, psize, pdata-1, result, wksp); - /*@=internalglobs =mods@*/ free(slide); } @@ -552,7 +575,7 @@ void mpbpowmodsld_w(const mpbarrett* b, const mpw* slide, size_t psize, const mp */ size_t size = b->size; - mpw temp = 0; + mpw temp; mpsetw(size, result, 1); @@ -566,10 +589,10 @@ void mpbpowmodsld_w(const mpbarrett* b, const mpw* slide, size_t psize, const mp /* if temp is still zero, then we're trying to raise x to power zero, and result stays one */ if (temp) { - unsigned int l = 0, n = 0, count = MP_WBITS; + short l = 0, n = 0, count = MP_WBITS; /* first skip bits until we reach a one */ - while (count != 0) + while (count) { if (temp & MP_MSBMASK) break; @@ -579,21 +602,21 @@ void mpbpowmodsld_w(const mpbarrett* b, const mpw* slide, size_t psize, const mp while (psize) { - while (count != 0) + while (count) { byte bit = (temp & MP_MSBMASK) ? 1 : 0; n <<= 1; n += bit; - - if (n != 0) + + if (n) { - if (l != 0) + if (l) l++; - else if (bit != 0) - l = 1U; + else if (bit) + l = 1; - if (l == 4U) + if (l == 4) { byte s = mpbslide_presq[n]; @@ -601,9 +624,9 @@ void mpbpowmodsld_w(const mpbarrett* b, const mpw* slide, size_t psize, const mp mpbsqrmod_w(b, size, result, result, wksp); mpbmulmod_w(b, size, result, size, slide+mpbslide_mulg[n]*size, result, wksp); - + s = mpbslide_postsq[n]; - + while (s--) mpbsqrmod_w(b, size, result, result, wksp); @@ -623,23 +646,24 @@ void mpbpowmodsld_w(const mpbarrett* b, const mpw* slide, size_t psize, const mp } } - if (n != 0) + if (n) { byte s = mpbslide_presq[n]; + while (s--) mpbsqrmod_w(b, size, result, result, wksp); - + mpbmulmod_w(b, size, result, size, slide+mpbslide_mulg[n]*size, result, wksp); - + s = mpbslide_postsq[n]; - + while (s--) mpbsqrmod_w(b, size, result, result, wksp); } } } -/** +/* * mpbtwopowmod_w * needs workspace of (4*size+2) words */ @@ -669,7 +693,7 @@ void mpbtwopowmod_w(const mpbarrett* b, size_t psize, const mpw* pdata, mpw* res /* if temp is still zero, then we're trying to raise x to power zero, and result stays one */ if (temp) { - register unsigned int count = MP_WBITS; + register int count = MP_WBITS; /* first skip bits until we reach a one */ while (count) @@ -686,14 +710,14 @@ void mpbtwopowmod_w(const mpbarrett* b, size_t psize, const mpw* pdata, mpw* res { /* always square */ mpbsqrmod_w(b, size, result, result, wksp); - + /* multiply by two if bit is 1 */ if (temp & MP_MSBMASK) { if (mpadd(size, result, result) || mpge(size, result, b->modl)) { /* there was carry, or the result is greater than the modulus, so we need to adjust */ - (void) mpsub(size, result, b->modl); + mpsub(size, result, b->modl); } } @@ -706,222 +730,7 @@ void mpbtwopowmod_w(const mpbarrett* b, size_t psize, const mpw* pdata, mpw* res } } -#ifdef DYING -/*@unchecked@*/ -static int _debug = 0; - -#undef FULL_BINARY_EXTENDED_GCD - -/** - * Computes the inverse (modulo b) of x, and returns 1 if x was invertible. - */ -int mpbinv_w(const mpbarrett* b, size_t xsize, const mpw* xdata, mpw* result, mpw* wksp) -{ - size_t ysize = b->size+1; - int k; - mpw* u = wksp; - mpw* v = u+ysize; - mpw* u1 = v+ysize; - mpw* v1 = u1+ysize; - mpw* t1 = v1+ysize; - mpw* u3 = t1+ysize; - mpw* v3 = u3+ysize; - mpw* t3 = v3+ysize; - -#ifdef FULL_BINARY_EXTENDED_GCD - mpw* u2 = t3+ysize; - mpw* v2 = u2+ysize; - mpw* t2 = v2+ysize; -#endif - - mpsetx(ysize, u, xsize, xdata); - mpsetx(ysize, v, b->size, b->modl); - - /* Y1. Find power of 2. */ - for (k = 0; mpeven(ysize, u) && mpeven(ysize, v); k++) { - mpdivtwo(ysize, u); - mpdivtwo(ysize, v); - } - - /* Y2. Initialize. */ - mpsetw(ysize, u1, 1); - mpsetx(ysize, v1, ysize, v); - mpsetx(ysize, u3, ysize, u); - mpsetx(ysize, v3, ysize, v); - -#ifdef FULL_BINARY_EXTENDED_GCD - mpzero(ysize, u2); - mpsetw(ysize, v2, 1); - (void) mpsub(ysize, v2, u); -#endif - -if (_debug < 0) { -/*@-modfilesys@*/ -fprintf(stderr, " u: "), mpfprintln(stderr, ysize, u); -fprintf(stderr, " v: "), mpfprintln(stderr, ysize, v); -fprintf(stderr, " u1: "), mpfprintln(stderr, ysize, u1); -#ifdef FULL_BINARY_EXTENDED_GCD -fprintf(stderr, " u2: "), mpfprintln(stderr, ysize, u2); -#endif -fprintf(stderr, " u3: "), mpfprintln(stderr, ysize, u3); -fprintf(stderr, " v1: "), mpfprintln(stderr, ysize, v1); -#ifdef FULL_BINARY_EXTENDED_GCD -fprintf(stderr, " v2: "), mpfprintln(stderr, ysize, v2); -#endif -fprintf(stderr, " v3: "), mpfprintln(stderr, ysize, v3); -/*@=modfilesys@*/ -} - - if (mpodd(ysize, u)) { - mpzero(ysize, t1); -#ifdef FULL_BINARY_EXTENDED_GCD - mpzero(ysize, t2); - mpsubw(ysize, t2, 1); -#endif - mpzero(ysize, t3); - (void) mpsub(ysize, t3, v); - goto Y4; - } else { - mpsetw(ysize, t1, 1); -#ifdef FULL_BINARY_EXTENDED_GCD - mpzero(ysize, t2); -#endif - mpsetx(ysize, t3, ysize, u); - } - - do { - do { -#ifdef FULL_BINARY_EXTENDED_GCD - if (mpodd(ysize, t1) || mpodd(ysize, t2)) { - (void) mpadd(ysize, t1, v); - (void) mpsub(ysize, t2, u); - } -#else - /* XXX this assumes v is odd, true for DSA inversion. */ - if (mpodd(ysize, t1)) - (void) mpadd(ysize, t1, v); -#endif - - mpsdivtwo(ysize, t1); -#ifdef FULL_BINARY_EXTENDED_GCD - mpsdivtwo(ysize, t2); -#endif - mpsdivtwo(ysize, t3); -Y4: -if (_debug < 0) { -/*@-modfilesys@*/ -fprintf(stderr, "-->Y4 t3: "), mpfprintln(stderr, ysize, t3); -#ifdef FULL_BINARY_EXTENDED_GCD -fprintf(stderr, " t2: "), mpfprintln(stderr, ysize, t2); -#endif -fprintf(stderr, " t1: "), mpfprintln(stderr, ysize, t1); -/*@=modfilesys@*/ -} - } while (mpeven(ysize, t3)); - - /* Y5. Reset max(u3,v3). */ - if (!(*t3 & MP_MSBMASK)) { - mpsetx(ysize, u1, ysize, t1); -#ifdef FULL_BINARY_EXTENDED_GCD - mpsetx(ysize, u2, ysize, t2); -#endif - mpsetx(ysize, u3, ysize, t3); -if (_debug < 0) { -/*@-modfilesys@*/ -fprintf(stderr, "-->Y5 u1: "), mpfprintln(stderr, ysize, u1); -#ifdef FULL_BINARY_EXTENDED_GCD -fprintf(stderr, " u2: "), mpfprintln(stderr, ysize, u2); -#endif -fprintf(stderr, " u3: "), mpfprintln(stderr, ysize, u3); -/*@=modfilesys@*/ -} - } else { - mpsetx(ysize, v1, ysize, v); - (void) mpsub(ysize, v1, t1); -#ifdef FULL_BINARY_EXTENDED_GCD - mpsetx(ysize, v2, ysize, u); - mpneg(ysize, v2); - (void) mpsub(ysize, v2, t2); -#endif - mpzero(ysize, v3); - (void) mpsub(ysize, v3, t3); -if (_debug < 0) { -/*@-modfilesys@*/ -fprintf(stderr, "-->Y5 v1: "), mpfprintln(stderr, ysize, v1); -#ifdef FULL_BINARY_EXTENDED_GCD -fprintf(stderr, " v2: "), mpfprintln(stderr, ysize, v2); -#endif -fprintf(stderr, " v3: "), mpfprintln(stderr, ysize, v3); -/*@=modfilesys@*/ -} - } - - /* Y6. Subtract. */ - mpsetx(ysize, t1, ysize, u1); - (void) mpsub(ysize, t1, v1); -#ifdef FULL_BINARY_EXTENDED_GCD - mpsetx(ysize, t2, ysize, u2); - (void) mpsub(ysize, t2, v2); -#endif - mpsetx(ysize, t3, ysize, u3); - (void) mpsub(ysize, t3, v3); - - if (*t1 & MP_MSBMASK) { - (void) mpadd(ysize, t1, v); -#ifdef FULL_BINARY_EXTENDED_GCD - (void) mpsub(ysize, t2, u); -#endif - } - -if (_debug < 0) { -/*@-modfilesys@*/ -fprintf(stderr, "-->Y6 t1: "), mpfprintln(stderr, ysize, t1); -#ifdef FULL_BINARY_EXTENDED_GCD -fprintf(stderr, " t2: "), mpfprintln(stderr, ysize, t2); -#endif -fprintf(stderr, " t3: "), mpfprintln(stderr, ysize, t3); -/*@=modfilesys@*/ -} - - } while (mpnz(ysize, t3)); - - if (!mpisone(ysize, u3) || !mpisone(ysize, v3)) - return 0; - - if (result) { - while (--k > 0) - (void) mpadd(ysize, u1, u1); - mpsetx(b->size, result, ysize, u1); - } - -if (_debug) { -/*@-modfilesys@*/ -if (result) -fprintf(stderr, "=== EXIT: "), mpfprintln(stderr, b->size, result); -fprintf(stderr, " u1: "), mpfprintln(stderr, ysize, u1); -#ifdef FULL_BINARY_EXTENDED_GCD -fprintf(stderr, " u2: "), mpfprintln(stderr, ysize, u2); -#endif -fprintf(stderr, " u3: "), mpfprintln(stderr, ysize, u3); -fprintf(stderr, " v1: "), mpfprintln(stderr, ysize, v1); -#ifdef FULL_BINARY_EXTENDED_GCD -fprintf(stderr, " v2: "), mpfprintln(stderr, ysize, v2); -#endif -fprintf(stderr, " v3: "), mpfprintln(stderr, ysize, v3); -fprintf(stderr, " t1: "), mpfprintln(stderr, ysize, t1); -#ifdef FULL_BINARY_EXTENDED_GCD -fprintf(stderr, " t2: "), mpfprintln(stderr, ysize, t2); -#endif -fprintf(stderr, " t3: "), mpfprintln(stderr, ysize, t3); -/*@=modfilesys@*/ -} - - return 1; -} - -#endif - -/** +/* * needs workspace of (7*size+2) words */ int mpbpprime_w(const mpbarrett* b, randomGeneratorContext* r, int t, mpw* wksp) @@ -941,20 +750,18 @@ int mpbpprime_w(const mpbarrett* b, randomGeneratorContext* r, int t, mpw* wksp) { /* * Small prime factor test: - * + * * Tables in mpspprod contain multi-precision integers with products of small primes * If the greatest common divisor of this product and the candidate is not one, then * the candidate has small prime factors, or is a small prime. Neither is acceptable when * we are looking for large probable primes =) * */ - + if (size > SMALL_PRIMES_PRODUCT_MAX) { mpsetx(size, wksp+size, SMALL_PRIMES_PRODUCT_MAX, mpspprod[SMALL_PRIMES_PRODUCT_MAX-1]); - /*@-compdef@*/ /* LCL: wksp+size */ mpgcd_w(size, b->modl, wksp+size, wksp, wksp+2*size); - /*@=compdef@*/ } else { @@ -973,14 +780,11 @@ int mpbpprime_w(const mpbarrett* b, randomGeneratorContext* r, int t, mpw* wksp) void mpbnrnd(const mpbarrett* b, randomGeneratorContext* rc, mpnumber* result) { register size_t size = b->size; - register mpw* temp = (mpw*) malloc(size * sizeof(*temp)); + register mpw* temp = (mpw*) malloc(size * sizeof(mpw)); - assert(temp != NULL); mpnfree(result); mpnsize(result, size); - /*@-usedef@*/ /* result->data unallocated? */ mpbrnd_w(b, rc, result->data, temp); - /*@=usedef@*/ free(temp); } @@ -988,14 +792,11 @@ void mpbnrnd(const mpbarrett* b, randomGeneratorContext* rc, mpnumber* result) void mpbnmulmod(const mpbarrett* b, const mpnumber* x, const mpnumber* y, mpnumber* result) { register size_t size = b->size; - register mpw* temp = (mpw*) malloc((4*size+2) * sizeof(*temp)); + register mpw* temp = (mpw*) malloc((4*size+2) * sizeof(mpw)); /* xsize and ysize must be <= b->size */ register size_t fill = 2*size-x->size-y->size; - register mpw* opnd; - - assert(temp != NULL); - opnd = temp + size*2+2; + register mpw* opnd = temp+size*2+2; mpnfree(result); mpnsize(result, size); @@ -1004,9 +805,7 @@ void mpbnmulmod(const mpbarrett* b, const mpnumber* x, const mpnumber* y, mpnumb mpzero(fill, opnd); mpmul(opnd+fill, x->size, x->data, y->size, y->data); - /*@-usedef -compdef @*/ /* result->data unallocated? */ mpbmod_w(b, opnd, result->data, temp); - /*@=usedef =compdef @*/ free(temp); } @@ -1014,23 +813,18 @@ void mpbnmulmod(const mpbarrett* b, const mpnumber* x, const mpnumber* y, mpnumb void mpbnsqrmod(const mpbarrett* b, const mpnumber* x, mpnumber* result) { register size_t size = b->size; - register mpw* temp = (mpw*) malloc(size * sizeof(*temp)); + register mpw* temp = (mpw*) malloc(size * sizeof(mpw)); /* xsize must be <= b->size */ register size_t fill = 2*(size-x->size); - register mpw* opnd; - - assert(temp != NULL); - opnd = temp + size*2+2; + register mpw* opnd = temp + size*2+2; if (fill) mpzero(fill, opnd); mpsqr(opnd+fill, x->size, x->data); mpnsize(result, size); - /*@-usedef -compdef @*/ /* result->data unallocated? */ mpbmod_w(b, opnd, result->data, temp); - /*@=usedef =compdef @*/ free(temp); } @@ -1038,9 +832,8 @@ void mpbnsqrmod(const mpbarrett* b, const mpnumber* x, mpnumber* result) void mpbnpowmod(const mpbarrett* b, const mpnumber* x, const mpnumber* pow, mpnumber* y) { register size_t size = b->size; - register mpw* temp = (mpw*) malloc((4*size+2) * sizeof(*temp)); + register mpw* temp = (mpw*) malloc((4*size+2) * sizeof(mpw)); - assert(temp != NULL); mpnfree(y); mpnsize(y, size); @@ -1052,15 +845,17 @@ void mpbnpowmod(const mpbarrett* b, const mpnumber* x, const mpnumber* pow, mpnu void mpbnpowmodsld(const mpbarrett* b, const mpw* slide, const mpnumber* pow, mpnumber* y) { register size_t size = b->size; - register mpw* temp = (mpw*) malloc((4*size+2) * sizeof(*temp)); + register mpw* temp = (mpw*) malloc((4*size+2) * sizeof(mpw)); - assert(temp != NULL); mpnfree(y); mpnsize(y, size); - /*@-internalglobs -mods@*/ /* noisy */ mpbpowmodsld_w(b, slide, pow->size, pow->data, y->data, temp); - /*@=internalglobs =mods@*/ free(temp); } + +size_t mpbbits(const mpbarrett* b) +{ + return mpbits(b->size, b->modl); +} diff --git a/beecrypt/mpbarrett.h b/beecrypt/mpbarrett.h index 6bfcf60..3cb362e 100644 --- a/beecrypt/mpbarrett.h +++ b/beecrypt/mpbarrett.h @@ -26,203 +26,128 @@ #ifndef _MPBARRETT_H #define _MPBARRETT_H -#include "beecrypt.h" -#include "mpnumber.h" +#include "beecrypt/beecrypt.h" +#include "beecrypt/mpnumber.h" -typedef struct +#ifdef __cplusplus +# include +#endif + +#ifdef __cplusplus +struct BEECRYPTAPI mpbarrett +#else +struct _mpbarrett +#endif { size_t size; -/*@owned@*/ mpw* modl; /* (size) words */ -/*@dependent@*/ /*@null@*/ - mpw* mu; /* (size+1) words */ -} mpbarrett; + mpw* mu; /* (size+1) words */ #ifdef __cplusplus -extern "C" { + mpbarrett(); + mpbarrett(const mpbarrett&); + ~mpbarrett(); + + const mpbarrett& operator=(const mpbarrett&); + bool operator==(const mpbarrett&); + bool operator!=(const mpbarrett&); + + void wipe(); + size_t bitlength() const; #endif +}; -/** - */ +#ifndef __cplusplus +typedef struct _mpbarrett mpbarrett; +#else BEECRYPTAPI -void mpbzero(/*@out@*/ mpbarrett* b) - /*@modifies b->size, b->modl, b->mu @*/; +std::ostream& operator<<(std::ostream&, const mpbarrett&); +#endif -/** - */ -BEECRYPTAPI -void mpbinit(mpbarrett* b, size_t size) - /*@modifies b->size, b->modl, b->mu @*/; +#ifdef __cplusplus +extern "C" { +#endif -/** - */ BEECRYPTAPI -void mpbfree(/*@special@*/ mpbarrett* b) - /*@uses b->size, b->modl @*/ - /*@releases b->modl @*/ - /*@modifies b->size, b->modl, b->mu @*/; - -/** - */ +void mpbzero(mpbarrett*); BEECRYPTAPI -void mpbcopy(mpbarrett* b, const mpbarrett* copy) - /*@modifies b->size, b->modl, b->mu @*/; - -/** - */ +void mpbinit(mpbarrett*, size_t); BEECRYPTAPI -void mpbset(mpbarrett* b, size_t size, const mpw* data) - /*@modifies b->size, b->modl, b->mu @*/; - -/** - */ -BEECRYPTAPI /*@unused@*/ -void mpbsethex(mpbarrett* b, const char* hex) - /*@modifies b->size, b->modl, b->mu @*/; - -/** - */ +void mpbfree(mpbarrett*); BEECRYPTAPI -void mpbsubone(const mpbarrett* b, mpw* result) - /*@modifies result @*/; - -/** - */ -BEECRYPTAPI /*@unused@*/ -void mpbneg(const mpbarrett* b, const mpw* data, mpw* result) - /*@modifies result @*/; - -/** - */ +void mpbcopy(mpbarrett*, const mpbarrett*); BEECRYPTAPI -void mpbmu_w(mpbarrett* b, /*@out@*/ mpw* wksp) - /*@modifies b->size, b->modl, b->mu, wksp @*/; +void mpbwipe(mpbarrett*); -/** - */ BEECRYPTAPI -void mpbrnd_w (const mpbarrett* b, randomGeneratorContext* rc, /*@out@*/ mpw* result, /*@out@*/ mpw* wksp) - /*@modifies result, wksp @*/; +void mpbset(mpbarrett*, size_t, const mpw*); -/** - */ -/*@-exportlocal@*/ BEECRYPTAPI -void mpbrndodd_w(const mpbarrett* b, randomGeneratorContext* rc, /*@out@*/ mpw* result, /*@out@*/ mpw* wksp) - /*@modifies result, wksp @*/; -/*@=exportlocal@*/ - -/** - */ +int mpbsetbin(mpbarrett*, const byte*, size_t); BEECRYPTAPI -void mpbrndinv_w(const mpbarrett* b, randomGeneratorContext* rc, /*@out@*/ mpw* result, /*@out@*/ mpw* inverse, /*@out@*/ mpw* wksp) - /*@modifies result, inverse, wksp @*/; +int mpbsethex(mpbarrett*, const char*); -/** - */ BEECRYPTAPI -void mpbmod_w(const mpbarrett* b, const mpw* data, /*@out@*/ mpw* result, /*@out@*/ mpw* wksp) - /*@modifies result, wksp @*/; +void mpbsubone(const mpbarrett*, mpw*); -/** - */ BEECRYPTAPI -void mpbaddmod_w(const mpbarrett* b, size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata, /*@out@*/ mpw* result, /*@out@*/ mpw* wksp) - /*@modifies result, wksp @*/; +void mpbmu_w(mpbarrett*, mpw*); -/** - */ -BEECRYPTAPI /*@unused@*/ -void mpbsubmod_w(const mpbarrett* b, size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata, /*@out@*/ mpw* result, /*@out@*/ mpw* wksp) - /*@modifies result, wksp @*/; - -/** - */ BEECRYPTAPI -void mpbmulmod_w(const mpbarrett* b, size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata, /*@out@*/ mpw* result, /*@out@*/ mpw* wksp) - /*@modifies result, wksp @*/; - -/** - */ +void mpbrnd_w (const mpbarrett*, randomGeneratorContext*, mpw*, mpw*); BEECRYPTAPI -void mpbsqrmod_w(const mpbarrett* b, size_t xsize, const mpw* xdata, /*@out@*/ mpw* result, /*@out@*/ mpw* wksp) - /*@modifies result, wksp @*/; - -/** - */ +void mpbrndodd_w(const mpbarrett*, randomGeneratorContext*, mpw*, mpw*); BEECRYPTAPI -void mpbpowmod_w(const mpbarrett* b, size_t xsize, const mpw* xdata, size_t psize, const mpw* pdata, /*@out@*/ mpw* result, /*@out@*/ mpw* wksp) - /*@modifies result, wksp @*/; +void mpbrndinv_w(const mpbarrett*, randomGeneratorContext*, mpw*, mpw*, mpw*); -/** - */ -/*@-exportlocal@*/ BEECRYPTAPI -void mpbpowmodsld_w(const mpbarrett* b, const mpw* slide, size_t psize, const mpw* pdata, /*@out@*/ mpw* result, /*@out@*/ mpw* wksp) - /*@globals internalState @*/ - /*@modifies result, wksp, internalState @*/; -/*@=exportlocal@*/ +void mpbneg_w(const mpbarrett*, const mpw*, mpw*); +BEECRYPTAPI +void mpbmod_w(const mpbarrett*, const mpw*, mpw*, mpw*); -/** - */ BEECRYPTAPI -void mpbtwopowmod_w(const mpbarrett* b, size_t psize, const mpw* pdata, /*@out@*/ mpw* result, /*@out@*/ mpw* wksp) - /*@modifies result, wksp @*/; +void mpbaddmod_w(const mpbarrett*, size_t, const mpw*, size_t, const mpw*, mpw*, mpw*); +BEECRYPTAPI +void mpbsubmod_w(const mpbarrett*, size_t, const mpw*, size_t, const mpw*, mpw*, mpw*); +BEECRYPTAPI +void mpbmulmod_w(const mpbarrett*, size_t, const mpw*, size_t, const mpw*, mpw*, mpw*); +BEECRYPTAPI +void mpbsqrmod_w(const mpbarrett*, size_t, const mpw*, mpw*, mpw*); +BEECRYPTAPI +void mpbpowmod_w(const mpbarrett*, size_t, const mpw*, size_t, const mpw*, mpw*, mpw*); +BEECRYPTAPI +void mpbpowmodsld_w(const mpbarrett*, const mpw*, size_t, const mpw*, mpw*, mpw*); +BEECRYPTAPI +void mpbtwopowmod_w(const mpbarrett*, size_t, const mpw*, mpw*, mpw*); -#ifdef NOTYET -/** - * @todo Simultaneous multiple exponentiation, for use in dsa and elgamal - * signature verification. +/* To be added: + * simultaneous multiple exponentiation, for use in dsa and elgamal signature verification */ -BEECRYPTAPI /*@unused@*/ -void mpbsm2powmod(const mpbarrett* b, const mpw*, const mpw*, const mpw*, const mpw*); +BEECRYPTAPI +void mpbsm2powmod(const mpbarrett*, const mpw*, const mpw*, const mpw*, const mpw*); +BEECRYPTAPI +void mpbsm3powmod(const mpbarrett*, const mpw*, const mpw*, const mpw*, const mpw*, const mpw*, const mpw*); -/** - */ -BEECRYPTAPI /*@unused@*/ -void mpbsm3powmod(const mpbarrett* b, const mpw*, const mpw*, const mpw*, const mpw*, const mpw*, const mpw*); -#endif /* NOTYET */ +BEECRYPTAPI +int mpbpprime_w(const mpbarrett*, randomGeneratorContext*, int, mpw*); -/** - */ -BEECRYPTAPI /*@unused@*/ -int mpbpprime_w(const mpbarrett* b, randomGeneratorContext* r, int t, /*@out@*/ mpw* wksp) - /*@modifies wksp @*/; +/* the next routines take mpnumbers as parameters */ -/** - * @note Takes mpnumber as parameter. - */ BEECRYPTAPI -void mpbnrnd(const mpbarrett* b, randomGeneratorContext* rc, mpnumber* result) - /*@modifies result @*/; - -/** - * @note Takes mpnumber as parameter. - */ -BEECRYPTAPI /*@unused@*/ -void mpbnmulmod(const mpbarrett* b, const mpnumber* x, const mpnumber* y, mpnumber* result) - /*@modifies result @*/; +void mpbnrnd(const mpbarrett*, randomGeneratorContext*, mpnumber*); -/** - * @note Takes mpnumber as parameter. - */ -BEECRYPTAPI /*@unused@*/ -void mpbnsqrmod(const mpbarrett* b, const mpnumber* x, mpnumber* result) - /*@modifies result @*/; +BEECRYPTAPI +void mpbnmulmod(const mpbarrett*, const mpnumber*, const mpnumber*, mpnumber*); +BEECRYPTAPI +void mpbnsqrmod(const mpbarrett*, const mpnumber*, mpnumber*); -/** - * @note Takes mpnumber as parameter. - */ BEECRYPTAPI -void mpbnpowmod (const mpbarrett* b, const mpnumber* x, const mpnumber* pow, mpnumber* y) - /*@modifies y @*/; +void mpbnpowmod (const mpbarrett*, const mpnumber*, const mpnumber*, mpnumber*); +BEECRYPTAPI +void mpbnpowmodsld(const mpbarrett*, const mpw*, const mpnumber*, mpnumber*); -/** - * @note Takes mpnumber as parameter. - */ -BEECRYPTAPI /*@unused@*/ -void mpbnpowmodsld(const mpbarrett* b, const mpw* slide, const mpnumber* pow, mpnumber* y) - /*@modifies y @*/; +BEECRYPTAPI +size_t mpbbits(const mpbarrett*); #ifdef __cplusplus } diff --git a/beecrypt/mpnumber.c b/beecrypt/mpnumber.c index 22de6c9..94c0378 100644 --- a/beecrypt/mpnumber.c +++ b/beecrypt/mpnumber.c @@ -23,10 +23,13 @@ * \ingroup MP_m */ -#include "system.h" -#include "mpnumber.h" -#include "mp.h" -#include "debug.h" +#define BEECRYPT_DLL_EXPORT + +#if HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/mpnumber.h" void mpnzero(mpnumber* n) { @@ -34,7 +37,6 @@ void mpnzero(mpnumber* n) n->data = (mpw*) 0; } -/*@-compdef @*/ /* n->data not initialized */ void mpnsize(mpnumber* n, size_t size) { if (size) @@ -42,18 +44,23 @@ void mpnsize(mpnumber* n, size_t size) if (n->data) { if (n->size != size) - n->data = (mpw*) realloc(n->data, size * sizeof(*n->data)); + { + if (size < n->size) + { + register size_t offset = n->size - size; + + memmove(n->data, n->data + offset, offset * sizeof(mpw)); + } + n->data = (mpw*) realloc(n->data, size * sizeof(mpw)); + } } else - n->data = (mpw*) malloc(size * sizeof(*n->data)); + n->data = (mpw*) malloc(size * sizeof(mpw)); - if (n->data) - n->size = size; - else - { + if (n->data == (mpw*) 0) n->size = 0; - n->data = (mpw*) 0; - } + else + n->size = size; } else if (n->data) @@ -63,23 +70,15 @@ void mpnsize(mpnumber* n, size_t size) n->size = 0; } } -/*@=compdef @*/ -/*@-bounds@*/ void mpninit(mpnumber* n, size_t size, const mpw* data) { n->size = size; - if (n->data) - { - free(n->data); - n->data = (mpw*) 0; - } - n->data = (mpw*) malloc(size * sizeof(*n->data)); + n->data = (mpw*) malloc(size * sizeof(mpw)); - if (n->data != (mpw*) 0 && data != (mpw*) 0) + if (n->data) mpcopy(size, n->data, data); } -/*@=bounds@*/ void mpnfree(mpnumber* n) { @@ -98,7 +97,7 @@ void mpncopy(mpnumber* n, const mpnumber* copy) void mpnwipe(mpnumber* n) { - if (n->data) + if (n->data != (mpw*) 0) mpzero(n->size, n->data); } @@ -109,23 +108,15 @@ void mpnset(mpnumber* n, size_t size, const mpw* data) if (n->data) { if (n->size != size) - n->data = (mpw*) realloc(n->data, size * sizeof(*n->data)); + n->data = (mpw*) realloc(n->data, size * sizeof(mpw)); } else - n->data = (mpw*) malloc(size * sizeof(*n->data)); + n->data = (mpw*) malloc(size * sizeof(mpw)); - if (n->data != (mpw*) 0 && data != (mpw*) 0) - { - n->size = size; - /*@-nullpass@*/ /* data is notnull */ - mpcopy(n->size, n->data, data); - /*@=nullpass@*/ - } + if (n->data) + mpcopy(n->size = size, n->data, data); else - { n->size = 0; - n->data = (mpw*) 0; - } } else if (n->data) { @@ -140,10 +131,10 @@ void mpnsetw(mpnumber* n, mpw val) if (n->data) { if (n->size != 1) - n->data = (mpw*) realloc(n->data, 1 * sizeof(*n->data)); + n->data = (mpw*) realloc(n->data, sizeof(mpw)); } else - n->data = (mpw*) malloc(1 * sizeof(*n->data)); + n->data = (mpw*) malloc(sizeof(mpw)); if (n->data) { @@ -151,53 +142,128 @@ void mpnsetw(mpnumber* n, mpw val) n->data[0] = val; } else - { n->size = 0; - n->data = (mpw*) 0; - } } -/*@-usedef @*/ /* n->data may be NULL */ -void mpnsethex(mpnumber* n, const char* hex) +int mpnsetbin(mpnumber* n, const byte* osdata, size_t ossize) { - register size_t len = strlen(hex); - register size_t size = MP_NIBBLES_TO_WORDS(len + MP_WNIBBLES - 1); + int rc = -1; + size_t size; + + /* skip zero bytes */ + while ((*osdata == 0) && ossize) + { + osdata++; + ossize--; + } + + size = MP_BYTES_TO_WORDS(ossize + MP_WBYTES - 1); if (n->data) { if (n->size != size) - n->data = (mpw*) realloc(n->data, size * sizeof(*n->data)); + n->data = (mpw*) realloc(n->data, size * sizeof(mpw)); } else - n->data = (mpw*) malloc(size * sizeof(*n->data)); + n->data = (mpw*) malloc(size * sizeof(mpw)); if (n->data) { n->size = size; - (void) hs2ip(n->data, size, hex, len); + rc = os2ip(n->data, size, osdata, ossize); } - else { + else n->size = 0; - n->data = (mpw*)0; + + return rc; +} + +int mpnsethex(mpnumber* n, const char* hex) +{ + int rc = -1; + size_t len = strlen(hex); + size_t size = MP_NIBBLES_TO_WORDS(len + MP_WNIBBLES - 1); + + if (n->data) + { + if (n->size != size) + n->data = (mpw*) realloc(n->data, size * sizeof(mpw)); + } + else + n->data = (mpw*) malloc(size * sizeof(mpw)); + + if (n->data) + { + n->size = size; + + rc = hs2ip(n->data, size, hex, len); } + else + n->size = 0; + + return rc; } -/*@=usedef @*/ int mpninv(mpnumber* inv, const mpnumber* k, const mpnumber* mod) { int rc = 0; size_t size = mod->size; - mpw* wksp = (mpw*) malloc((7*size+6) * sizeof(*wksp)); + mpw* wksp = (mpw*) malloc((7*size+6) * sizeof(mpw)); if (wksp) { - mpnzero(inv); mpnsize(inv, size); mpsetx(size, wksp, k->size, k->data); - rc = mpextgcd_w(size, wksp, mod->data, inv->data, wksp+size); + rc = mpextgcd_w(size, mod->data, wksp, inv->data, wksp+size); free(wksp); } return rc; } + +size_t mpntrbits(mpnumber* n, size_t bits) +{ + size_t sigbits = mpbits(n->size, n->data); + size_t offset = 0; + + if (sigbits < bits) + { + /* no need to truncate */ + return sigbits; + } + else + { + size_t allbits = MP_BITS_TO_WORDS(n->size + MP_WBITS - 1); + + while ((allbits - bits) > MP_WBITS) + { + /* zero a word */ + n->data[offset++] = 0; + allbits -= MP_WBITS; + } + + if ((allbits - bits)) + { + /* mask the next word */ + n->data[offset] &= (MP_ALLMASK >> (MP_WBITS - bits)); + + /* resize the number */ + mpnsize(n, n->size - offset); + + /* finally return the number of remaining bits */ + return bits; + } + else + { + /* nothing remains */ + mpnsetw(n, 0); + return 0; + } + } +} + +size_t mpnbits(const mpnumber* n) +{ + return mpbits(n->size, n->data); +} diff --git a/beecrypt/mpnumber.h b/beecrypt/mpnumber.h index 66b6b06..08156e3 100644 --- a/beecrypt/mpnumber.h +++ b/beecrypt/mpnumber.h @@ -26,80 +26,84 @@ #ifndef _MPNUMBER_H #define _MPNUMBER_H -#include "mp.h" +#include "beecrypt/mp.h" -/** - */ -typedef struct +#ifdef __cplusplus +# include +#endif + +#ifdef __cplusplus +struct BEECRYPTAPI mpnumber +#else +struct _mpnumber +#endif { size_t size; -/*@owned@*/ /*@relnull@*/ mpw* data; -} mpnumber; #ifdef __cplusplus -extern "C" { + mpnumber(); + mpnumber(unsigned int); + mpnumber(const mpnumber&); + ~mpnumber(); + + const mpnumber& operator=(const mpnumber&); + bool operator==(const mpnumber&); + bool operator!=(const mpnumber&); + + void wipe(); + + size_t bitlength() const; #endif +}; -/** - */ +#ifndef __cplusplus +typedef struct _mpnumber mpnumber; +#else BEECRYPTAPI -void mpnzero(/*@out@*/ mpnumber* n) - /*@modifies n->size, n->data @*/; - -/** - */ +std::ostream& operator<<(std::ostream&, const mpnumber&); +/* BEECRYPTAPI -void mpnsize(mpnumber* n, size_t size) - /*@modifies n->size, n->data @*/; +std::istream& operator>>(std::istream&, mpnumber&); +*/ +#endif -/** - */ -BEECRYPTAPI /*@unused@*/ -void mpninit(mpnumber* n, size_t size, const mpw* data) - /*@modifies n->size, n->data @*/; +#ifdef __cplusplus +extern "C" { +#endif -/** - */ BEECRYPTAPI -void mpnfree(mpnumber* n) - /*@modifies n->size, n->data @*/; - -/** - */ +void mpnzero(mpnumber*); BEECRYPTAPI -void mpncopy(mpnumber* n, const mpnumber* copy) - /*@modifies n->size, n->data @*/; - -/** - */ +void mpnsize(mpnumber*, size_t); +BEECRYPTAPI +void mpninit(mpnumber*, size_t, const mpw*); +BEECRYPTAPI +void mpnfree(mpnumber*); +BEECRYPTAPI +void mpncopy(mpnumber*, const mpnumber*); BEECRYPTAPI -void mpnwipe(mpnumber* n) - /*@modifies n->size, n->data @*/; +void mpnwipe(mpnumber*); -/** - */ BEECRYPTAPI -void mpnset (mpnumber* n, size_t size, /*@null@*/ const mpw* data) - /*@modifies n->size, n->data @*/; +void mpnset (mpnumber*, size_t, const mpw*); +BEECRYPTAPI +void mpnsetw (mpnumber*, mpw); -/** - */ BEECRYPTAPI -void mpnsetw (mpnumber* n, mpw val) - /*@modifies n->size, n->data @*/; +int mpnsetbin(mpnumber*, const byte*, size_t); +BEECRYPTAPI +int mpnsethex(mpnumber*, const char*); -/** - */ -BEECRYPTAPI /*@unused@*/ -void mpnsethex(/*@out@*/ mpnumber* n, const char* hex) - /*@modifies n->size, n->data @*/; +BEECRYPTAPI +int mpninv(mpnumber*, const mpnumber*, const mpnumber*); -/** +/*!\brief Truncate the mpnumber to the specified number of (least significant) bits. */ -BEECRYPTAPI /*@unused@*/ -int mpninv(/*@out@*/ mpnumber* inv, const mpnumber* k, const mpnumber* mod) - /*@modifies inv->size, inv->data @*/; +BEECRYPTAPI +size_t mpntrbits(mpnumber*, size_t); +BEECRYPTAPI +size_t mpnbits(const mpnumber*); #ifdef __cplusplus } diff --git a/beecrypt/mpopt.h b/beecrypt/mpopt.h index a6384ed..f9ba2db 100644 --- a/beecrypt/mpopt.h +++ b/beecrypt/mpopt.h @@ -71,10 +71,10 @@ # define ASM_MPFILL # define ASM_MPEVEN # define ASM_MPODD -# define ASM_MPADDW -# define ASM_MPSUBW # define ASM_MPADD +# define ASM_MPADDW # define ASM_MPSUB +# define ASM_MPSUBW # define ASM_MPMULTWO # define ASM_MPDIVTWO # define ASM_MPSETMUL @@ -97,10 +97,10 @@ # define ASM_MPADDSQRTRC # elif defined(OPTIMIZE_POWERPC) || defined(OPTIMIZE_POWERPC64) # define ASM_MPSETMUL -# define ASM_MPADDW -# define ASM_MPSUBW # define ASM_MPADD +# define ASM_MPADDW # define ASM_MPSUB +# define ASM_MPSUBW # define ASM_MPMULTWO # define ASM_MPADDMUL # define ASM_MPADDSQRTRC @@ -125,8 +125,15 @@ # define ASM_MPFILL # define ASM_MPEVEN # define ASM_MPODD +# define ASM_MPADD +# define ASM_MPADDW +# define ASM_MPSUB +# define ASM_MPSUBW +# define ASM_MPDIVTWO +# define ASM_MPMULTWO # define ASM_MPSETMUL # define ASM_MPADDMUL +# define ASM_MPADDSQRTRC # endif #endif diff --git a/beecrypt/mpprime.c b/beecrypt/mpprime.c index 1593100..c21287a 100644 --- a/beecrypt/mpprime.c +++ b/beecrypt/mpprime.c @@ -23,14 +23,16 @@ * \ingroup MP_m */ -#include "system.h" -#include "mpprime.h" -#include "mp.h" -#include "mpbarrett.h" -#include "debug.h" - -/** - * A word of explanation here on what these tables accomplish: +#define BEECRYPT_DLL_EXPORT + +#if HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/mpprime.h" + +/* + * A word of explanation here on what this table accomplishes: * * For fast checking whether a candidate prime can be divided by small primes, we use this table, * which contains the products of all small primes starting at 3, up to a word size equal to the size @@ -47,69 +49,42 @@ #if (MP_WBITS == 64) -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_01[] = /* primes 3 to 53 */ { 0xe221f97c30e94e1dU }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_02[] = /* primes 3 to 101 */ { 0x5797d47c51681549U, 0xd734e4fc4c3eaf7fU }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_03[] = /* primes 3 to 149 */ { 0x1e6d8e2a0ffceafbU, 0xbcbfc14a4c3bc1e1U, 0x009c6a22a0a7adf5U }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_04[] = /* primes 3 to 193 */ { 0xdbf05b6f5654b3c0U, 0xf524355143958688U, 0x9f155887819aed2aU, 0xc05b93352be98677U }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_05[] = /* primes 3 to 239 */ { 0x3faa5dadb695ce58U, 0x4a579328eab20f1fU, 0xef00fe27ffc36456U, 0x0a65723e27d8884aU, 0xd59da0a992f77529U }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_06[] = /* primes 3 to 281 */ { 0x501201cc51a492a5U, 0x44d3900ad4f8b32aU, 0x203c858406a4457cU, 0xab0b4f805ab18ac6U, 0xeb9572ac6e9394faU, 0x522bffb6f44af2f3U }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_07[] = /* primes 3 to 331 */ { 0x0120eb4d70279230U, 0x9ed122fce0488be4U, 0x1d0c99f5d8c039adU, 0x058c90b4780500feU, 0xf39c05cc09817a27U, 0xc3e1776a246b6af2U, 0x946a10d66eafaedfU }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_08[] = /* primes 3 to 379 */ { 0x106aa9fb7646fa6eU, 0xb0813c28c5d5f09fU, 0x077ec3ba238bfb99U, 0xc1b631a203e81187U, 0x233db117cbc38405U, 0x6ef04659a4a11de4U, 0x9f7ecb29bada8f98U, 0x0decece92e30c48fU }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_09[] = /* primes 3 to 421 */ { 0x0185dbeb2b8b11d3U, 0x7633e9dc1eec5415U, 0x65c6ce8431d227eeU, 0x28f0328a60c90118U, @@ -117,9 +92,6 @@ static mpw spp_09[] = /* primes 3 to 421 */ 0xf35e974579072ec8U, 0xcaf1ac8eefd5566fU, 0xa15fb94fe34f5d37U }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_10[] = /* primes 3 to 463 */ { 0x833a505cf9922beeU, 0xc80265a6d50e1cceU, 0xa22f6fec2eb84450U, 0xcec64a3c0e10d472U, @@ -127,9 +99,6 @@ static mpw spp_10[] = /* primes 3 to 463 */ 0x5e21023267bda426U, 0x738730cfb8e6e2aeU, 0xc08c9d4bd2420066U, 0xdccf95ef49a560b7U }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_11[] = /* primes 3 to 509 */ { 0x309d024bd5380319U, 0x2ca334690bafb43aU, 0x0abd5840fbeb24d1U, 0xf49b633047902baeU, @@ -138,9 +107,6 @@ static mpw spp_11[] = /* primes 3 to 509 */ 0x8ffd0db8e8fa61a1U, 0x6e1c0970beb81adcU, 0xf49c82dff960d36fU }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_12[] = /* primes 3 to 569 */ { 0x25eac89f8d4da338U, 0x337b49850d2d1489U, 0x2663177b4010af3dU, 0xd23eeb0b228f3832U, @@ -149,9 +115,6 @@ static mpw spp_12[] = /* primes 3 to 569 */ 0x93c158c1a9a8227fU, 0xf81a90c5630e9c44U, 0x845c755c7df35a7dU, 0x430c679a11575655U }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_13[] = /* primes 3 to 607 */ { 0x3383219d26454f06U, 0xe2789b7f9c3b940eU, 0x03be2105798e3ff7U, 0x945bd325997bc262U, @@ -161,9 +124,6 @@ static mpw spp_13[] = /* primes 3 to 607 */ 0xde195be86e66ba89U, 0xb0ab042d3276976cU, 0x3dbeb3d7413ea96dU }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_14[] = /* primes 3 to 647 */ { 0x6e02645460adbd18U, 0xcd52ce1a1beab1c0U, 0x36e468e9f350d69bU, 0x1d357d083a59f778U, @@ -173,9 +133,6 @@ static mpw spp_14[] = /* primes 3 to 647 */ 0xc74d951db361f061U, 0xc4d14f000d806db4U, 0xcd939110c7cab492U, 0x2f3ea4c4852ca469U }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_15[] = /* primes 3 to 683 */ { 0x008723131f66758aU, 0x414bbebb2f8670bfU, 0x01dc959d74468901U, 0x57c57f40e210c9c2U, @@ -186,9 +143,6 @@ static mpw spp_15[] = /* primes 3 to 683 */ 0xe61b766ec0943254U, 0x1cd70f0fd5a0ce6bU, 0x8ab998fb8ab36e0dU }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_16[] = /* primes 3 to 739 */ { 0x02c85ff870f24be8U, 0x0f62b1ba6c20bd72U, 0xb837efdf121206d8U, 0x7db56b7d69fa4c02U, @@ -199,9 +153,6 @@ static mpw spp_16[] = /* primes 3 to 739 */ 0x35bbb6e5dae2783dU, 0xd1c0ce7dec4fc70eU, 0x5186d411df36368fU, 0x061aa36011f30179U }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_17[] = /* primes 3 to 787 */ { 0x16af5c18a2bef8efU, 0xf2278332182d0fbfU, 0x0038cc205148b83dU, 0x06e3d7d932828b18U, @@ -213,9 +164,6 @@ static mpw spp_17[] = /* primes 3 to 787 */ 0xb0cfbf964c8f27ceU, 0x05d6c77a01f9d332U, 0x36c9d442ad69ed33U }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_18[] = /* primes 3 to 827 */ { 0x005bfd2583ab7a44U, 0x13d4df0f537c686cU, 0xa8e6b583e491130eU, 0x96dfcc1c05ba298fU, @@ -227,9 +175,6 @@ static mpw spp_18[] = /* primes 3 to 827 */ 0x9513a9cbe3e67e3aU, 0xe501c1c522aa8ba9U, 0xf955789589161febU, 0xc69941a147aa9685U }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_19[] = /* primes 3 to 877 */ { 0x06706918e8355b7fU, 0xfd3f024da6b012e2U, 0xbb7338f30d51a968U, 0x0f3d912035ed70e0U, @@ -242,9 +187,6 @@ static mpw spp_19[] = /* primes 3 to 877 */ 0xe85d8e9434a37006U, 0x8cebc96060ab2f87U, 0x81efeb182d0e724bU }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_20[] = /* primes 3 to 929 */ { 0xa9e9591f7815617eU, 0xcabe352fa13445c4U, 0xf8e319ba63042e1cU, 0xb0a017d0e729a699U, @@ -257,9 +199,6 @@ static mpw spp_20[] = /* primes 3 to 929 */ 0x30b96bfb6475393bU, 0x5f43a549d95c5619U, 0x7e274850ad1a6d18U, 0xb5eaa41dd42fda55U }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_21[] = /* primes 3 to 971 */ { 0x06e1d136cb78cac5U, 0x4da4bfcb6f2c4a24U, 0xfcf3796b77719c31U, 0xd27915860001f03eU, @@ -273,9 +212,6 @@ static mpw spp_21[] = /* primes 3 to 971 */ 0x0d57d0f076647b0aU, 0xb191f543dc08c392U, 0x3167e5ee56c66847U }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_22[] = /* primes 3 to 1013 */ { 0x005ca1a92edd0e81U, 0x9619289e1ecfe2d7U, 0xf3949eaf363a5fe8U, 0xf6fee01ccd480490U, @@ -289,9 +225,6 @@ static mpw spp_22[] = /* primes 3 to 1013 */ 0x5b7138fc36f7989cU, 0xe85b07c2d4d59d42U, 0x1541c765f6c2111dU, 0xb82eca06b437f757U }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_23[] = /* primes 3 to 1051 */ { 0x18e5b310229f618dU, 0xe0f54782f57fff33U, 0x10546ba8efc0a69cU, 0xac4b573b749cc43dU, @@ -306,9 +239,6 @@ static mpw spp_23[] = /* primes 3 to 1051 */ 0x531bccbf17e3c78dU, 0x5c43d8f6866ad640U, 0xfdbbba0fe997b27bU }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_24[] = /* primes 3 to 1093 */ { 0x021bf9497091b8c3U, 0x68cc7c8e00c1990cU, 0x6027481b79215ac8U, 0xa7517749a2151377U, @@ -323,9 +253,6 @@ static mpw spp_24[] = /* primes 3 to 1093 */ 0x7dfb5c9c8ada77cdU, 0x0d5b94eff021e02eU, 0x307d08010312d57cU, 0xb5d975764697842dU }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_25[] = /* primes 3 to 1151 */ { 0xfa1bd62baae1e767U, 0x47535af3830fc07dU, 0xebcf3ef7e5a8e46bU, 0x8937c4afe02aef0aU, @@ -341,9 +268,6 @@ static mpw spp_25[] = /* primes 3 to 1151 */ 0x138b42a3c1d9593cU, 0xe1254fb3214d2b08U, 0x52532bc528bc6467U }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_26[] = /* primes 3 to 1193 */ { 0x239afcd438799705U, 0xab8a0cda4802bc8fU, 0xb0e87f44a568f618U, 0x7c604708dfb79072U, @@ -359,9 +283,6 @@ static mpw spp_26[] = /* primes 3 to 1193 */ 0x66aa84bf84d4448dU, 0x2119029166db27bdU, 0x515599cdcd147810U, 0x3acf73e7fe62aed9U }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_27[] = /* primes 3 to 1231 */ { 0x0654f0d4cdacb307U, 0x5419612fae3cf746U, 0xfbab751fd0887955U, 0x28adc68d26f32877U, @@ -378,9 +299,6 @@ static mpw spp_27[] = /* primes 3 to 1231 */ 0x55e0d645628c5475U, 0x6217c0bdf119900bU, 0x05ea71dd714fd2c9U }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_28[] = /* primes 3 to 1283 */ { 0x01662c66dab7a4faU, 0xdba4265ac2075912U, 0x59e9c885e1330cb6U, 0xc91bee92f1b334ffU, @@ -397,9 +315,6 @@ static mpw spp_28[] = /* primes 3 to 1283 */ 0x4548a05562ed1c09U, 0x1a63309bf1a9df8bU, 0xf0c59af912a62c22U, 0xe1e1f49bb0115c17U }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_29[] = /* primes 3 to 1307 */ { 0x005cda0c54b07f4fU, 0xff0caca07cc89b95U, 0x1c021191164be693U, 0x6665357ebb2f689cU, @@ -417,9 +332,6 @@ static mpw spp_29[] = /* primes 3 to 1307 */ 0xd052c10abfc67bf6U, 0x915d44352688091bU, 0x1eb1c7117c91eae5U }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_30[] = /* primes 3 to 1381 */ { 0xa0604bc54c251adeU, 0xcf22bf075a150bb1U, 0x2a67d65a5045c183U, 0x172466270d72a8c6U, @@ -437,9 +349,6 @@ static mpw spp_30[] = /* primes 3 to 1381 */ 0xca98bda05c0c6ac6U, 0x666daad014d2ff3fU, 0x7138fa68ddd5e9f0U, 0xe92edcaa62b56483U }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_31[] = /* primes 3 to 1433 */ { 0x4742fdaff7e8231aU, 0xded6827758493423U, 0x12b13d2f5925c539U, 0x82d876ef7ff69e7fU, @@ -458,9 +367,6 @@ static mpw spp_31[] = /* primes 3 to 1433 */ 0x177c5dc0fbfbb491U, 0xa1e5e03e5715875cU, 0xa02a0fa41fde7abdU }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_32[] = /* primes 3 to 1471 */ { 0x2465a7bd85011e1cU, 0x9e0527929fff268cU, 0x82ef7efa416863baU, 0xa5acdb0971dba0ccU, @@ -481,129 +387,78 @@ static mpw spp_32[] = /* primes 3 to 1471 */ #elif (MP_WBITS == 32) -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_01[] = /* primes 3 to 29 */ { 0xc0cfd797U }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_02[] = /* primes 3 to 53 */ { 0xe221f97cU, 0x30e94e1dU }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_03[] = /* primes 3 to 73 */ { 0x41cd66acU, 0xc237b226U, 0x81a18067U }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_04[] = /* primes 3 to 101 */ { 0x5797d47cU, 0x51681549U, 0xd734e4fcU, 0x4c3eaf7fU }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_05[] = /* primes 3 to 113 */ { 0x02c4b8d0U, 0xd2e0d937U, 0x3935200fU, 0xb49be231U, 0x5ce1a307U }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_06[] = /* primes 3 to 149 */ { 0x1e6d8e2aU, 0x0ffceafbU, 0xbcbfc14aU, 0x4c3bc1e1U, 0x009c6a22U, 0xa0a7adf5U }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_07[] = /* primes 3 to 167 */ { 0x049265d3U, 0x574cefd0U, 0x4229bfd6U, 0x62a4a46fU, 0x8611ed02U, 0x26c655f0U, 0x76ebade3U }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_08[] = /* primes 3 to 193 */ { 0xdbf05b6fU, 0x5654b3c0U, 0xf5243551U, 0x43958688U, 0x9f155887U, 0x819aed2aU, 0xc05b9335U, 0x2be98677U }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_09[] = /* primes 3 to 223 */ { 0x5e75cec8U, 0xb5de5ea1U, 0x5da8302aU, 0x2f28b4adU, 0x2735bdc3U, 0x9344c52eU, 0x67570925U, 0x6feb71efU, 0x6811d741U }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_10[] = /* primes 3 to 239 */ { 0x3faa5dadU, 0xb695ce58U, 0x4a579328U, 0xeab20f1fU, 0xef00fe27U, 0xffc36456U, 0x0a65723eU, 0x27d8884aU, 0xd59da0a9U, 0x92f77529U }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_11[] = /* primes 3 to 263 */ { 0x3c9b6e49U, 0xb7cf685bU, 0xe7f3a239U, 0xfb4084cbU, 0x166885e3U, 0x9d4f65b4U, 0x0bb0e51cU, 0x0a5d36feU, 0x98c32069U, 0xfd5c441cU, 0x6d82f115U }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_12[] = /* primes 3 to 281 */ { 0x501201ccU, 0x51a492a5U, 0x44d3900aU, 0xd4f8b32aU, 0x203c8584U, 0x06a4457cU, 0xab0b4f80U, 0x5ab18ac6U, 0xeb9572acU, 0x6e9394faU, 0x522bffb6U, 0xf44af2f3U }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_13[] = /* primes 3 to 311 */ { 0x9397b5b4U, 0x414dc331U, 0x04561364U, 0x79958cc8U, 0xfd5ea01fU, 0x5d5e9f61U, 0xbd0f1cb6U, 0x24af7e6aU, 0x3284dbb2U, 0x9857622bU, 0x8be980a6U, 0x5456a5c1U, 0xed928009U }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_14[] = /* primes 3 to 331 */ { 0x0120eb4dU, 0x70279230U, 0x9ed122fcU, 0xe0488be4U, 0x1d0c99f5U, 0xd8c039adU, 0x058c90b4U, 0x780500feU, 0xf39c05ccU, 0x09817a27U, 0xc3e1776aU, 0x246b6af2U, 0x946a10d6U, 0x6eafaedfU }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_15[] = /* primes 3 to 353 */ { 0x03c91dd1U, 0x2e893191U, 0x94095649U, 0x874b41d6U, 0x05810c06U, 0x195d70ebU, 0xbd54a862U, 0x50c52733U, 0x06dc6648U, 0x1c251ca4U, 0xa02c9a04U, 0x78c96f0dU, 0x02f0db0bU, 0x39d624caU, 0x0b0441c1U }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_16[] = /* primes 3 to 379 */ { 0x106aa9fbU, 0x7646fa6eU, 0xb0813c28U, 0xc5d5f09fU, 0x077ec3baU, 0x238bfb99U, 0xc1b631a2U, 0x03e81187U, 0x233db117U, 0xcbc38405U, 0x6ef04659U, 0xa4a11de4U, 0x9f7ecb29U, 0xbada8f98U, 0x0decece9U, 0x2e30c48fU }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_17[] = /* primes 3 to 401 */ { 0x5aa88d8cU, 0x594bb372U, 0xc4bc813fU, 0x4a87a266U, 0x1f984840U, 0xdab15692U, 0x2c2a177dU, 0x95843665U, @@ -611,9 +466,6 @@ static mpw spp_17[] = /* primes 3 to 401 */ 0x3b3536a4U, 0x0b2745bdU, 0xadf1a6c9U, 0x7b23e85aU, 0xdc6695c1U }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_18[] = /* primes 3 to 421 */ { 0x0185dbebU, 0x2b8b11d3U, 0x7633e9dcU, 0x1eec5415U, 0x65c6ce84U, 0x31d227eeU, 0x28f0328aU, 0x60c90118U, @@ -621,9 +473,6 @@ static mpw spp_18[] = /* primes 3 to 421 */ 0xf35e9745U, 0x79072ec8U, 0xcaf1ac8eU, 0xefd5566fU, 0xa15fb94fU, 0xe34f5d37U }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_19[] = /* primes 3 to 443 */ { 0x0cde6fd1U, 0xcf108066U, 0xcc548df9U, 0x070e102cU, 0x2c651b88U, 0x5f24f503U, 0xaaffe276U, 0xfeb57311U, @@ -631,9 +480,6 @@ static mpw spp_19[] = /* primes 3 to 443 */ 0xc43f999dU, 0x5d06b89fU, 0xcb22e533U, 0x5a9287bcU, 0x6d75a3e9U, 0x1e53906dU, 0x413163d5U }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_20[] = /* primes 3 to 463 */ { 0x833a505cU, 0xf9922beeU, 0xc80265a6U, 0xd50e1cceU, 0xa22f6fecU, 0x2eb84450U, 0xcec64a3cU, 0x0e10d472U, @@ -641,9 +487,6 @@ static mpw spp_20[] = /* primes 3 to 463 */ 0x5e210232U, 0x67bda426U, 0x738730cfU, 0xb8e6e2aeU, 0xc08c9d4bU, 0xd2420066U, 0xdccf95efU, 0x49a560b7U }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_21[] = /* primes 3 to 487 */ { 0x035417f1U, 0xe321c06cU, 0xbe32ffceU, 0xae752cc9U, 0xa9fe11a6U, 0x3d94c946U, 0x456edd7dU, 0x5a060de1U, @@ -652,9 +495,6 @@ static mpw spp_21[] = /* primes 3 to 487 */ 0x491cbd61U, 0x55e565afU, 0x4a9f4331U, 0x0adbb0d7U, 0x06e86f6dU }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_22[] = /* primes 3 to 509 */ { 0x309d024bU, 0xd5380319U, 0x2ca33469U, 0x0bafb43aU, 0x0abd5840U, 0xfbeb24d1U, 0xf49b6330U, 0x47902baeU, @@ -663,9 +503,6 @@ static mpw spp_22[] = /* primes 3 to 509 */ 0x8ffd0db8U, 0xe8fa61a1U, 0x6e1c0970U, 0xbeb81adcU, 0xf49c82dfU, 0xf960d36fU }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_23[] = /* primes 3 to 541 */ { 0x01ab244aU, 0x33bc047eU, 0x804590b4U, 0xc3207237U, 0xea503fa0U, 0x7541b251U, 0x57cfd03fU, 0xf602c9d0U, @@ -674,9 +511,6 @@ static mpw spp_23[] = /* primes 3 to 541 */ 0xb6a5129cU, 0x7699fb5cU, 0xccec6d45U, 0x56c9b8eaU, 0xfa05897cU, 0xb8c5cf72U, 0xb77603d9U }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_24[] = /* primes 3 to 569 */ { 0x25eac89fU, 0x8d4da338U, 0x337b4985U, 0x0d2d1489U, 0x2663177bU, 0x4010af3dU, 0xd23eeb0bU, 0x228f3832U, @@ -685,9 +519,6 @@ static mpw spp_24[] = /* primes 3 to 569 */ 0x93c158c1U, 0xa9a8227fU, 0xf81a90c5U, 0x630e9c44U, 0x845c755cU, 0x7df35a7dU, 0x430c679aU, 0x11575655U }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_25[] = /* primes 3 to 587 */ { 0x01b515a8U, 0xdca3d6e4U, 0x69090373U, 0x84febfe8U, 0xf32e06cfU, 0x9bde8c89U, 0x6b3f992fU, 0x2ff23508U, @@ -697,9 +528,6 @@ static mpw spp_25[] = /* primes 3 to 587 */ 0x6b3faafcU, 0x0f200b35U, 0x7485ce4aU, 0x2f08f148U, 0xcce6887dU }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_26[] = /* primes 3 to 607 */ { 0x3383219dU, 0x26454f06U, 0xe2789b7fU, 0x9c3b940eU, 0x03be2105U, 0x798e3ff7U, 0x945bd325U, 0x997bc262U, @@ -709,9 +537,6 @@ static mpw spp_26[] = /* primes 3 to 607 */ 0xde195be8U, 0x6e66ba89U, 0xb0ab042dU, 0x3276976cU, 0x3dbeb3d7U, 0x413ea96dU }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_27[] = /* primes 3 to 619 */ { 0x02ced4b7U, 0xf15179e8U, 0x7fcba6daU, 0x7b07a6f3U, 0xf9311218U, 0xa7b88985U, 0xac74b503U, 0xbf745330U, @@ -721,9 +546,6 @@ static mpw spp_27[] = /* primes 3 to 619 */ 0x80751585U, 0xc70e20c2U, 0x2d15d3feU, 0xc1b40c7fU, 0x8e25dd07U, 0xdb09dd86U, 0x791aa9e3U }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_28[] = /* primes 3 to 647 */ { 0x6e026454U, 0x60adbd18U, 0xcd52ce1aU, 0x1beab1c0U, 0x36e468e9U, 0xf350d69bU, 0x1d357d08U, 0x3a59f778U, @@ -733,9 +555,6 @@ static mpw spp_28[] = /* primes 3 to 647 */ 0xc74d951dU, 0xb361f061U, 0xc4d14f00U, 0x0d806db4U, 0xcd939110U, 0xc7cab492U, 0x2f3ea4c4U, 0x852ca469U }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_29[] = /* primes 3 to 661 */ { 0x074921f7U, 0x6a76cec3U, 0xaeb05f74U, 0x60b21f16U, 0x49dece2fU, 0x21bb3ed9U, 0xe4cb4ebcU, 0x05d6f408U, @@ -746,9 +565,6 @@ static mpw spp_29[] = /* primes 3 to 661 */ 0xc7001c45U, 0x4a84a45dU, 0x66007591U, 0x27e85693U, 0x2288d0fbU }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_30[] = /* primes 3 to 683 */ { 0x00872313U, 0x1f66758aU, 0x414bbebbU, 0x2f8670bfU, 0x01dc959dU, 0x74468901U, 0x57c57f40U, 0xe210c9c2U, @@ -759,9 +575,6 @@ static mpw spp_30[] = /* primes 3 to 683 */ 0xe61b766eU, 0xc0943254U, 0x1cd70f0fU, 0xd5a0ce6bU, 0x8ab998fbU, 0x8ab36e0dU }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_31[] = /* primes 3 to 719 */ { 0x1e595df4U, 0x3064a8c9U, 0xd61ae17bU, 0xde1938f0U, 0x22ee6357U, 0x35f4caddU, 0x3d39f473U, 0xafed7df5U, @@ -772,9 +585,6 @@ static mpw spp_31[] = /* primes 3 to 719 */ 0x20969ec0U, 0x1a480d31U, 0x331b3252U, 0x01b36fabU, 0x3d5b415bU, 0x1a4567e7U, 0x3baf6389U }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static mpw spp_32[] = /* primes 3 to 739 */ { 0x02c85ff8U, 0x70f24be8U, 0x0f62b1baU, 0x6c20bd72U, 0xb837efdfU, 0x121206d8U, 0x7db56b7dU, 0x69fa4c02U, @@ -896,37 +706,57 @@ int mpptrials(size_t bits) return 35; } -/** +/* + * needs workspace of (size*2) words */ -static void mpprndbits(mpbarrett* p, size_t msbclr, size_t lsbset, randomGeneratorContext* rc) - /*@modifies p @*/ +static void mpprndbits(mpbarrett* p, size_t bits, size_t lsbset, const mpnumber* min, const mpnumber* max, randomGeneratorContext* rc, mpw* wksp) { register size_t size = p->size; + register size_t msbclr = MP_WORDS_TO_BITS(size) - bits; - if (p == (mpbarrett*) 0 || p->modl == (mpw*) 0) - return; + /* assume that mpbits(max) == bits */ + /* calculate k=max-min; generate q such that 0 <= q <= k; then set p = q + min */ + /* for the second step, set the appropriate number of bits */ -/*@-noeffectuncon@*/ - (void) rc->rng->next(rc->param, (byte*) p->modl, MP_WORDS_TO_BYTES(size)); -/*@=noeffectuncon@*/ + if (max) + { + mpsetx(size, wksp, max->size, max->data); + } + else + { + mpfill(size, wksp, MP_ALLMASK); + wksp[0] &= (MP_ALLMASK >> msbclr); + } + if (min) + { + mpsetx(size, wksp+size, min->size, min->data); + } + else + { + mpzero(size, wksp+size); + wksp[size] |= (MP_MSBMASK >> msbclr); + } + + mpsub(size, wksp, wksp+size); - if (msbclr != 0) - p->modl[0] &= (MP_ALLMASK >> msbclr); + rc->rng->next(rc->param, (byte*) p->modl, MP_WORDS_TO_BYTES(size)); - p->modl[0] |= (MP_MSBMASK >> msbclr); + p->modl[0] &= (MP_ALLMASK >> msbclr); - if (lsbset != 0) + while (mpgt(size, p->modl, wksp)) + mpsub(size, p->modl, wksp); + + mpadd(size, p->modl, wksp+size); + + if (lsbset) p->modl[size-1] |= (MP_ALLMASK >> (MP_WBITS - lsbset)); } -/** +/* * mppsppdiv_w * needs workspace of (3*size) words */ -static -int mppsppdiv_w(const mpbarrett* p, /*@out@*/ mpw* wksp) - /*@globals mpspprod @*/ - /*@modifies wksp @*/ +int mppsppdiv_w(const mpbarrett* p, mpw* wksp) { /* small prime product trial division test */ register size_t size = p->size; @@ -934,9 +764,7 @@ int mppsppdiv_w(const mpbarrett* p, /*@out@*/ mpw* wksp) if (size > SMALL_PRIMES_PRODUCT_MAX) { mpsetx(size, wksp+size, SMALL_PRIMES_PRODUCT_MAX, mpspprod[SMALL_PRIMES_PRODUCT_MAX-1]); - /*@-compdef@*/ /* LCL: wksp+size undef */ mpgcd_w(size, p->modl, wksp+size, wksp, wksp+2*size); - /*@=compdef@*/ } else { @@ -946,13 +774,10 @@ int mppsppdiv_w(const mpbarrett* p, /*@out@*/ mpw* wksp) return mpisone(size, wksp); } -/** - * mppmilrabtwo_w +/* * needs workspace of (5*size+2) */ -static -int mppmilrabtwo_w(const mpbarrett* p, int s, const mpw* rdata, const mpw* ndata, /*@out@*/ mpw* wksp) - /*@modifies wksp @*/ +int mppmilrabtwo_w(const mpbarrett* p, int s, const mpw* rdata, const mpw* ndata, mpw* wksp) { register size_t size = p->size; register int j = 0; @@ -974,13 +799,10 @@ int mppmilrabtwo_w(const mpbarrett* p, int s, const mpw* rdata, const mpw* ndata } } -/** - * mppmilraba_w +/* * needs workspace of (5*size+2) words */ -static -int mppmilraba_w(const mpbarrett* p, const mpw* adata, int s, const mpw* rdata, const mpw* ndata, /*@out@*/ mpw* wksp) - /*@modifies wksp @*/ +int mppmilraba_w(const mpbarrett* p, const mpw* adata, int s, const mpw* rdata, const mpw* ndata, mpw* wksp) { register size_t size = p->size; register int j = 0; @@ -1002,7 +824,7 @@ int mppmilraba_w(const mpbarrett* p, const mpw* adata, int s, const mpw* rdata, } } -/** +/* * needs workspace of (8*size+2) words */ int mppmilrab_w(const mpbarrett* p, randomGeneratorContext* rc, int t, mpw* wksp) @@ -1029,7 +851,7 @@ int mppmilrab_w(const mpbarrett* p, randomGeneratorContext* rc, int t, mpw* wksp int s; mpcopy(size, ndata, p->modl); - (void) mpsubw(size, ndata, 1); + mpsubw(size, ndata, 1); mpcopy(size, rdata, ndata); s = mprshiftlsz(size, rdata); /* we've split p-1 into (2^s)*r */ @@ -1055,24 +877,48 @@ int mppmilrab_w(const mpbarrett* p, randomGeneratorContext* rc, int t, mpw* wksp return 1; } -/** +/* * needs workspace of (8*size+2) words */ -void mpprnd_w(mpbarrett* p, randomGeneratorContext* rc, size_t bits, int t, const mpnumber* f, mpw* wksp) +int mpprnd_w(mpbarrett* p, randomGeneratorContext* rc, size_t bits, int t, const mpnumber* f, mpw* wksp) +{ + return mpprndr_w(p, rc, bits, t, (const mpnumber*) 0, (const mpnumber*) 0, f, wksp); +} + +/* + * implements IEEE P1363 A.15.6 + * + * f, min, max are optional + */ +int mpprndr_w(mpbarrett* p, randomGeneratorContext* rc, size_t bits, int t, const mpnumber* min, const mpnumber* max, const mpnumber* f, mpw* wksp) { /* * Generate a prime into p with the requested number of bits * * Conditions: size(f) <= size(p) * + * Optional input min: if min is not null, then search p so that min <= p + * Optional input max: if max is not null, then search p so that p <= max * Optional input f: if f is not null, then search p so that GCD(p-1,f) = 1 */ size_t size = MP_BITS_TO_WORDS(bits + MP_WBITS - 1); + /* if min has more bits than what was requested for p, bail out */ + if (min && (mpbits(min->size, min->data) > bits)) + return -1; + + /* if max has a different number of bits than what was requested for p, bail out */ + if (max && (mpbits(max->size, max->data) != bits)) + return -1; + + /* if min is not less than max, bail out */ + if (min && max && mpgex(min->size, min->data, max->size, max->data)) + return -1; + mpbinit(p, size); - if (p->modl != (mpw*) 0) + if (p->modl) { while (1) { @@ -1080,7 +926,7 @@ void mpprnd_w(mpbarrett* p, randomGeneratorContext* rc, size_t bits, int t, cons * Generate a random appropriate candidate prime, and test * it with small prime divisor test BEFORE computing mu */ - mpprndbits(p, MP_WORDS_TO_BITS(size) - bits, 1, rc); + mpprndbits(p, bits, 1, min, max, rc, wksp); /* do a small prime product trial division test on p */ if (!mppsppdiv_w(p, wksp)) @@ -1090,7 +936,7 @@ void mpprnd_w(mpbarrett* p, randomGeneratorContext* rc, size_t bits, int t, cons if (f != (mpnumber*) 0) { mpcopy(size, wksp, p->modl); - (void) mpsubw(size, wksp, 1); + mpsubw(size, wksp, 1); mpsetx(size, wksp+size, f->size, f->data); mpgcd_w(size, wksp, wksp+size, wksp+2*size, wksp+3*size); @@ -1102,12 +948,13 @@ void mpprnd_w(mpbarrett* p, randomGeneratorContext* rc, size_t bits, int t, cons mpbmu_w(p, wksp); if (mppmilrab_w(p, rc, t, wksp)) - return; + return 0; } } + return -1; } -/** +/* * needs workspace of (8*size+2) words */ void mpprndconone_w(mpbarrett* p, randomGeneratorContext* rc, size_t bits, int t, const mpbarrett* q, const mpnumber* f, mpnumber* r, int cofactor, mpw* wksp) @@ -1139,9 +986,8 @@ void mpprndconone_w(mpbarrett* p, randomGeneratorContext* rc, size_t bits, int t while (1) { - mpprndbits(&s, MP_WORDS_TO_BITS(s.size) - sbits, 0, rc); + mpprndbits(&s, sbits, 0, (mpnumber*) 0, (mpnumber*) 0, rc, wksp); - /*@-usedef@*/ /* s is set */ if (cofactor == 1) { mpsetlsb(s.size, s.modl); @@ -1174,8 +1020,8 @@ void mpprndconone_w(mpbarrett* p, randomGeneratorContext* rc, size_t bits, int t /* s.size + q.size may be greater than p.size by 1, but the product will fit exactly into p */ mpsetx(p->size, p->modl, s.size+q->size, wksp); /* multiply by two and add 1 */ - (void) mpmultwo(p->size, p->modl); - (void) mpaddw(p->size, p->modl, 1); + mpmultwo(p->size, p->modl); + mpaddw(p->size, p->modl, 1); /* test if the product actually contains enough bits */ if (mpbits(p->size, p->modl) < bits) continue; @@ -1188,7 +1034,7 @@ void mpprndconone_w(mpbarrett* p, randomGeneratorContext* rc, size_t bits, int t if (f != (mpnumber*) 0) { mpcopy(p->size, wksp, p->modl); - (void) mpsubw(p->size, wksp, 1); + mpsubw(p->size, wksp, 1); mpsetx(p->size, wksp, f->size, f->data); mpgcd_w(p->size, wksp, wksp+p->size, wksp+2*p->size, wksp+3*p->size); if (!mpisone(p->size, wksp+2*p->size)) @@ -1211,11 +1057,10 @@ void mpprndconone_w(mpbarrett* p, randomGeneratorContext* rc, size_t bits, int t continue; mpnset(r, s.size, s.modl); - (void) mpmultwo(r->size, r->data); + mpmultwo(r->size, r->data); mpbfree(&s); return; - /*@=usedef@*/ } } } @@ -1239,7 +1084,6 @@ void mpprndsafe_w(mpbarrett* p, randomGeneratorContext* rc, size_t bits, int t, mpbzero(&q); mpbinit(&q, size); - /*@-usedef@*/ /* q is set */ while (1) { /* @@ -1247,7 +1091,7 @@ void mpprndsafe_w(mpbarrett* p, randomGeneratorContext* rc, size_t bits, int t, * it with small prime divisor test BEFORE computing mu */ - mpprndbits(p, 0, 2, rc); + mpprndbits(p, bits, 2, (mpnumber*) 0, (mpnumber*) 0, rc, wksp); mpcopy(size, q.modl, p->modl); mpdivtwo(size, q.modl); @@ -1275,6 +1119,5 @@ void mpprndsafe_w(mpbarrett* p, randomGeneratorContext* rc, size_t bits, int t, return; } - /*@=usedef@*/ } } diff --git a/beecrypt/mpprime.h b/beecrypt/mpprime.h index 0b7e27f..61e400d 100644 --- a/beecrypt/mpprime.h +++ b/beecrypt/mpprime.h @@ -26,61 +26,31 @@ #ifndef _MPPRIME_H #define _MPPRIME_H -#include "mpbarrett.h" +#include "beecrypt/mpbarrett.h" #define SMALL_PRIMES_PRODUCT_MAX 32 -/** - */ -/*@-exportlocal@*/ -/*@unchecked@*/ extern mpw* mpspprod[SMALL_PRIMES_PRODUCT_MAX]; -/*@=exportlocal@*/ #ifdef __cplusplus extern "C" { #endif -/** - */ BEECRYPTAPI -int mpptrials (size_t bits) - /*@*/; - -/** - */ +int mpptrials (size_t); BEECRYPTAPI -int mppmilrab_w (const mpbarrett* p, randomGeneratorContext* rc, int t, /*@out@*/ mpw* wksp) - /*@modifies wksp @*/; +int mppmilrab_w (const mpbarrett*, randomGeneratorContext*, int, mpw*); -/** - */ BEECRYPTAPI -void mpprnd_w (mpbarrett* p, randomGeneratorContext* rc, size_t bits, int t, /*@null@*/ const mpnumber* f, /*@out@*/ mpw* wksp) - /*@globals mpspprod @*/ - /*@modifies p, rc, wksp @*/; - -/** - */ +int mpprnd_w (mpbarrett*, randomGeneratorContext*, size_t, int, const mpnumber*, mpw*); BEECRYPTAPI -void mpprndsafe_w (mpbarrett* p, randomGeneratorContext* rc, size_t bits, int t, /*@out@*/ mpw* wksp) - /*@globals mpspprod @*/ - /*@modifies p, rc, wksp @*/; - -#ifdef NOTYET -/** - */ -BEECRYPTAPI /*@unused@*/ -void mpprndcon_w (mpbarrett* p, randomGeneratorContext* rc, size_t, int, const mpnumber*, const mpnumber*, const mpnumber*, mpnumber*, /*@out@*/ mpw* wksp) - /*@modifies wksp @*/; -#endif - -/** - */ +int mpprndr_w (mpbarrett*, randomGeneratorContext*, size_t, int, const mpnumber*, const mpnumber*, const mpnumber*, mpw*); +BEECRYPTAPI +void mpprndsafe_w (mpbarrett*, randomGeneratorContext*, size_t, int, mpw*); +BEECRYPTAPI +void mpprndcon_w (mpbarrett*, randomGeneratorContext*, size_t, int, const mpnumber*, const mpnumber*, const mpnumber*, mpnumber*, mpw*); BEECRYPTAPI -void mpprndconone_w(mpbarrett* p, randomGeneratorContext* rc, size_t bits, int t, const mpbarrett* q, /*@null@*/ const mpnumber* f, mpnumber* r, int cofactor, /*@out@*/ mpw* wksp) - /*@globals mpspprod @*/ - /*@modifies p, rc, r, wksp @*/; +void mpprndconone_w(mpbarrett*, randomGeneratorContext*, size_t, int, const mpbarrett*, const mpnumber*, mpnumber*, int, mpw*); #ifdef __cplusplus } diff --git a/beecrypt/mtprng.c b/beecrypt/mtprng.c index 9e6ad8c..2f4c0a8 100644 --- a/beecrypt/mtprng.c +++ b/beecrypt/mtprng.c @@ -1,8 +1,6 @@ /* * Copyright (c) 1998, 1999, 2000, 2001 Virtual Unlimited B.V. * - * Author: Bob Deblier - * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either @@ -28,35 +26,31 @@ * Adapted from optimized code by Shawn J. Cokus * * \warning This generator has a very long period, passes statistical test and - & is very fast, but is not recommended for use in cryptography. - * - * \author Bob Deblier + * is very fast, but is not recommended for use in cryptography. + * + * \author Bob Deblier * \ingroup PRNG_m */ -#include "system.h" -#include "beecrypt.h" -#include "mtprng.h" -#include "mpopt.h" -#include "mp.h" -#include "debug.h" +#define BEECRYPT_DLL_EXPORT + +#if HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/mtprng.h" #define hiBit(a) ((a) & 0x80000000U) #define loBit(a) ((a) & 0x1U) #define loBits(a) ((a) & 0x7FFFFFFFU) #define mixBits(a, b) (hiBit(a) | loBits(b)) -/*@-sizeoftype@*/ const randomGenerator mtprng = { "Mersenne Twister", sizeof(mtprngParam), (randomGeneratorSetup) mtprngSetup, (randomGeneratorSeed) mtprngSeed, (randomGeneratorNext) mtprngNext, (randomGeneratorCleanup) mtprngCleanup }; -/*@=sizeoftype@*/ -/** - */ static void mtprngReload(mtprngParam* mp) - /*@modifies mp @*/ { register uint32_t *p0 = mp->state; - register uint32_t *p2=p0+2, *pM = p0+M, s0, s1; + register uint32_t *p2 = p0+2, *pM = p0+M, s0, s1; register int j; for (s0=mp->state[0], s1=mp->state[1], j=N-M+1; --j; s0=s1, s1=*(p2++)) @@ -84,19 +78,15 @@ int mtprngSetup(mtprngParam* mp) if (mutex_init(&mp->lock, USYNC_THREAD, (void *) 0)) return -1; # elif HAVE_PTHREAD_H - /*@-nullpass@*/ - /*@-moduncon@*/ if (pthread_mutex_init(&mp->lock, (pthread_mutexattr_t *) 0)) return -1; - /*@=moduncon@*/ - /*@=nullpass@*/ # endif # endif #endif mp->left = 0; - return entropyGatherNext((byte*)mp->state, sizeof(mp->state)); + return entropyGatherNext((byte*) mp->state, (N+1) * sizeof(uint32_t)); } return -1; } @@ -105,8 +95,8 @@ int mtprngSeed(mtprngParam* mp, const byte* data, size_t size) { if (mp) { - size_t needed = sizeof(mp->state); - byte* dest = (byte *) mp->state; + size_t needed = (N+1) * sizeof(uint32_t); + byte* dest = (byte*) mp->state; #ifdef _REENTRANT # if WIN32 @@ -117,10 +107,8 @@ int mtprngSeed(mtprngParam* mp, const byte* data, size_t size) if (mutex_lock(&mp->lock)) return -1; # elif HAVE_PTHREAD_H - /*@-moduncon@*/ if (pthread_mutex_lock(&mp->lock)) return -1; - /*@=moduncon@*/ # endif # endif #endif @@ -140,10 +128,8 @@ int mtprngSeed(mtprngParam* mp, const byte* data, size_t size) if (mutex_unlock(&mp->lock)) return -1; # elif HAVE_PTHREAD_H - /*@-moduncon@*/ if (pthread_mutex_unlock(&mp->lock)) return -1; - /*@=moduncon@*/ # endif # endif #endif @@ -167,14 +153,11 @@ int mtprngNext(mtprngParam* mp, byte* data, size_t size) if (mutex_lock(&mp->lock)) return -1; # elif HAVE_PTHREAD_H - /*@-moduncon@*/ if (pthread_mutex_lock(&mp->lock)) return -1; - /*@=moduncon@*/ # endif # endif #endif - /*@-branchstate@*/ while (size > 0) { if (mp->left == 0) @@ -187,10 +170,10 @@ int mtprngNext(mtprngParam* mp, byte* data, size_t size) tmp ^= (tmp >> 18); mp->left--; - if (size >= sizeof(tmp)) + if (size >= 4) { - memcpy(data, &tmp, sizeof(tmp)); - size -= sizeof(tmp); + memcpy(data, &tmp, 4); + size -= 4; } else { @@ -198,7 +181,6 @@ int mtprngNext(mtprngParam* mp, byte* data, size_t size) size = 0; } } - /*@=branchstate@*/ #ifdef _REENTRANT # if WIN32 if (!ReleaseMutex(mp->lock)) @@ -208,10 +190,8 @@ int mtprngNext(mtprngParam* mp, byte* data, size_t size) if (mutex_unlock(&mp->lock)) return -1; # elif HAVE_PTHREAD_H - /*@-moduncon@*/ if (pthread_mutex_unlock(&mp->lock)) return -1; - /*@=moduncon@*/ # endif # endif #endif @@ -233,10 +213,8 @@ int mtprngCleanup(mtprngParam* mp) if (mutex_destroy(&mp->lock)) return -1; # elif HAVE_PTHREAD_H - /*@-moduncon@*/ if (pthread_mutex_destroy(&mp->lock)) return -1; - /*@=moduncon@*/ # endif # endif #endif diff --git a/beecrypt/mtprng.h b/beecrypt/mtprng.h index ddd3be7..4e60318 100644 --- a/beecrypt/mtprng.h +++ b/beecrypt/mtprng.h @@ -19,76 +19,65 @@ /*!\file mtprng.h * \brief Mersenne Twister pseudo-random number generator, headers. - * \author Bob Deblier + * \author Bob Deblier * \ingroup PRNG_m */ #ifndef _MTPRNG_H #define _MTPRNG_H -#include "beecrypt.h" +#include "beecrypt/beecrypt.h" + +#ifdef _REENTRANT +# if WIN32 +# include +# include +# endif +#endif #define N 624 #define M 397 #define K 0x9908B0DFU -/** +/* */ typedef struct { #ifdef _REENTRANT - # if WIN32 - HANDLE lock; - # else - bc_lock_t lock; - # endif + bc_mutex_t lock; #endif - uint32_t state[N+1]; - uint32_t left; -/*@kept@*/ - uint32_t* nextw; + uint32_t state[N+1]; + uint32_t left; + uint32_t* nextw; } mtprngParam; #ifdef __cplusplus extern "C" { #endif -/** +/* */ -/*@observer@*/ /*@checked@*/ extern BEECRYPTAPI const randomGenerator mtprng; -/** +/* */ -/*@-exportlocal@*/ BEECRYPTAPI -int mtprngSetup (mtprngParam* mp) - /*@modifies mp @*/; -/*@=exportlocal@*/ +int mtprngSetup (mtprngParam* mp); -/** +/* */ -/*@-exportlocal@*/ BEECRYPTAPI -int mtprngSeed (mtprngParam* mp, const byte* data, size_t size) - /*@modifies mp @*/; -/*@=exportlocal@*/ +int mtprngSeed (mtprngParam* mp, const byte* data, size_t size); -/** +/* */ -/*@-exportlocal@*/ BEECRYPTAPI -int mtprngNext (mtprngParam* mp, byte* data, size_t size) - /*@modifies mp, data @*/; -/*@=exportlocal@*/ +int mtprngNext (mtprngParam* mp, byte* data, size_t size); -/** +/* */ -/*@-exportlocal@*/ BEECRYPTAPI -int mtprngCleanup(mtprngParam* mp) - /*@modifies mp @*/; -/*@=exportlocal@*/ +int mtprngCleanup(mtprngParam* mp); #ifdef __cplusplus } diff --git a/beecrypt/mwerks/.cvsignore b/beecrypt/mwerks/.cvsignore deleted file mode 100644 index 540cfea..0000000 --- a/beecrypt/mwerks/.cvsignore +++ /dev/null @@ -1,19 +0,0 @@ -.deps -.depend -.depend-done -.libs -Makefile -Makefile.in -config.cache -config.guess -config.log -config.status -config.sub -configure -libtool -ltconfig -ltmain.sh -*.o -*.lo -stamp-h -stamp-h.in diff --git a/beecrypt/mwerks/Makefile.am b/beecrypt/mwerks/Makefile.am deleted file mode 100644 index be826af..0000000 --- a/beecrypt/mwerks/Makefile.am +++ /dev/null @@ -1,25 +0,0 @@ -# -# Makefile.am's purpose is to add the Metrowerks CodeWarrior assembler sources to the dist -# -# Copyright (c) 2001 Virtual Unlimited B.V. -# -# Author: Bob Deblier -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# - -AUTOMAKE_OPTIONS = gnu no-dependencies - -EXTRA_DIST = beecrypt.pch blowfishopt.i586.asm mp32opt.i386.asm sha1opt.i586.asm diff --git a/beecrypt/mwerks/beecrypt.pch b/beecrypt/mwerks/beecrypt.pch deleted file mode 100644 index 059bc82..0000000 --- a/beecrypt/mwerks/beecrypt.pch +++ /dev/null @@ -1,6 +0,0 @@ -#include - -#pragma precompile_target "beecrypt.mch" - -#define HAVE_CONFIG_H -#define JAVAGLUE 1 diff --git a/beecrypt/mwerks/blowfishopt.i586.asm b/beecrypt/mwerks/blowfishopt.i586.asm deleted file mode 100644 index 1c283b6..0000000 --- a/beecrypt/mwerks/blowfishopt.i586.asm +++ /dev/null @@ -1,173 +0,0 @@ -# -# blowfishopt.i586.asm -# -# Assembler optimized blowfish routines for Intel Pentium processors -# -# Compile target is Metrowerks CodeWarrior Pro 5 for Windows -# -# Copyright (c) 2000 Virtual Unlimited B.V. -# -# Author: Bob Deblier -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# - -etworounds: .macro p - xor ecx,[esi+p] - rol ecx,16 - mov al,ch - mov bl,cl - rol ecx,16 - mov edi,[esi+eax*4+72+0x000] - add edi,[esi+ebx*4+72+0x400] - mov al,ch - mov bl,cl - xor edi,[esi+eax*4+72+0x800] - add edi,[esi+ebx*4+72+0xC00] - xor edx,edi - xor edx,[esi+p+4] - rol edx,16 - mov al,dh - mov bl,dl - rol edx,16 - mov edi,[esi+eax*4+72+0x000] - add edi,[esi+ebx*4+72+0x400] - mov al,dh - mov bl,dl - xor edi,[esi+eax*4+72+0x800] - add edi,[esi+ebx*4+72+0xC00] - xor ecx,edi - .endm - -dtworounds: .macro p - xor ecx,[esi+p+4] - rol ecx,16 - mov al,ch - mov bl,cl - rol ecx,16 - mov edi,[esi+eax*4+72+0x000] - add edi,[esi+ebx*4+72+0x400] - mov al,ch - mov bl,cl - xor edi,[esi+eax*4+72+0x800] - add edi,[esi+ebx*4+72+0xC00] - xor edx,edi - xor edx,[esi+p] - rol edx,16 - mov al,dh - mov bl,dl - rol edx,16 - mov edi,[esi+eax*4+72+0x000] - add edi,[esi+ebx*4+72+0x400] - mov al,dh - mov bl,dl - xor edi,[esi+eax*4+72+0x800] - add edi,[esi+ebx*4+72+0xC00] - xor ecx,edi - .endm - - .text - - .align 8 - .globl _blowfishEncrypt - -_blowfishEncrypt: - push edi - push esi - push ebx - - mov esi,[esp+16] - mov edi,[esp+24] - - xor eax,eax - xor ebx,ebx - - mov ecx,[edi] - mov edx,[edi+4] - - bswap ecx - bswap edx - - etworounds 0 - etworounds 8 - etworounds 16 - etworounds 24 - etworounds 32 - etworounds 40 - etworounds 48 - etworounds 56 - - mov edi,[esp+20] - xor ecx,[esi+64] - xor edx,[esi+68] - - bswap ecx - bswap edx - - mov [edi+4],ecx - mov [edi],edx - - xor eax,eax - - pop ebx - pop esi - pop edi - ret - - .align 8 - .globl _blowfishDecrypt - -_blowfishDecrypt: - push edi - push esi - push ebx - - mov esi,[esp+16] - mov edi,[esp+24] - - xor eax,eax - xor ebx,ebx - - mov ecx,[edi] - mov edx,[edi+4] - - bswap ecx - bswap edx - - dtworounds 64 - dtworounds 56 - dtworounds 48 - dtworounds 40 - dtworounds 32 - dtworounds 24 - dtworounds 16 - dtworounds 8 - - mov edi,[esp+20] - xor ecx,[esi+4] - xor edx,[esi] - - bswap ecx - bswap edx - - mov [edi+4],ecx - mov [edi],edx - - xor eax,eax - - pop ebx - pop esi - pop edi - ret diff --git a/beecrypt/mwerks/mp32opt.i386.asm b/beecrypt/mwerks/mp32opt.i386.asm deleted file mode 100644 index a5dd319..0000000 --- a/beecrypt/mwerks/mp32opt.i386.asm +++ /dev/null @@ -1,299 +0,0 @@ -# -# mp32opt.i386.asm -# -# Assembler optimized multiprecision integer routines for Intel 386 -# -# Compile target is MetroWerks CodeWarrior Pro 5 for Windows -# -# Copyright (c) 1998, 1999, 2000, 2001 Virtual Unlimited B.V. -# -# Author: Bob Deblier -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# - - .text - - .align 8 - .globl _mp32zero -_mp32zero: - push edi - - mov ecx,[esp+8] - mov edi,[esp+12] - - xor eax,eax - rep stosd - - pop edi - ret - - - .align 8 - .globl _mp32fill -_mp32fill: - push edi - - mov ecx,[esp+8] - mov edi,[esp+12] - mov eax,[esp+16] - - rep stosd - - pop edi - ret - - - .align 8 - .globl _mp32odd -_mp32odd: - mov ecx,[esp+4] - mov eax,[esp+8] - mov eax,[eax+ecx*4-4] - and eax,1 - ret - - - .align 8 - .globl _mp32even -_mp32even: - mov ecx,[esp+4] - mov eax,[esp+8] - mov eax,[eax+ecx*4-4] - not eax - and eax,1 - ret - - - .align 8 - .globl _mp32addw -_mp32addw: - push edi - - mov ecx,[esp+8] - mov edi,[esp+12] - mov eax,[esp+16] - - lea edi,[edi+ecx*4-4] - add [edi],eax - dec ecx - jz @mp32addw_end - sub edi,4 - xor edx,edx - - .align 4 -@mp32addw_loop: - adc [edi],edx - sub edi,4 - dec ecx - jnz @mp32addw_loop -@mp32addw_end: - sbb eax,eax - neg eax - - pop edi - ret - - - .align 8 - .globl _mp32subw -_mp32subw: - push edi - - mov ecx,[esp+8] - mov edi,[esp+12] - mov eax,[esp+16] - - lea edi,[edi+ecx*4-4] - sub [edi],eax - dec ecx - jz @mp32subw_end - sub edi,4 - xor edx,edx - - .align 4 -@mp32subw_loop: - sbb [edi],edx - sub edi,4 - dec ecx - jnz @mp32subw_loop -@mp32subw_end: - sbb eax,eax - neg eax - - pop edi - ret - - - .align 8 - .globl _mp32add -_mp32add: - push edi - push esi - - mov ecx,[esp+12] - mov edi,[esp+16] - mov esi,[esp+20] - - xor edx,edx - dec ecx - -@mp32add_loop: - mov eax,[esi+ecx*4] - adc [edi+ecx*4],eax - dec ecx - jns @mp32add_loop - - sbb eax,eax - neg eax - - pop esi - pop edi - ret - - - .align 8 - .globl _mp32sub -_mp32sub: - push edi - push esi - - mov ecx,[esp+12] - mov edi,[esp+16] - mov esi,[esp+20] - - xor edx,edx - dec ecx - -@mp32sub_loop: - mov eax,[esi+ecx*4] - sbb [edi+ecx*4],eax - dec ecx - jns @mp32sub_loop - - sbb eax,eax - neg eax - - pop esi - pop edi - ret - - - .align 8 - .globl _mp32setmul -_mp32setmul: - push edi - push esi - push ebx - push ebp - - mov ecx,[esp+20] - mov edi,[esp+24] - mov esi,[esp+28] - mov ebp,[esp+32] - - xor edx,edx - dec ecx - - .align 4 -@mp32setmul_loop: - mov ebx,edx - mov eax,[esi+ecx*4] - mul ebp - add eax,ebx - adc edx,0 - mov [edi+ecx*4],eax - dec ecx - jns @mp32setmul_loop - - mov eax,edx - - pop ebp - pop ebx - pop esi - pop edi - ret - - - .align 8 - .globl _mp32addmul -_mp32addmul: - push edi - push esi - push ebx - push ebp - - mov ecx,[esp+20] - mov edi,[esp+24] - mov esi,[esp+28] - mov ebp,[esp+32] - - xor edx,edx - dec ecx - - .align 4 -@mp32addmul_loop: - mov ebx,edx - mov eax,[esi+ecx*4] - mul ebp - add eax,ebx - adc edx,0 - add [edi+ecx*4],eax - adc edx,0 - dec ecx - jns @mp32addmul_loop - - mov eax,edx - - pop ebp - pop ebx - pop esi - pop edi - ret - - - .align 8 - .globl _mp32addsqrtrc -_mp32addsqrtrc: - push edi - push esi - push ebx - - mov ecx,[esp+16] - mov edi,[esp+20] - mov esi,[esp+24] - - xor ebx,ebx - dec ecx - - .align 4 -@mp32addsqrtrc_loop: - mov eax,[esi+ecx*4] - mul eax - add eax,ebx - adc edx,0 - add [edi+ecx*8+4],eax - adc [edi+ecx*8+0],edx - sbb ebx,ebx - neg ebx - dec ecx - jns @mp32addsqrtrc_loop - - mov eax,ebx - - pop ebx - pop esi - pop edi - ret diff --git a/beecrypt/mwerks/sha1opt.i586.asm b/beecrypt/mwerks/sha1opt.i586.asm deleted file mode 100644 index d4d64a6..0000000 --- a/beecrypt/mwerks/sha1opt.i586.asm +++ /dev/null @@ -1,292 +0,0 @@ -# -# sha1opt.i586.asm -# -# Assembler optimized SHA-1 routines for Intel Pentium processors -# -# Compile target is Metrowerks CodeWarrior Pro 5 for Windows -# -# Copyright (c) 2000 Virtual Unlimited B.V. -# -# Author: Bob Deblier -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# - -K00 .equ 0x5a827999 -K20 .equ 0x6ed9eba1 -K40 .equ 0x8f1bbcdc -K60 .equ 0xca62c1d6 - -PARAM_H .equ 0 -PARAM_DATA .equ 20 -PARAM_OFFSET .equ 352 - -subround1: .macro b,c,d,e,w - mov ecx,c - mov ebx,b - mov edx,d - rol eax,5 - xor ecx,edx - add eax,e - and ecx,ebx - add eax,K00 - ror ebx,2 - add eax,w - xor ecx,edx - mov b,ebx - add eax,ecx - mov e,eax - .endm - -subround2: .macro b,c,d,e,w - mov ecx,c - mov ebx,b - rol eax,5 - xor ecx,ebx - add eax,e - xor ecx,d - add eax,K20 - ror ebx,2 - add eax,w - mov b,ebx - add eax,ecx - mov e,eax - .endm - -subround3: .macro b,c,d,e,w - mov ecx,c - rol eax,5 - mov ebx,b - mov edx,ecx - add eax,e - or ecx,ebx # (b|c) - and edx,ebx # (b&c) - and ecx,d # (b|c)&d - add eax,K40 - or ecx,edx - add eax,w - ror ebx,2 - add eax,ecx - mov b,ebx - mov e,eax - .endm - -subround4: .macro b,c,d,e,w - mov ecx,c - mov ebx,b - rol eax,5 - xor ecx,ebx - add eax,e - xor ecx,d - add eax,K60 - ror ebx,2 - add eax,w - mov b,ebx - add eax,ecx - mov e,eax - .endm - - .text - - .align 8 - .globl _sha1Process - -_sha1Process: - push edi - push esi - push ebx - push ebp - # allocate local variables - mov esi,[esp+20] - sub esp,20 - lea edi,[esi+PARAM_DATA] - mov ebp,esp - - mov ecx,4 -@loads: - mov edx,[esi+ecx*4] - mov [ebp+ecx*4],edx - dec ecx - jns @loads - - mov ecx,15 - xor eax,eax - - .align 4 -@swaps: - mov edx,[edi+ecx*4] - bswap edx - mov [edi+ecx*4],edx - dec ecx - jns @swaps - - lea edi,[esi+PARAM_DATA] - mov [esi+PARAM_OFFSET],al - mov ecx,16 - - .align 4 -@xors: - mov eax,[edi+52] - mov ebx,[edi+56] - xor eax,[edi+32] - xor ebx,[edi+36] - xor eax,[edi+ 8] - xor ebx,[edi+12] - xor eax,[edi ] - xor ebx,[edi+ 4] - rol eax,1 - rol ebx,1 - mov [edi+64],eax - mov [edi+68],ebx - mov eax,[edi+60] - mov ebx,[edi+64] - xor eax,[edi+40] - xor ebx,[edi+44] - xor eax,[edi+16] - xor ebx,[edi+20] - xor eax,[edi+ 8] - xor ebx,[edi+12] - rol eax,1 - rol ebx,1 - mov [edi+72],eax - mov [edi+76],ebx - add edi,16 - dec ecx - jnz @xors - - mov edi,PARAM_DATA - - # to optimize further, use esi only, and store the add constant into edi - # will make code smaller and faster - -@round01to20: - mov eax,[ebp] - subround1 [ebp+4],[ebp+8],[ebp+12],[ebp+16],[esi+edi] - subround1 [ebp],ebx,[ebp+8],[ebp+12],[esi+edi+4] - subround1 [ebp+16],ebx,[ebp+4],[ebp+8],[esi+edi+8] - subround1 [ebp+12],ebx,[ebp],[ebp+4],[esi+edi+12] - subround1 [ebp+8],ebx,[ebp+16],[ebp],[esi+edi+16] - add edi,20 - subround1 [ebp+4],ebx,[ebp+12],[ebp+16],[esi+edi] - subround1 [ebp],ebx,[ebp+8],[ebp+12],[esi+edi+4] - subround1 [ebp+16],ebx,[ebp+4],[ebp+8],[esi+edi+8] - subround1 [ebp+12],ebx,[ebp],[ebp+4],[esi+edi+12] - subround1 [ebp+8],ebx,[ebp+16],[ebp],[esi+edi+16] - add edi,20 - subround1 [ebp+4],ebx,[ebp+12],[ebp+16],[esi+edi] - subround1 [ebp],ebx,[ebp+8],[ebp+12],[esi+edi+4] - subround1 [ebp+16],ebx,[ebp+4],[ebp+8],[esi+edi+8] - subround1 [ebp+12],ebx,[ebp],[ebp+4],[esi+edi+12] - subround1 [ebp+8],ebx,[ebp+16],[ebp],[esi+edi+16] - add edi,20 - subround1 [ebp+4],ebx,[ebp+12],[ebp+16],[esi+edi] - subround1 [ebp],ebx,[ebp+8],[ebp+12],[esi+edi+4] - subround1 [ebp+16],ebx,[ebp+4],[ebp+8],[esi+edi+8] - subround1 [ebp+12],ebx,[ebp],[ebp+4],[esi+edi+12] - subround1 [ebp+8],ebx,[ebp+16],[ebp],[esi+edi+16] - add edi,20 - -@round21to40: - subround2 [ebp+4],ebx,[ebp+12],[ebp+16],[esi+edi] - subround2 [ebp],ebx,[ebp+8],[ebp+12],[esi+edi+4] - subround2 [ebp+16],ebx,[ebp+4],[ebp+8],[esi+edi+8] - subround2 [ebp+12],ebx,[ebp],[ebp+4],[esi+edi+12] - subround2 [ebp+8],ebx,[ebp+16],[ebp],[esi+edi+16] - add edi,20 - subround2 [ebp+4],ebx,[ebp+12],[ebp+16],[esi+edi] - subround2 [ebp],ebx,[ebp+8],[ebp+12],[esi+edi+4] - subround2 [ebp+16],ebx,[ebp+4],[ebp+8],[esi+edi+8] - subround2 [ebp+12],ebx,[ebp],[ebp+4],[esi+edi+12] - subround2 [ebp+8],ebx,[ebp+16],[ebp],[esi+edi+16] - add edi,20 - subround2 [ebp+4],ebx,[ebp+12],[ebp+16],[esi+edi] - subround2 [ebp],ebx,[ebp+8],[ebp+12],[esi+edi+4] - subround2 [ebp+16],ebx,[ebp+4],[ebp+8],[esi+edi+8] - subround2 [ebp+12],ebx,[ebp],[ebp+4],[esi+edi+12] - subround2 [ebp+8],ebx,[ebp+16],[ebp],[esi+edi+16] - add edi,20 - subround2 [ebp+4],ebx,[ebp+12],[ebp+16],[esi+edi] - subround2 [ebp],ebx,[ebp+8],[ebp+12],[esi+edi+4] - subround2 [ebp+16],ebx,[ebp+4],[ebp+8],[esi+edi+8] - subround2 [ebp+12],ebx,[ebp],[ebp+4],[esi+edi+12] - subround2 [ebp+8],ebx,[ebp+16],[ebp],[esi+edi+16] - add edi,20 - -@round41to60: - subround3 [ebp+4],ebx,[ebp+12],[ebp+16],[esi+edi] - subround3 [ebp],ebx,[ebp+8],[ebp+12],[esi+edi+4] - subround3 [ebp+16],ebx,[ebp+4],[ebp+8],[esi+edi+8] - subround3 [ebp+12],ebx,[ebp],[ebp+4],[esi+edi+12] - subround3 [ebp+8],ebx,[ebp+16],[ebp],[esi+edi+16] - add edi,20 - subround3 [ebp+4],ebx,[ebp+12],[ebp+16],[esi+edi] - subround3 [ebp],ebx,[ebp+8],[ebp+12],[esi+edi+4] - subround3 [ebp+16],ebx,[ebp+4],[ebp+8],[esi+edi+8] - subround3 [ebp+12],ebx,[ebp],[ebp+4],[esi+edi+12] - subround3 [ebp+8],ebx,[ebp+16],[ebp],[esi+edi+16] - add edi,20 - subround3 [ebp+4],ebx,[ebp+12],[ebp+16],[esi+edi] - subround3 [ebp],ebx,[ebp+8],[ebp+12],[esi+edi+4] - subround3 [ebp+16],ebx,[ebp+4],[ebp+8],[esi+edi+8] - subround3 [ebp+12],ebx,[ebp],[ebp+4],[esi+edi+12] - subround3 [ebp+8],ebx,[ebp+16],[ebp],[esi+edi+16] - add edi,20 - subround3 [ebp+4],ebx,[ebp+12],[ebp+16],[esi+edi] - subround3 [ebp],ebx,[ebp+8],[ebp+12],[esi+edi+4] - subround3 [ebp+16],ebx,[ebp+4],[ebp+8],[esi+edi+8] - subround3 [ebp+12],ebx,[ebp],[ebp+4],[esi+edi+12] - subround3 [ebp+8],ebx,[ebp+16],[ebp],[esi+edi+16] - add edi,20 - -@round61to80: - subround4 [ebp+4],ebx,[ebp+12],[ebp+16],[esi+edi] - subround4 [ebp],ebx,[ebp+8],[ebp+12],[esi+edi+4] - subround4 [ebp+16],ebx,[ebp+4],[ebp+8],[esi+edi+8] - subround4 [ebp+12],ebx,[ebp],[ebp+4],[esi+edi+12] - subround4 [ebp+8],ebx,[ebp+16],[ebp],[esi+edi+16] - add edi,20 - subround4 [ebp+4],ebx,[ebp+12],[ebp+16],[esi+edi] - subround4 [ebp],ebx,[ebp+8],[ebp+12],[esi+edi+4] - subround4 [ebp+16],ebx,[ebp+4],[ebp+8],[esi+edi+8] - subround4 [ebp+12],ebx,[ebp],[ebp+4],[esi+edi+12] - subround4 [ebp+8],ebx,[ebp+16],[ebp],[esi+edi+16] - add edi,20 - subround4 [ebp+4],ebx,[ebp+12],[ebp+16],[esi+edi] - subround4 [ebp],ebx,[ebp+8],[ebp+12],[esi+edi+4] - subround4 [ebp+16],ebx,[ebp+4],[ebp+8],[esi+edi+8] - subround4 [ebp+12],ebx,[ebp],[ebp+4],[esi+edi+12] - subround4 [ebp+8],ebx,[ebp+16],[ebp],[esi+edi+16] - add edi,20 - subround4 [ebp+4],ebx,[ebp+12],[ebp+16],[esi+edi] - subround4 [ebp],ebx,[ebp+8],[ebp+12],[esi+edi+4] - subround4 [ebp+16],ebx,[ebp+4],[ebp+8],[esi+edi+8] - subround4 [ebp+12],ebx,[ebp],[ebp+4],[esi+edi+12] - subround4 [ebp+8],ebx,[ebp+16],[ebp],[esi+edi+16] - # add edi,20 - - mov ecx,4 - -@adds: - mov eax,[ebp+ecx*4] - add [esi+ecx*4],eax - dec ecx - jns @adds - - add esp,20 - pop ebp - pop ebx - pop esi - pop edi - ret diff --git a/beecrypt/pkcs1.c b/beecrypt/pkcs1.c new file mode 100644 index 0000000..d680425 --- /dev/null +++ b/beecrypt/pkcs1.c @@ -0,0 +1,62 @@ +#define BEECRYPT_DLL_EXPORT + +#include "beecrypt/pkcs1.h" + +const byte EMSA_MD5_DIGESTINFO[18] = { + 0x30,0x20,0x30,0x0c,0x06,0x08,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x02,0x05,0x05,0x00, + 0x04,0x10 +}; + +const byte EMSA_SHA1_DIGESTINFO[15] = { + 0x30,0x21,0x30,0x09,0x06,0x05,0x2b,0x0e,0x03,0x02,0x1a,0x05,0x00,0x04,0x14 +}; + +const byte EMSA_SHA256_DIGESTINFO[19] = { + 0x30,0x31,0x30,0x0d,0x06,0x09,0x60,0x86,0x48,0x01,0x65,0x03,0x04,0x02,0x01,0x05, + 0x00,0x04,0x20 +}; + +int pkcs1_emsa_encode_digest(hashFunctionContext* ctxt, byte* emdata, size_t emlen) +{ + int rc = -1; + const byte* tinfo; + size_t tlen, digestsize = ctxt->algo->digestsize; + + if (strcmp(ctxt->algo->name, "MD5") == 0) + { + /* tlen is 18 bytes for EMSA_MD5_DIGESTINFO plus digestsize */ + tinfo = EMSA_MD5_DIGESTINFO; + tlen = 18; + } + else if (strcmp(ctxt->algo->name, "SHA-1") == 0) + { + /* tlen is 15 bytes for EMSA_SHA1_DIGESTINFO plus 20 bytes digest */ + tinfo = EMSA_SHA1_DIGESTINFO; + tlen = 15; + } + else if (strcmp(ctxt->algo->name, "SHA-256") == 0) + { + /* tlen is 19 bytes for EMSA_SHA256_DIGESTINFO plus 32 bytes digest */ + tinfo = EMSA_SHA256_DIGESTINFO; + tlen = 19; + } + else + goto cleanup; + + tlen += digestsize; + + /* fill emdata with 0x00 0x01 0xff .... 0xff 0x00 EMSA_x_DIGESTINFO DIGEST */ + emdata[0] = 0x00; + emdata[1] = 0x01; + memset(emdata+2, 0xff, emlen-tlen-3); + emdata[emlen-tlen-1] = 0x00; + memcpy(emdata+emlen-tlen, tinfo, tlen-digestsize); + + hashFunctionContextDigest(ctxt, emdata+emlen-digestsize); + + rc = 0; + +cleanup: + + return rc; +} diff --git a/beecrypt/pkcs1.h b/beecrypt/pkcs1.h new file mode 100644 index 0000000..336fbf1 --- /dev/null +++ b/beecrypt/pkcs1.h @@ -0,0 +1,27 @@ +/*!\file pkcs1.h + * \brief PKCS#1 utility routines + * \ingroup PKCS1_m + */ + +#ifndef _PKCS1_H +#define _PKCS1_H + +#include "beecrypt/beecrypt.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/*!\brief This function computes the digest, and encodes it it according to PKCS#1 for signing + * \param ctxt The hash function context + * \param emdata + * \param emsize + */ +BEECRYPTAPI +int pkcs1_emsa_encode_digest(hashFunctionContext* ctxt, byte* emdata, size_t emsize); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/beecrypt/pkcs12.c b/beecrypt/pkcs12.c new file mode 100644 index 0000000..b11fe1c --- /dev/null +++ b/beecrypt/pkcs12.c @@ -0,0 +1,81 @@ +#define BEECRYPT_DLL_EXPORT + +#include "beecrypt/pkcs12.h" + +int pkcs12_derive_key(const hashFunction* h, byte id, const byte* pdata, size_t psize, const byte* sdata, size_t ssize, size_t iterationcount, byte* ndata, size_t nsize) +{ + int rc = -1; + size_t i, remain; + hashFunctionContext ctxt; + byte *digest; + + digest = (byte*) malloc(h->digestsize); + if (!digest) + goto cleanup; + + if (hashFunctionContextInit(&ctxt, h)) + goto cleanup; + + /* we start by hashing the diversifier; don't allocate a buffer for this */ + for (i = 0; i < h->blocksize; i++) + hashFunctionContextUpdate(&ctxt, &id, 1); + + /* next we hash the salt data, concatenating until we have a whole number of blocks */ + if (ssize) + { + remain = ((ssize / h->blocksize) + (ssize % h->blocksize)) * h->blocksize; + while (remain > 0) + { + size_t tmp = remain > ssize ? ssize : remain; + + hashFunctionContextUpdate(&ctxt, sdata, tmp); + + remain -= tmp; + } + } + + /* next we hash the password data, concatenating until we have a whole number of blocks */ + if (psize) + { + remain = ((psize / h->blocksize) + (psize % h->blocksize)) * h->blocksize; + while (remain > 0) + { + size_t tmp = remain > psize ? psize : remain; + + hashFunctionContextUpdate(&ctxt, pdata, tmp); + + remain -= tmp; + } + } + + /* now we iterate through the following loop */ + while (iterationcount-- > 0) + { + hashFunctionContextDigest(&ctxt, digest); + hashFunctionContextUpdate(&ctxt, digest, h->digestsize); + } + + /* do the final digest */ + hashFunctionContextDigest(&ctxt, digest); + + /* fill key */ + while (nsize > 0) + { + size_t tmp = nsize > h->digestsize ? h->digestsize : nsize; + + memcpy(ndata, digest, tmp); + ndata += tmp; + nsize -= tmp; + } + + if (hashFunctionContextFree(&ctxt)) + goto cleanup; + + rc = 0; + +cleanup: + if (digest) + free(digest); + + return rc; +} diff --git a/beecrypt/pkcs12.h b/beecrypt/pkcs12.h new file mode 100644 index 0000000..60a1587 --- /dev/null +++ b/beecrypt/pkcs12.h @@ -0,0 +1,26 @@ +/*!\file pkcs12.h + * \brief PKCS#12 utility routines + * \ingroup PKCS12_m + */ + +#ifndef _PKCS12_H +#define _PKCS12_H + +#include "beecrypt/beecrypt.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define PKCS12_ID_CIPHER 0x1 +#define PKCS12_ID_IV 0x2 +#define PKCS12_ID_MAC 0x3 + +BEECRYPTAPI +int pkcs12_derive_key(const hashFunction* h, byte id, const byte* pdata, size_t psize, const byte* sdata, size_t ssize, size_t iterationcount, byte* ndata, size_t nsize); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/beecrypt/python/.cvsignore b/beecrypt/python/.cvsignore deleted file mode 100644 index 88b36fb..0000000 --- a/beecrypt/python/.cvsignore +++ /dev/null @@ -1,7 +0,0 @@ -.deps -.libs -Makefile -Makefile.in -*.la -*.lo -*.pyc diff --git a/beecrypt/python/Makefile.am b/beecrypt/python/Makefile.am index 50be843..d4223d5 100644 --- a/beecrypt/python/Makefile.am +++ b/beecrypt/python/Makefile.am @@ -1,39 +1,28 @@ # Makefile for rpm library. -AUTOMAKE_OPTIONS = 1.4 foreign +AUTOMAKE_OPTIONS = 1.4 foreign no-dependencies LINT = splint -PYVER= 2.2 - SUBDIRS = test -pylibdir = $(shell python -c 'import sys; print sys.path[1]') -pyincdir = $(prefix)/include/python${PYVER} - EXTRA_DIST = debug-py.c INCLUDES = -I. \ - -I$(top_srcdir) \ - -I$(pyincdir) + -I$(top_srcdir)/.. @PYTHONINC@ noinst_HEADERS = mpw-py.h rng-py.h -mylibs= $(top_builddir)/.libs/libbeecrypt.so +mylibs = $(top_builddir)/libbeecrypt.la LDADD = -pythondir = $(pylibdir)/site-packages -python_PROGRAMS = _bc.so - -_bc_so_SOURCES = -_bc_so_LDFLAGS = $(mylibs) $(LIBS) -shared -Wl,-soname,_bc.so - -noinst_LTLIBRARIES = libbc.la -libbc_la_SOURCES = _bc-py.c mpw-py.c rng-py.c +pythondir = @PYTHONLIB@ +python_LTLIBRARIES = _bc.la -_bc.so$(EXEEXT): $(libbc_la_OBJECTS) - $(CC) -o $@ $(libbc_la_OBJECTS) $(_bc_so_LDFLAGS) +_bc_la_SOURCES = _bc-py.c mpw-py.c rng-py.c +_bc_la_LDFLAGS = -avoid-version -module +_bc_la_LIBADD = $(mylibs) splint_srcs = _bc-py.c $(libbc_la_sources) diff --git a/beecrypt/python/_bc-py.c b/beecrypt/python/_bc-py.c index 2074d1c..d0aadb7 100644 --- a/beecrypt/python/_bc-py.c +++ b/beecrypt/python/_bc-py.c @@ -3,7 +3,7 @@ */ #define _REENTRANT 1 /* XXX config.h collides with pyconfig.h */ -#include "system.h" +#include "config.h" #include "Python.h" #ifdef __LCLINT__ @@ -11,10 +11,8 @@ #define PyObject_HEAD int _PyObjectHead; #endif -#include "mpw-py.h" -#include "rng-py.h" - -#include "debug.h" +#include "beecrypt/python/mpw-py.h" +#include "beecrypt/python/rng-py.h" #ifdef __LCLINT__ #undef PyObject_HEAD diff --git a/beecrypt/python/debug-py.c b/beecrypt/python/debug-py.c index 06aa932..ce2f8e6 100644 --- a/beecrypt/python/debug-py.c +++ b/beecrypt/python/debug-py.c @@ -6,8 +6,8 @@ extern PyTypeObject PyDictIter_Type; /*@unchecked@*/ extern PyTypeObject PyFrame_Type; -#include "mpw-py.h" /* XXX debug only */ -#include "rng-py.h" /* XXX debug only */ +#include "beecrypt/python/mpw-py.h" /* XXX debug only */ +#include "beecrypt/python/rng-py.h" /* XXX debug only */ /** */ diff --git a/beecrypt/python/mpw-py.c b/beecrypt/python/mpw-py.c index 1f5dee8..ec2443c 100644 --- a/beecrypt/python/mpw-py.c +++ b/beecrypt/python/mpw-py.c @@ -3,7 +3,7 @@ */ #define _REENTRANT 1 /* XXX config.h collides with pyconfig.h */ -#define _GNU_SOURCE 1 /* XXX pick up stpcpy et al */ +#define _GNU_SOURCE /* XXX pick up stpcpy et al */ #include "config.h" #include "Python.h" @@ -14,8 +14,8 @@ #define PyObject_HEAD int _PyObjectHead; #endif -#include "mpw-py.h" -#include "rng-py.h" +#include "beecrypt/python/mpw-py.h" +#include "beecrypt/python/rng-py.h" #include "debug-py.c" @@ -332,7 +332,7 @@ static void prtmpw(const char * msg, mpwObject * x) /*@global stderr, fileSystem @*/ /*@modifies stderr, fileSystem @*/ { -fprintf(stderr, "%5.5s %p[%Zu]:\t", msg, MPW_DATA(x), MPW_SIZE(x)), mpfprintln(stderr, MPW_SIZE(x), MPW_DATA(x)); +fprintf(stderr, "%5.5s %p[%d]:\t", msg, MPW_DATA(x), MPW_SIZE(x)), mpfprintln(stderr, MPW_SIZE(x), MPW_DATA(x)); } static size_t @@ -354,7 +354,7 @@ mpsizeinbase(size_t xsize, mpw* xdata, size_t base) res = (nbits * mp_bases[base].chars_per_bit_exactly) + 1; } if (_mpw_debug < -1) -fprintf(stderr, "*** mpsizeinbase(%p[%Zu], %Zu) res %u\n", xdata, xsize, base, (unsigned)res); +fprintf(stderr, "*** mpsizeinbase(%p[%d], %d) res %u\n", xdata, xsize, base, (unsigned)res); return res; } @@ -408,7 +408,7 @@ mpstr(char * t, size_t nt, size_t size, mpw* data, mpw base) size_t result; if (_mpw_debug < -1) -fprintf(stderr, "*** mpstr(%p[%Zu], %p[%Zu], %u):\t", t, nt, data, size, (unsigned) base), mpfprintln(stderr, size, data); +fprintf(stderr, "*** mpstr(%p[%d], %p[%d], %d):\t", t, nt, data, size, base), mpfprintln(stderr, size, data); mpsetx(asize, adata, size, data); @@ -418,8 +418,8 @@ fprintf(stderr, "*** mpstr(%p[%Zu], %p[%Zu], %u):\t", t, nt, data, size, (unsign mpndivmod(zdata, asize, adata, 1, &base, wksp); if (_mpw_debug < -1) { -fprintf(stderr, " a %p[%Zu]:\t", adata, asize), mpfprintln(stderr, asize, adata); -fprintf(stderr, " z %p[%Zu]:\t", zdata, asize+1), mpfprintln(stderr, asize+1, zdata); +fprintf(stderr, " a %p[%d]:\t", adata, asize), mpfprintln(stderr, asize, adata); +fprintf(stderr, " z %p[%d]:\t", zdata, asize+1), mpfprintln(stderr, asize+1, zdata); } result = zdata[asize]; t[nt] = bchars[result]; @@ -461,7 +461,7 @@ mpw_format(mpwObject * z, size_t base, int addL) } if (_mpw_debug < -1) -fprintf(stderr, "*** mpw_format(%p,%Zu,%d):\t", z, base, addL), mpfprintln(stderr, zsize, zdata); +fprintf(stderr, "*** mpw_format(%p,%d,%d):\t", z, base, addL), mpfprintln(stderr, zsize, zdata); assert(base >= 2 && base <= 36); @@ -812,7 +812,7 @@ static void mpnpow_w(mpnumber* n, size_t xsize, const mpw* xdata, size = MP_ROUND_B2W(15 * xbits); if (_mpw_debug < 0) -fprintf(stderr, "*** pbits %Zu xbits %Zu nsize %Zu size %Zu\n", pbits, xbits, nsize, size); +fprintf(stderr, "*** pbits %d xbits %d nsize %d size %d\n", pbits, xbits, nsize, size); mpnsize(n, nsize); /* 1. Precompute odd powers of x (up to 2**K). */ @@ -1588,7 +1588,7 @@ fprintf(stderr, "sub ++: borrow\n"); } if (_mpw_debug) -fprintf(stderr, "*** mpw_%s %p[%Zu]\t", fname, MPW_DATA(z), MPW_SIZE(z)), mpfprintln(stderr, MPW_SIZE(z), MPW_DATA(z)); +fprintf(stderr, "*** mpw_%s %p[%d]\t", fname, MPW_DATA(z), MPW_SIZE(z)), mpfprintln(stderr, MPW_SIZE(z), MPW_DATA(z)); exit: mpbfree(&b); @@ -1667,7 +1667,7 @@ prtmpw("c", m); z = mpw_FromMPW(zsize, zdata, 1); if (_mpw_debug < 0) -fprintf(stderr, "*** mpw_%s %p[%Zu]\t", fname, MPW_DATA(z), MPW_SIZE(z)), mpfprintln(stderr, MPW_SIZE(z), MPW_DATA(z)); +fprintf(stderr, "*** mpw_%s %p[%d]\t", fname, MPW_DATA(z), MPW_SIZE(z)), mpfprintln(stderr, MPW_SIZE(z), MPW_DATA(z)); exit: mpbfree(&b); @@ -1949,9 +1949,9 @@ mpw_divmod(PyObject * v, PyObject * w) mpndivmod(zdata, asize, adata, bsize, bdata, wksp); if (_mpw_debug < 0) { -fprintf(stderr, " a %p[%Zu]:\t", adata, asize), mpfprintln(stderr, asize, adata); -fprintf(stderr, " b %p[%Zu]:\t", bdata, bsize), mpfprintln(stderr, bsize, bdata); -fprintf(stderr, " z %p[%Zu]:\t", zdata, zsize), mpfprintln(stderr, zsize, zdata); +fprintf(stderr, " a %p[%d]:\t", adata, asize), mpfprintln(stderr, asize, adata); +fprintf(stderr, " b %p[%d]:\t", bdata, bsize), mpfprintln(stderr, bsize, bdata); +fprintf(stderr, " z %p[%d]:\t", zdata, zsize), mpfprintln(stderr, zsize, zdata); } zsize -= bsize; @@ -2026,7 +2026,7 @@ mpw_neg(mpwObject * a) } if (z != NULL && _mpw_debug) -fprintf(stderr, "*** mpw_neg %p[%Zu]\t", MPW_DATA(z), MPW_SIZE(z)), mpfprintln(stderr, MPW_SIZE(z), MPW_DATA(z)); +fprintf(stderr, "*** mpw_neg %p[%d]\t", MPW_DATA(z), MPW_SIZE(z)), mpfprintln(stderr, MPW_SIZE(z), MPW_DATA(z)); return (PyObject *)z; } @@ -2044,7 +2044,7 @@ mpw_pos(mpwObject * a) z = mpw_Copy(a); if (z != NULL && _mpw_debug) -fprintf(stderr, "*** mpw_pos %p[%Zu]\t", MPW_DATA(z), MPW_SIZE(z)), mpfprintln(stderr, MPW_SIZE(z), MPW_DATA(z)); +fprintf(stderr, "*** mpw_pos %p[%d]\t", MPW_DATA(z), MPW_SIZE(z)), mpfprintln(stderr, MPW_SIZE(z), MPW_DATA(z)); return (PyObject *)z; } @@ -2061,7 +2061,7 @@ mpw_abs(mpwObject * a) z = (mpwObject *)mpw_pos(a); if (z != NULL && _mpw_debug) -fprintf(stderr, "*** mpw_abs %p[%Zu]\t", MPW_DATA(z), MPW_SIZE(z)), mpfprintln(stderr, MPW_SIZE(z), MPW_DATA(z)); +fprintf(stderr, "*** mpw_abs %p[%d]\t", MPW_DATA(z), MPW_SIZE(z)), mpfprintln(stderr, MPW_SIZE(z), MPW_DATA(z)); return (PyObject *)z; } diff --git a/beecrypt/python/mpw-py.h b/beecrypt/python/mpw-py.h index 2ef9707..e340533 100644 --- a/beecrypt/python/mpw-py.h +++ b/beecrypt/python/mpw-py.h @@ -4,7 +4,7 @@ /** \ingroup py_c * \file python/mpw-py.h */ -#include "mp.h" +#include "beecrypt/mp.h" /** */ diff --git a/beecrypt/python/rng-py.c b/beecrypt/python/rng-py.c index 1a9173d..6252ede 100644 --- a/beecrypt/python/rng-py.c +++ b/beecrypt/python/rng-py.c @@ -11,7 +11,7 @@ #define PyObject_HEAD int _PyObjectHead; #endif -#include "rng-py.h" +#include "beecrypt/python/rng-py.h" #include "debug-py.c" diff --git a/beecrypt/python/rng-py.h b/beecrypt/python/rng-py.h index 70a99c5..32162c0 100644 --- a/beecrypt/python/rng-py.h +++ b/beecrypt/python/rng-py.h @@ -4,8 +4,8 @@ /** \ingroup py_c * \file python/rng-py.h */ -#include "beecrypt.h" -#include "mpprime.h" +#include "beecrypt/beecrypt.h" +#include "beecrypt/mpprime.h" /** */ diff --git a/beecrypt/python/test/.cvsignore b/beecrypt/python/test/.cvsignore deleted file mode 100644 index 12664c7..0000000 --- a/beecrypt/python/test/.cvsignore +++ /dev/null @@ -1,3 +0,0 @@ -Makefile -Makefile.in -*.pyc diff --git a/beecrypt/python/test/Makefile.am b/beecrypt/python/test/Makefile.am index 7710090..1d00d24 100644 --- a/beecrypt/python/test/Makefile.am +++ b/beecrypt/python/test/Makefile.am @@ -2,9 +2,6 @@ AUTOMAKE_OPTIONS = 1.4 foreign -PYVER= 2.2 - -pylibdir = $(shell python -c 'import sys; print sys.path[1]') VALGRIND = # valgrind --verbose --leak-check=yes EXTRA_DIST = \ @@ -14,4 +11,4 @@ EXTRA_DIST = \ all: check: - env PYTHONPATH=.. $(VALGRIND) python test_all.py verbose + $(VALGRIND) PYTHONPATH=.. python test_all.py verbose diff --git a/beecrypt/python/test/test_methods.py b/beecrypt/python/test/test_methods.py index 44ba482..71faa61 100644 --- a/beecrypt/python/test/test_methods.py +++ b/beecrypt/python/test/test_methods.py @@ -90,12 +90,10 @@ class BasicTestCase(unittest.TestCase): zs = hex(za) print "__hex__:\t", hex(wa), "\t", zs -# XXX x86_64 appends L to zs -# assert hex(wa) == zs +# assert hex(wa) == zs # fails because of missing trailing L zs = oct(za) print "__oct__:\t", oct(wa), "\t", zs -# XXX x86_64 appends L to zs -# assert oct(wa) == zs +# assert oct(wa) == zs # fails because of missing trailing L print "__neg__:\t", (-wa), "\t", long(-za) print "__pos__:\t", (+wa), "\t", long(+za) diff --git a/beecrypt/rsa.c b/beecrypt/rsa.c index 23827b7..9674be1 100644 --- a/beecrypt/rsa.c +++ b/beecrypt/rsa.c @@ -23,26 +23,31 @@ * \ingroup IF_m IF_rsa_m */ -#include "system.h" -#include "rsa.h" -#include "mp.h" -#include "debug.h" +#define BEECRYPT_DLL_EXPORT -int rsapub(const rsapk* pk, const mpnumber* m, mpnumber* c) +#if HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/rsa.h" + +int rsapub(const mpbarrett* n, const mpnumber* e, + const mpnumber* m, mpnumber* c) { - register size_t size = pk->n.size; + register size_t size = n->size; register mpw* temp; - if (mpgex(m->size, m->data, pk->n.size, pk->n.modl)) + if (mpgex(m->size, m->data, n->size, n->modl)) return -1; - temp = (mpw*) malloc((4*size+2)*sizeof(*temp)); + temp = (mpw*) malloc((4*size+2)*sizeof(mpw)); if (temp) { mpnsize(c, size); - mpbpowmod_w(&pk->n, m->size, m->data, pk->e.size, pk->e.data, c->data, temp); + mpbpowmod_w(n, m->size, m->data, e->size, e->data, c->data, temp); + free(temp); return 0; @@ -50,20 +55,21 @@ int rsapub(const rsapk* pk, const mpnumber* m, mpnumber* c) return -1; } -int rsapri(const rsakp* kp, const mpnumber* c, mpnumber* m) +int rsapri(const mpbarrett* n, const mpnumber* d, + const mpnumber* c, mpnumber* m) { - register size_t size = kp->n.size; + register size_t size = n->size; register mpw* temp; - if (mpgex(c->size, c->data, kp->n.size, kp->n.modl)) + if (mpgex(c->size, c->data, n->size, n->modl)) return -1; - temp = (mpw*) malloc((4*size+2) * sizeof(*temp)); + temp = (mpw*) malloc((4*size+2)*sizeof(mpw)); if (temp) { mpnsize(m, size); - mpbpowmod_w(&kp->n, c->size, c->data, kp->d.size, kp->d.data, m->data, temp); + mpbpowmod_w(n, c->size, c->data, d->size, d->data, m->data, temp); free(temp); @@ -72,23 +78,25 @@ int rsapri(const rsakp* kp, const mpnumber* c, mpnumber* m) return -1; } -int rsapricrt(const rsakp* kp, const mpnumber* c, mpnumber* m) +int rsapricrt(const mpbarrett* n, const mpbarrett* p, const mpbarrett* q, + const mpnumber* dp, const mpnumber* dq, const mpnumber* qi, + const mpnumber* c, mpnumber* m) { - register size_t nsize = kp->n.size; - register size_t psize = kp->p.size; - register size_t qsize = kp->q.size; + register size_t nsize = n->size; + register size_t psize = p->size; + register size_t qsize = q->size; register mpw* ptemp; register mpw* qtemp; - if (mpgex(c->size, c->data, kp->n.size, kp->n.modl)) + if (mpgex(c->size, c->data, n->size, n->modl)) return -1; - ptemp = (mpw*) malloc((6*psize+2)*sizeof(*ptemp)); + ptemp = (mpw*) malloc((6*psize+2)*sizeof(mpw)); if (ptemp == (mpw*) 0) return -1; - qtemp = (mpw*) malloc((6*qsize+2)*sizeof(*qtemp)); + qtemp = (mpw*) malloc((6*qsize+2)*sizeof(mpw)); if (qtemp == (mpw*) 0) { free(ptemp); @@ -99,32 +107,32 @@ int rsapricrt(const rsakp* kp, const mpnumber* c, mpnumber* m) mpsetx(psize*2, ptemp, c->size, c->data); /* reduce modulo p before we powmod */ - mpbmod_w(&kp->p, ptemp, ptemp+psize, ptemp+2*psize); + mpbmod_w(p, ptemp, ptemp+psize, ptemp+2*psize); - /* compute j1 = c^d1 mod p, store @ ptemp */ - mpbpowmod_w(&kp->p, psize, ptemp+psize, kp->d1.size, kp->d1.data, ptemp, ptemp+2*psize); + /* compute j1 = c^dp mod p, store @ ptemp */ + mpbpowmod_w(p, psize, ptemp+psize, dp->size, dp->data, ptemp, ptemp+2*psize); /* resize c for powmod q */ mpsetx(qsize*2, qtemp, c->size, c->data); /* reduce modulo q before we powmod */ - mpbmod_w(&kp->q, qtemp, qtemp+qsize, qtemp+2*qsize); + mpbmod_w(q, qtemp, qtemp+qsize, qtemp+2*qsize); - /* compute j2 = c^d2 mod q, store @ qtemp */ - mpbpowmod_w(&kp->q, qsize, qtemp+qsize, kp->d2.size, kp->d2.data, qtemp, qtemp+2*qsize); + /* compute j2 = c^dq mod q, store @ qtemp */ + mpbpowmod_w(q, qsize, qtemp+qsize, dq->size, dq->data, qtemp, qtemp+2*qsize); /* compute j1-j2 mod p, store @ ptemp */ - mpbsubmod_w(&kp->p, psize, ptemp, qsize, qtemp, ptemp, ptemp+2*psize); + mpbsubmod_w(p, psize, ptemp, qsize, qtemp, ptemp, ptemp+2*psize); /* compute h = c*(j1-j2) mod p, store @ ptemp */ - mpbmulmod_w(&kp->p, psize, ptemp, psize, kp->c.data, ptemp, ptemp+2*psize); + mpbmulmod_w(p, psize, ptemp, psize, qi->data, ptemp, ptemp+2*psize); /* make sure the message gets the proper size */ mpnsize(m, nsize); /* compute m = h*q + j2 */ - mpmul(m->data, psize, ptemp, qsize, kp->q.modl); - (void) mpaddx(nsize, m->data, qsize, qtemp); + mpmul(m->data, psize, ptemp, qsize, q->modl); + mpaddx(nsize, m->data, qsize, qtemp); free(ptemp); free(qtemp); @@ -132,29 +140,32 @@ int rsapricrt(const rsakp* kp, const mpnumber* c, mpnumber* m) return 0; } -int rsavrfy(const rsapk* pk, const mpnumber* m, const mpnumber* c) +int rsavrfy(const mpbarrett* n, const mpnumber* e, + const mpnumber* m, const mpnumber* c) { int rc; - register size_t size = pk->n.size; + register size_t size = n->size; + register mpw* temp; - if (mpgex(m->size, m->data, pk->n.size, pk->n.modl)) + if (mpgex(m->size, m->data, n->size, n->modl)) return -1; - if (mpgex(c->size, c->data, pk->n.size, pk->n.modl)) + if (mpgex(c->size, c->data, n->size, n->modl)) return 0; - temp = (mpw*) malloc((5*size+2) * sizeof(*temp)); + temp = (mpw*) malloc((5*size+2)*sizeof(mpw)); if (temp) { - mpbpowmod_w(&pk->n, c->size, c->data, pk->e.size, pk->e.data, temp, temp+size); + mpbpowmod_w(n, m->size, m->data, e->size, e->data, temp, temp+size); - rc = mpeqx(size, temp, m->size, m->data); + rc = mpeqx(size, temp, c->size, c->data); free(temp); return rc; } + return 0; } diff --git a/beecrypt/rsa.h b/beecrypt/rsa.h index 1bdb20a..dbb0e45 100644 --- a/beecrypt/rsa.h +++ b/beecrypt/rsa.h @@ -26,76 +26,93 @@ #ifndef _RSA_H #define _RSA_H -#include "rsakp.h" +#include "beecrypt/rsakp.h" #ifdef __cplusplus extern "C" { #endif -/** - * The raw RSA public key operation. +/*!\fn int rsapub(const mpbarrett* n, const mpnumber* e, const mpnumber* m, mpnumber* c) + * \brief This function performs a raw RSA public key operation. * * This function can be used for encryption and verifying. * * It performs the following operation: * \li \f$c=m^{e}\ \textrm{mod}\ n\f$ * - * @param pk RSA public key - * @param m message - * @param c ciphertext - * @retval 0 on success, -1 on failure - */ -BEECRYPTAPI /*@unused@*/ - int rsapub(const rsapk* pk, const mpnumber* m, mpnumber* c) - /*@modifies c @*/; + * \param n The RSA modulus. + * \param e The RSA public exponent. + * \param m The message. + * \param c The ciphertext. + * \retval 0 on success. + * \retval -1 on failure. + */ +BEECRYPTAPI +int rsapub(const mpbarrett* n, const mpnumber* e, + const mpnumber* m, mpnumber* c); -/** - * The raw RSA private key operation. +/*!\fn int rsapri(const mpbarrett* n, const mpnumber* d, const mpnumber* c, mpnumber* m) + * \brief This function performs a raw RSA private key operation. * * This function can be used for decryption and signing. * * It performs the operation: * \li \f$m=c^{d}\ \textrm{mod}\ n\f$ * - * @param kp RSA keypair - * @param c ciphertext - * @param m message - * @retval 0 on success, -1 on failure + * \param n The RSA modulus. + * \param d The RSA private exponent. + * \param c The ciphertext. + * \param m The message. + * \retval 0 on success. + * \retval -1 on failure. */ -BEECRYPTAPI /*@unused@*/ -int rsapri (const rsakp* kp, const mpnumber* c, mpnumber* m) - /*@modifies m @*/; +BEECRYPTAPI +int rsapri(const mpbarrett* n, const mpnumber* d, + const mpnumber* c, mpnumber* m); -/** - * The raw RSA private key operation, with Chinese Remainder Theorem. +/*!\fn int rsapricrt(const mpbarrett* n, const mpbarrett* p, const mpbarrett* q, const mpnumber* dp, const mpnumber* dq, const mpnumber* qi, const mpnumber* c, mpnumber* m) + * + * \brief This function performs a raw RSA private key operation, with + * application of the Chinese Remainder Theorem. * * It performs the operation: - * \li \f$j_1=c^{d_1}\ \textrm{mod}\ p\f$ - * \li \f$j_2=c^{d_2}\ \textrm{mod}\ q\f$ - * \li \f$h=c \cdot (j_1-j_2)\ \textrm{mod}\ p\f$ + * \li \f$j_1=c^{dp}\ \textrm{mod}\ p\f$ + * \li \f$j_2=c^{dq}\ \textrm{mod}\ q\f$ + * \li \f$h=qi \cdot (j_1-j_2)\ \textrm{mod}\ p\f$ * \li \f$m=j_2+hq\f$ * - * @param kp RSA keypair - * @param c ciphertext - * @param m message - * @retval 0 on success, -1 on failure. + * \param n The RSA modulus. + * \param p The first RSA prime factor. + * \param q The second RSA prime factor. + * \param dp + * \param dq + * \param qi + * \param c The ciphertext. + * \param m The message. + * \retval 0 on success. + * \retval -1 on failure. */ BEECRYPTAPI -int rsapricrt(const rsakp* kp, const mpnumber* c, mpnumber* m) - /*@modifies m @*/; +int rsapricrt(const mpbarrett* n, const mpbarrett* p, const mpbarrett* q, + const mpnumber* dp, const mpnumber* dq, const mpnumber* qi, + const mpnumber* c, mpnumber* m); -/** - * Verify if ciphertext \e c was encrypted from cleartext \e m - * with the private key matching the given public key \e pk. +/*!\fn int rsavrfy(const mpbarrett* n, const mpnumber* e, const mpnumber* m, const mpnumber* c) + * \brief This function performs a raw RSA verification. + * + * It verifies if ciphertext \a c was encrypted from cleartext \a m + * with the private key matching the given public key \a (n, e). * - * @param pk RSA public key - * @param m cleartext message - * @param c ciphertext message - * @retval 1 on success, 0 on failure + * \param n The RSA modulus. + * \param e The RSA public exponent. + * \param m The cleartext message. + * \param c The ciphertext message. + * \retval 1 on success. + * \retval 0 on failure. */ BEECRYPTAPI -int rsavrfy (const rsapk* pk, const mpnumber* m, const mpnumber* c) - /*@*/; +int rsavrfy(const mpbarrett* n, const mpnumber* e, + const mpnumber* m, const mpnumber* c); #ifdef __cplusplus } diff --git a/beecrypt/rsakp.c b/beecrypt/rsakp.c index 6da864f..a00fac3 100644 --- a/beecrypt/rsakp.c +++ b/beecrypt/rsakp.c @@ -23,119 +23,112 @@ * \ingroup IF_m IF_rsa_m */ -#include "system.h" -#include "rsakp.h" -#include "mpprime.h" -#include "mp.h" -#include "debug.h" +#define BEECRYPT_DLL_EXPORT + +#if HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/rsakp.h" +#include "beecrypt/mpprime.h" /*!\addtogroup IF_rsa_m * \{ */ -int rsakpMake(rsakp* kp, randomGeneratorContext* rgc, size_t nsize) +int rsakpMake(rsakp* kp, randomGeneratorContext* rgc, size_t bits) { /* * Generates an RSA Keypair for use with the Chinese Remainder Theorem */ - register size_t pqsize = (nsize + 1U) >> 1; - register mpw* temp = (mpw*) malloc((16*pqsize+6) * sizeof(*temp)); - register int newn = 1; + size_t pbits = (bits+1) >> 1; + size_t qbits = (bits - pbits); + size_t nsize = MP_BITS_TO_WORDS(bits+MP_WBITS-1); + size_t psize = MP_BITS_TO_WORDS(pbits+MP_WBITS-1); + size_t qsize = MP_BITS_TO_WORDS(qbits+MP_WBITS-1); + size_t pqsize = psize+qsize; + mpw* temp = (mpw*) malloc((16*pqsize+6)*sizeof(mpw)); if (temp) { - mpbarrett r, psubone, qsubone; - mpnumber phi; - - nsize = pqsize << 1; - - /* set e */ - mpnsetw(&kp->e, 65535); - - /* generate a random prime p and q */ - mpprnd_w(&kp->p, rgc, pqsize, mpptrials(MP_WORDS_TO_BITS(pqsize)), &kp->e, temp); - mpprnd_w(&kp->q, rgc, pqsize, mpptrials(MP_WORDS_TO_BITS(pqsize)), &kp->e, temp); - - /* if p <= q, perform a swap to make p larger than q */ - if (mple(pqsize, kp->p.modl, kp->q.modl)) + mpbarrett psubone, qsubone; + mpnumber phi, min; + mpw* divmod = temp; + mpw* dividend = divmod+nsize+1; + mpw* workspace = dividend+nsize+1; + int shift; + + /* set e to default value if e is empty */ + if (kp->e.size == 0 && !kp->e.data) + mpnsetw(&kp->e, 65537U); + + /* generate a random prime p, so that gcd(p-1,e) = 1 */ + mpprnd_w(&kp->p, rgc, pbits, mpptrials(pbits), &kp->e, temp); + + /* find out how big q should be */ + shift = MP_WORDS_TO_BITS(nsize) - bits; + mpzero(nsize, dividend); + dividend[0] |= MP_MSBMASK; + dividend[nsize-1] |= MP_LSBMASK; + mpndivmod(divmod, nsize+1, dividend, psize, kp->p.modl, workspace); + mprshift(nsize+1, divmod, shift); + + mpnzero(&min); + mpnset(&min, nsize+1-psize, divmod); + + /* generate a random prime q, with min/max constraints, so that gcd(q-1,e) = 1 */ + if (mpprndr_w(&kp->q, rgc, qbits, mpptrials(qbits), &min, (mpnumber*) 0, &kp->e, temp)) { - memcpy(&r, &kp->q, sizeof(r)); - memcpy(&kp->q, &kp->p, sizeof(kp->q)); - memcpy(&kp->p, &r, sizeof(kp->p)); + /* shouldn't happen */ + mpnfree(&min); + free(temp); + return -1; } - mpbzero(&r); + mpnfree(&min); + mpbzero(&psubone); mpbzero(&qsubone); mpnzero(&phi); - while (1) - { - mpmul(temp, pqsize, kp->p.modl, pqsize, kp->q.modl); - - if (newn && mpmsbset(nsize, temp)) - break; - - /* product of p and q doesn't have the required size (one bit short) */ - - mpprnd_w(&r, rgc, pqsize, mpptrials(MP_WORDS_TO_BITS(pqsize)), &kp->e, temp); - - /*@-usedef -branchstate @*/ /* r is set */ - if (mple(pqsize, kp->p.modl, r.modl)) - { - mpbfree(&kp->q); - memcpy(&kp->q, &kp->p, sizeof(kp->q)); - memcpy(&kp->p, &r, sizeof(kp->p)); - mpbzero(&r); - newn = 1; - } - else if (mple(pqsize, kp->q.modl, r.modl)) - { - mpbfree(&kp->q); - memcpy(&kp->q, &r, sizeof(kp->q)); - mpbzero(&r); - newn = 1; - } - else - { - mpbfree(&r); - newn = 0; - } - /*@=usedef =branchstate @*/ - } - - mpbset(&kp->n, nsize, temp); + /* set n = p*q, with appropriate size (pqsize may be > nsize) */ + mpmul(temp, psize, kp->p.modl, qsize, kp->q.modl); + mpbset(&kp->n, nsize, temp+pqsize-nsize); /* compute p-1 */ mpbsubone(&kp->p, temp); - mpbset(&psubone, pqsize, temp); + mpbset(&psubone, psize, temp); /* compute q-1 */ mpbsubone(&kp->q, temp); - mpbset(&qsubone, pqsize, temp); + mpbset(&qsubone, qsize, temp); - /*@-usedef@*/ /* psubone/qsubone are set */ /* compute phi = (p-1)*(q-1) */ - mpmul(temp, pqsize, psubone.modl, pqsize, qsubone.modl); + mpmul(temp, psize, psubone.modl, qsize, qsubone.modl); mpnset(&phi, nsize, temp); - /* compute d = inv(e) mod phi */ - (void) mpninv(&kp->d, &kp->e, &phi); + /* compute d = inv(e) mod phi; if gcd(e, phi) != 1 then this function will fail + */ + if (mpninv(&kp->d, &kp->e, &phi) == 0) + { + /* shouldn't happen, since gcd(p-1,e) = 1 and gcd(q-1,e) = 1 ==> gcd((p-1)(q-1),e) = 1 */ + free(temp); + return -1; + } - /* compute d1 = d mod (p-1) */ - mpnsize(&kp->d1, pqsize); - mpbmod_w(&psubone, kp->d.data, kp->d1.data, temp); + /* compute dp = d mod (p-1) */ + mpnsize(&kp->dp, psize); + mpbmod_w(&psubone, kp->d.data, kp->dp.data, temp); - /* compute d2 = d mod (q-1) */ - mpnsize(&kp->d2, pqsize); - mpbmod_w(&qsubone, kp->d.data, kp->d2.data, temp); + /* compute dq = d mod (q-1) */ + mpnsize(&kp->dq, qsize); + mpbmod_w(&qsubone, kp->d.data, kp->dq.data, temp); - /* compute c = inv(q) mod p */ - (void) mpninv(&kp->c, (const mpnumber*) &kp->q, (const mpnumber*) &kp->p); + /* compute qi = inv(q) mod p */ + mpninv(&kp->qi, (mpnumber*) &kp->q, (mpnumber*) &kp->p); free(temp); - /*@=usedef@*/ return 0; } @@ -144,16 +137,16 @@ int rsakpMake(rsakp* kp, randomGeneratorContext* rgc, size_t nsize) int rsakpInit(rsakp* kp) { - memset(kp, 0, sizeof(*kp)); + memset(kp, 0, sizeof(rsakp)); /* or mpbzero(&kp->n); mpnzero(&kp->e); mpnzero(&kp->d); mpbzero(&kp->p); mpbzero(&kp->q); - mpnzero(&kp->d1); - mpnzero(&kp->d2); - mpnzero(&kp->c); + mpnzero(&kp->dp); + mpnzero(&kp->dq); + mpnzero(&kp->qi); */ return 0; @@ -161,18 +154,23 @@ int rsakpInit(rsakp* kp) int rsakpFree(rsakp* kp) { - /*@-usereleased -compdef @*/ /* kp->param.{n,p,q}.modl is OK */ + /* wipe all secret key components */ mpbfree(&kp->n); mpnfree(&kp->e); + mpnwipe(&kp->d); mpnfree(&kp->d); + mpbwipe(&kp->p); mpbfree(&kp->p); + mpbwipe(&kp->q); mpbfree(&kp->q); - mpnfree(&kp->d1); - mpnfree(&kp->d2); - mpnfree(&kp->c); + mpnwipe(&kp->dp); + mpnfree(&kp->dp); + mpnwipe(&kp->dq); + mpnfree(&kp->dq); + mpnwipe(&kp->qi); + mpnfree(&kp->qi); return 0; - /*@=usereleased =compdef @*/ } int rsakpCopy(rsakp* dst, const rsakp* src) @@ -182,9 +180,9 @@ int rsakpCopy(rsakp* dst, const rsakp* src) mpncopy(&dst->d, &src->d); mpbcopy(&dst->p, &src->p); mpbcopy(&dst->q, &src->q); - mpncopy(&dst->d1, &src->d1); - mpncopy(&dst->d2, &src->d2); - mpncopy(&dst->c, &src->c); + mpncopy(&dst->dp, &src->dp); + mpncopy(&dst->dp, &src->dp); + mpncopy(&dst->qi, &src->qi); return 0; } diff --git a/beecrypt/rsakp.h b/beecrypt/rsakp.h index 9e96100..b8bab5f 100644 --- a/beecrypt/rsakp.h +++ b/beecrypt/rsakp.h @@ -26,50 +26,77 @@ #ifndef _RSAKP_H #define _RSAKP_H -#include "rsapk.h" +#include "beecrypt/rsapk.h" /*!\brief RSA keypair. * \ingroup IF_rsa_m */ -typedef struct +#ifdef __cplusplus +struct BEECRYPTAPI rsakp +#else +struct _rsakp +#endif { + /*!\var n + * \brief The modulus. + * + * \f$n=pq\f$ + */ mpbarrett n; + /*!\var e + * \brief The public exponent. + */ mpnumber e; + /*!\var d + * \brief The private exponent. + */ mpnumber d; + /*!\var p + * \brief The first prime factor of the modulus. + */ mpbarrett p; + /*!\var q + * \brief The second prime factor of the modulus. + */ mpbarrett q; - mpnumber d1; - mpnumber d2; - mpnumber c; -} rsakp; + /*!\var dp + * \brief the first prime coefficient. + * \f$dp=d\ \textrm{mod}\ (p-1)\f$ + */ + mpnumber dp; + /*!\var dq + * \brief the second prime coefficient. + * \f$dq=d\ \textrm{mod}\ (q-1)\f$ + */ + mpnumber dq; + /*!\var qi + * \brief the crt coefficient. + * \f$qi=q^{-1}\ \textrm{mod}\ p\f$ + */ + mpnumber qi; + #ifdef __cplusplus + rsakp(); + rsakp(const rsakp&); + ~rsakp(); + #endif +}; + +#ifndef __cplusplus +typedef struct _rsakp rsakp; +#endif #ifdef __cplusplus extern "C" { #endif -/** - */ -BEECRYPTAPI /*@unused@*/ -int rsakpMake(rsakp* kp, randomGeneratorContext* rgc, size_t nsize) - /*@modifies kp, rgc @*/; - -/** - */ -BEECRYPTAPI /*@unused@*/ -int rsakpInit(rsakp* kp) - /*@modifies kp @*/; - -/** - */ -BEECRYPTAPI /*@unused@*/ -int rsakpFree(rsakp* kp) - /*@modifies kp @*/; - -/** - */ -BEECRYPTAPI /*@unused@*/ -int rsakpCopy(rsakp* dst, const rsakp* src) - /*@modifies dst @*/; +BEECRYPTAPI +int rsakpMake(rsakp*, randomGeneratorContext*, size_t); +BEECRYPTAPI +int rsakpInit(rsakp*); +BEECRYPTAPI +int rsakpFree(rsakp*); +BEECRYPTAPI +int rsakpCopy(rsakp*, const rsakp*); #ifdef __cplusplus } diff --git a/beecrypt/rsapk.c b/beecrypt/rsapk.c index d84738c..570db18 100644 --- a/beecrypt/rsapk.c +++ b/beecrypt/rsapk.c @@ -23,9 +23,13 @@ * \ingroup IF_m IF_rsa_m */ -#include "system.h" -#include "rsapk.h" -#include "debug.h" +#define BEECRYPT_DLL_EXPORT + +#if HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/rsapk.h" /*!\addtogroup IF_rsa_m * \{ @@ -33,7 +37,7 @@ int rsapkInit(rsapk* pk) { - memset(pk, 0, sizeof(*pk)); + memset(pk, 0, sizeof(rsapk)); /* or mpbzero(&pk->n); mpnzero(&pk->e); @@ -44,12 +48,10 @@ int rsapkInit(rsapk* pk) int rsapkFree(rsapk* pk) { - /*@-usereleased -compdef @*/ /* pk->n.modl is OK */ mpbfree(&pk->n); mpnfree(&pk->e); return 0; - /*@=usereleased =compdef @*/ } int rsapkCopy(rsapk* dst, const rsapk* src) diff --git a/beecrypt/rsapk.h b/beecrypt/rsapk.h index 5a3ac03..96b746d 100644 --- a/beecrypt/rsapk.h +++ b/beecrypt/rsapk.h @@ -26,37 +26,37 @@ #ifndef _RSAPK_H #define _RSAPK_H -#include "mpbarrett.h" +#include "beecrypt/mpbarrett.h" -/** - */ -typedef struct +#ifdef __cplusplus +struct BEECRYPTAPI rsapk +#else +struct _rsapk +#endif { mpbarrett n; mpnumber e; -} rsapk; + #ifdef __cplusplus + rsapk(); + rsapk(const rsapk&); + ~rsapk(); + #endif +}; + +#ifndef __cplusplus +typedef struct _rsapk rsapk; +#endif #ifdef __cplusplus extern "C" { #endif -/** - */ -BEECRYPTAPI /*@unused@*/ -int rsapkInit(rsapk* pk) - /*@modifies pk @*/; - -/** - */ -BEECRYPTAPI /*@unused@*/ -int rsapkFree(rsapk* pk) - /*@modifies pk @*/; - -/** - */ -BEECRYPTAPI /*@unused@*/ -int rsapkCopy(rsapk* dst, const rsapk* src) - /*@modifies dst @*/; +BEECRYPTAPI +int rsapkInit(rsapk*); +BEECRYPTAPI +int rsapkFree(rsapk*); +BEECRYPTAPI +int rsapkCopy(rsapk*, const rsapk*); #ifdef __cplusplus } diff --git a/beecrypt/sha1.c b/beecrypt/sha1.c index 49c7108..a0265fd 100644 --- a/beecrypt/sha1.c +++ b/beecrypt/sha1.c @@ -22,53 +22,46 @@ * \author Bob Deblier * \ingroup HASH_m HASH_sha1_m */ + +#define BEECRYPT_DLL_EXPORT -#include "system.h" -#include "beecrypt.h" -#include "sha1opt.h" -#include "sha1.h" -#include "mp.h" -#include "endianness.h" -#include "debug.h" +#if HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/sha1.h" +#include "beecrypt/endianness.h" /*!\addtogroup HASH_sha1_m * \{ */ -/** \ingroup HASH_sha1_m - */ -/*@observer@*/ /*@unchecked@*/ static const uint32_t k[4] = { 0x5a827999U, 0x6ed9eba1U, 0x8f1bbcdcU, 0xca62c1d6U }; -/** \ingroup HASH_sha1_m - */ -/*@observer@*/ /*@unchecked@*/ static const uint32_t hinit[5] = { 0x67452301U, 0xefcdab89U, 0x98badcfeU, 0x10325476U, 0xc3d2e1f0U }; -/*@-sizeoftype@*/ const hashFunction sha1 = { "SHA-1", sizeof(sha1Param), - 64U, - 5U * sizeof(uint32_t), + 64, + 20, (hashFunctionReset) sha1Reset, (hashFunctionUpdate) sha1Update, (hashFunctionDigest) sha1Digest }; -/*@=sizeoftype@*/ -int sha1Reset(sha1Param* sp) +int sha1Reset(register sha1Param* p) { - memcpy(sp->h, hinit, sizeof(sp->h)); - memset(sp->data, 0, sizeof(sp->data)); + memcpy(p->h, hinit, 5 * sizeof(uint32_t)); + memset(p->data, 0, 80 * sizeof(uint32_t)); #if (MP_WBITS == 64) - mpzero(1, sp->length); + mpzero(1, p->length); #elif (MP_WBITS == 32) - mpzero(2, sp->length); + mpzero(2, p->length); #else # error #endif - sp->offset = 0; + p->offset = 0; return 0; } @@ -215,45 +208,39 @@ int sha1Update(sha1Param* sp, const byte* data, size_t size) mpw add[1]; mpsetw(1, add, size); mplshift(1, add, 3); - (void) mpadd(1, sp->length, add); + mpadd(1, sp->length, add); #elif (MP_WBITS == 32) mpw add[2]; mpsetw(2, add, size); mplshift(2, add, 3); - (void) mpadd(2, sp->length, add); + mpadd(2, sp->length, add); #else # error #endif -/*@-type@*/ while (size > 0) { proclength = ((sp->offset + size) > 64U) ? (64U - sp->offset) : size; - memmove(((byte *) sp->data) + sp->offset, data, proclength); + memcpy(((byte *) sp->data) + sp->offset, data, proclength); size -= proclength; data += proclength; sp->offset += proclength; - if (sp->offset == 64U) + if (sp->offset == 64) { sha1Process(sp); sp->offset = 0; } } -/*@=type@*/ return 0; } -/** \ingroup HASH_sha1_m - */ static void sha1Finish(sha1Param* sp) - /*@modifies sp @*/ { register byte *ptr = ((byte *) sp->data) + sp->offset++; *(ptr++) = 0x80; -/*@-type@*/ if (sp->offset > 56) { while (sp->offset++ < 64) @@ -266,10 +253,9 @@ static void sha1Finish(sha1Param* sp) ptr = ((byte*) sp->data) + sp->offset; while (sp->offset++ < 56) *(ptr++) = 0; -/*@=type@*/ #if WORDS_BIGENDIAN - memcpy(ptr, sp->length, sizeof(sp->length)); + memcpy(ptr, sp->length, 8); #else # if (MP_WBITS == 64) ptr[0] = (byte)(sp->length[0] >> 56); @@ -299,37 +285,37 @@ static void sha1Finish(sha1Param* sp) sp->offset = 0; } -int sha1Digest(sha1Param* sp, byte* digest) +int sha1Digest(sha1Param* sp, byte* data) { sha1Finish(sp); #if WORDS_BIGENDIAN - memcpy(digest, sp->h, sizeof(sp->h)); + memcpy(data, sp->h, 20); #else /* encode 5 integers big-endian style */ - digest[ 0] = (byte)(sp->h[0] >> 24); - digest[ 1] = (byte)(sp->h[0] >> 16); - digest[ 2] = (byte)(sp->h[0] >> 8); - digest[ 3] = (byte)(sp->h[0] >> 0); - digest[ 4] = (byte)(sp->h[1] >> 24); - digest[ 5] = (byte)(sp->h[1] >> 16); - digest[ 6] = (byte)(sp->h[1] >> 8); - digest[ 7] = (byte)(sp->h[1] >> 0); - digest[ 8] = (byte)(sp->h[2] >> 24); - digest[ 9] = (byte)(sp->h[2] >> 16); - digest[10] = (byte)(sp->h[2] >> 8); - digest[11] = (byte)(sp->h[2] >> 0); - digest[12] = (byte)(sp->h[3] >> 24); - digest[13] = (byte)(sp->h[3] >> 16); - digest[14] = (byte)(sp->h[3] >> 8); - digest[15] = (byte)(sp->h[3] >> 0); - digest[16] = (byte)(sp->h[4] >> 24); - digest[17] = (byte)(sp->h[4] >> 16); - digest[18] = (byte)(sp->h[4] >> 8); - digest[19] = (byte)(sp->h[4] >> 0); + data[ 0] = (byte)(sp->h[0] >> 24); + data[ 1] = (byte)(sp->h[0] >> 16); + data[ 2] = (byte)(sp->h[0] >> 8); + data[ 3] = (byte)(sp->h[0] >> 0); + data[ 4] = (byte)(sp->h[1] >> 24); + data[ 5] = (byte)(sp->h[1] >> 16); + data[ 6] = (byte)(sp->h[1] >> 8); + data[ 7] = (byte)(sp->h[1] >> 0); + data[ 8] = (byte)(sp->h[2] >> 24); + data[ 9] = (byte)(sp->h[2] >> 16); + data[10] = (byte)(sp->h[2] >> 8); + data[11] = (byte)(sp->h[2] >> 0); + data[12] = (byte)(sp->h[3] >> 24); + data[13] = (byte)(sp->h[3] >> 16); + data[14] = (byte)(sp->h[3] >> 8); + data[15] = (byte)(sp->h[3] >> 0); + data[16] = (byte)(sp->h[4] >> 24); + data[17] = (byte)(sp->h[4] >> 16); + data[18] = (byte)(sp->h[4] >> 8); + data[19] = (byte)(sp->h[4] >> 0); #endif - (void) sha1Reset(sp); + sha1Reset(sp); return 0; } diff --git a/beecrypt/sha1.h b/beecrypt/sha1.h index 8c97165..2a811bc 100644 --- a/beecrypt/sha1.h +++ b/beecrypt/sha1.h @@ -26,14 +26,24 @@ #ifndef _SHA1_H #define _SHA1_H -#include "beecrypt.h" +#include "beecrypt/beecrypt.h" +#include "beecrypt/sha1opt.h" -/** \ingroup HASH_sha1_m +/*!\brief Holds all the parameters necessary for the SHA-1 algorithm. + * \ingroup HASH_sha1_m */ typedef struct { + /*!\var h + */ uint32_t h[5]; + /*!\var data + */ uint32_t data[80]; + /*!\var length + * \brief Multi-precision integer counter for the bits that have been + * processed so far. + */ #if (MP_WBITS == 64) mpw length[1]; #elif (MP_WBITS == 32) @@ -41,6 +51,10 @@ typedef struct #else # error #endif + /*!\var offset + * \brief Offset into \a data; points to the place where new data will be + * copied before it is processed. + */ uint32_t offset; } sha1Param; @@ -48,50 +62,48 @@ typedef struct extern "C" { #endif -/** \ingroup HASH_sha1_m - * Holds the full API description of the SHA-1 algorithm. +/*!\var sha1 + * \brief Holds the full API description of the SHA-1 algorithm. */ -/*@observer@*/ /*@unchecked@*/ extern BEECRYPTAPI const hashFunction sha1; -/** \ingroup HASH_sha1_m - * This function performs the SHA-1 hash algorithm on 64 byte blocks of data. - * @param sp hash parameter block +/*!\fn void sha1Process(sha1Param* sp) + * \brief This function performs the core of the SHA-1 hash algorithm; it + * processes a block of 64 bytes. + * \param sp The hash function's parameter block. */ BEECRYPTAPI -void sha1Process(sha1Param* sp) - /*@modifies sp @*/; +void sha1Process(sha1Param* sp); -/** \ingroup HASH_sha1_m - * This function resets the parameter block so that it's ready for a new hash. - * @param sp hash parameter block - * @return 0 on success +/*!\fn int sha1Reset(sha1Param* sp) + * \brief This function resets the parameter block so that it's ready for a + * new hash. + * \param sp The hash function's parameter block. + * \retval 0 on success. */ -BEECRYPTAPI /*@unused@*/ -int sha1Reset (sha1Param* sp) - /*@modifies sp @*/; +BEECRYPTAPI +int sha1Reset (sha1Param* sp); -/** \ingroup HASH_sha1_m - * This function should be used to pass successive blocks of data to be hashed. - * @param sp hash parameter block - * @param *data bytes to hash - * @param size no. of bytes to hash - * @return 0 on success +/*!\fn int sha1Update(sha1Param* sp, const byte* data, size_t size) + * \brief This function should be used to pass successive blocks of data + * to be hashed. + * \param sp The hash function's parameter block. + * \param data + * \param size + * \retval 0 on success. */ -BEECRYPTAPI /*@unused@*/ -int sha1Update (sha1Param* sp, const byte* data, size_t size) - /*@modifies sp @*/; +BEECRYPTAPI +int sha1Update (sha1Param* sp, const byte* data, size_t size); -/** \ingroup HASH_sha1_m - * This function finishes the current hash computation, returning the digest - * value in \a digest. - * @param sp hash parameter block - * @retval *digest 20 byte SHA-1 digest - * @return 0 on success +/*!\fn int sha1Digest(sha1Param* sp, byte* digest) + * \brief This function finishes the current hash computation and copies + * the digest value into \a digest. + * \param sp The hash function's parameter block. + * \param digest The place to store the 20-byte digest. + * \retval 0 on success. */ -BEECRYPTAPI /*@unused@*/ -int sha1Digest (sha1Param* sp, /*@out@*/ byte* digest) - /*@modifies sp, digest @*/; +BEECRYPTAPI +int sha1Digest (sha1Param* sp, byte* digest); #ifdef __cplusplus } diff --git a/beecrypt/sha1opt.h b/beecrypt/sha1opt.h index 6098caa..9fb0eab 100644 --- a/beecrypt/sha1opt.h +++ b/beecrypt/sha1opt.h @@ -1,12 +1,12 @@ -/** \ingroup HASH_sha1_m HASH_m - * \file sha1opt.h - * - * SHA-1 assembler-optimized routines, header. - */ - /* + * sha1opt.h + * + * SHA-1 assembler-optimized routines, header + * * Copyright (c) 2000, 2003 Virtual Unlimited B.V. * + * Author: Bob Deblier + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either @@ -26,6 +26,9 @@ #ifndef _SHA1OPT_H #define _SHA1OPT_H +#include "beecrypt/beecrypt.h" +#include "beecrypt/sha1.h" + #ifdef __cplusplus extern "C" { #endif diff --git a/beecrypt/sha256.c b/beecrypt/sha256.c index 4f9b3ff..a3ee355 100644 --- a/beecrypt/sha256.c +++ b/beecrypt/sha256.c @@ -23,19 +23,19 @@ * \ingroup HASH_m HASH_sha256_m */ -#include "system.h" -#include "sha256.h" -#include "mp.h" -#include "endianness.h" -#include "debug.h" +#define BEECRYPT_DLL_EXPORT + +#if HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/sha256.h" +#include "beecrypt/endianness.h" /*!\addtogroup HASH_sha256_m * \{ */ -/** - */ -/*@observer@*/ /*@unchecked@*/ static const uint32_t k[64] = { 0x428a2f98U, 0x71374491U, 0xb5c0fbcfU, 0xe9b5dba5U, 0x3956c25bU, 0x59f111f1U, 0x923f82a4U, 0xab1c5ed5U, 0xd807aa98U, 0x12835b01U, 0x243185beU, 0x550c7dc3U, 0x72be5d74U, 0x80deb1feU, 0x9bdc06a7U, 0xc19bf174U, @@ -47,30 +47,23 @@ static const uint32_t k[64] = { 0x748f82eeU, 0x78a5636fU, 0x84c87814U, 0x8cc70208U, 0x90befffaU, 0xa4506cebU, 0xbef9a3f7U, 0xc67178f2U }; -/** - */ -/*@observer@*/ /*@unchecked@*/ static const uint32_t hinit[8] = { 0x6a09e667U, 0xbb67ae85U, 0x3c6ef372U, 0xa54ff53aU, 0x510e527fU, 0x9b05688cU, 0x1f83d9abU, 0x5be0cd19U }; -/*@-sizeoftype@*/ -const hashFunction sha256 = { - "SHA-256", - sizeof(sha256Param), - 64U, - 8U * sizeof(uint32_t), - (hashFunctionReset) sha256Reset, - (hashFunctionUpdate) sha256Update, - (hashFunctionDigest) sha256Digest -}; -/*@=sizeoftype@*/ +const hashFunction sha256 = { "SHA-256", sizeof(sha256Param), 64, 32, (hashFunctionReset) sha256Reset, (hashFunctionUpdate) sha256Update, (hashFunctionDigest) sha256Digest }; -int sha256Reset(sha256Param* sp) +int sha256Reset(register sha256Param* sp) { - memcpy(sp->h, hinit, sizeof(sp->h)); - memset(sp->data, 0, sizeof(sp->data)); - memset(&sp->length, 0, sizeof(sp->length)); + memcpy(sp->h, hinit, 8 * sizeof(uint32_t)); + memset(sp->data, 0, 64 * sizeof(uint32_t)); + #if (MP_WBITS == 64) + mpzero(1, sp->length); + #elif (MP_WBITS == 32) + mpzero(2, sp->length); + #else + # error + #endif sp->offset = 0; return 0; } @@ -91,7 +84,7 @@ int sha256Reset(sha256Param* sp) d += temp #ifndef ASM_SHA256PROCESS -void sha256Process(sha256Param* sp) +void sha256Process(register sha256Param* sp) { register uint32_t a, b, c, d, e, f, g, h, temp; register uint32_t *w; @@ -104,7 +97,7 @@ void sha256Process(sha256Param* sp) t = 16; while (t--) { - temp = swapu32(*w); + register uint32_t temp = swapu32(*w); *(w++) = temp; } #endif @@ -112,7 +105,7 @@ void sha256Process(sha256Param* sp) t = 48; while (t--) { - temp = sig1(w[-2]) + w[-7] + sig0(w[-15]) + w[-16]; + register uint32_t temp = sig1(w[-2]) + w[-7] + sig0(w[-15]) + w[-16]; *(w++) = temp; } @@ -197,7 +190,7 @@ void sha256Process(sha256Param* sp) } #endif -int sha256Update(sha256Param* sp, const byte* data, size_t size) +int sha256Update(register sha256Param* sp, const byte* data, size_t size) { register uint32_t proclength; @@ -205,21 +198,20 @@ int sha256Update(sha256Param* sp, const byte* data, size_t size) mpw add[1]; mpsetw(1, add, size); mplshift(1, add, 3); - (void) mpadd(1, sp->length, add); + mpadd(1, sp->length, add); #elif (MP_WBITS == 32) mpw add[2]; mpsetw(2, add, size); mplshift(2, add, 3); - (void) mpadd(2, sp->length, add); + mpadd(2, sp->length, add); #else # error #endif -/*@-type@*/ while (size > 0) { proclength = ((sp->offset + size) > 64U) ? (64U - sp->offset) : size; - memmove(((byte *) sp->data) + sp->offset, data, proclength); + memcpy(((byte *) sp->data) + sp->offset, data, proclength); size -= proclength; data += proclength; sp->offset += proclength; @@ -230,21 +222,15 @@ int sha256Update(sha256Param* sp, const byte* data, size_t size) sp->offset = 0; } } -/*@=type@*/ return 0; } -/** - */ -static void sha256Finish(sha256Param* sp) - /*@globals internalState @*/ - /*@modifies sp, internalState @*/ +static void sha256Finish(register sha256Param* sp) { register byte *ptr = ((byte *) sp->data) + sp->offset++; *(ptr++) = 0x80; -/*@-type@*/ if (sp->offset > 56) { while (sp->offset++ < 64) @@ -257,7 +243,6 @@ static void sha256Finish(sha256Param* sp) ptr = ((byte *) sp->data) + sp->offset; while (sp->offset++ < 56) *(ptr++) = 0; -/*@=type@*/ #if (MP_WBITS == 64) ptr[0] = (byte)(sp->length[0] >> 56); @@ -285,45 +270,45 @@ static void sha256Finish(sha256Param* sp) sp->offset = 0; } -int sha256Digest(sha256Param* sp, byte* digest) +int sha256Digest(register sha256Param* sp, byte* data) { sha256Finish(sp); /* encode 8 integers big-endian style */ - digest[ 0] = (byte)(sp->h[0] >> 24); - digest[ 1] = (byte)(sp->h[0] >> 16); - digest[ 2] = (byte)(sp->h[0] >> 8); - digest[ 3] = (byte)(sp->h[0] >> 0); - digest[ 4] = (byte)(sp->h[1] >> 24); - digest[ 5] = (byte)(sp->h[1] >> 16); - digest[ 6] = (byte)(sp->h[1] >> 8); - digest[ 7] = (byte)(sp->h[1] >> 0); - digest[ 8] = (byte)(sp->h[2] >> 24); - digest[ 9] = (byte)(sp->h[2] >> 16); - digest[10] = (byte)(sp->h[2] >> 8); - digest[11] = (byte)(sp->h[2] >> 0); - digest[12] = (byte)(sp->h[3] >> 24); - digest[13] = (byte)(sp->h[3] >> 16); - digest[14] = (byte)(sp->h[3] >> 8); - digest[15] = (byte)(sp->h[3] >> 0); - digest[16] = (byte)(sp->h[4] >> 24); - digest[17] = (byte)(sp->h[4] >> 16); - digest[18] = (byte)(sp->h[4] >> 8); - digest[19] = (byte)(sp->h[4] >> 0); - digest[20] = (byte)(sp->h[5] >> 24); - digest[21] = (byte)(sp->h[5] >> 16); - digest[22] = (byte)(sp->h[5] >> 8); - digest[23] = (byte)(sp->h[5] >> 0); - digest[24] = (byte)(sp->h[6] >> 24); - digest[25] = (byte)(sp->h[6] >> 16); - digest[26] = (byte)(sp->h[6] >> 8); - digest[27] = (byte)(sp->h[6] >> 0); - digest[28] = (byte)(sp->h[7] >> 24); - digest[29] = (byte)(sp->h[7] >> 16); - digest[30] = (byte)(sp->h[7] >> 8); - digest[31] = (byte)(sp->h[7] >> 0); - - (void) sha256Reset(sp); + data[ 0] = (byte)(sp->h[0] >> 24); + data[ 1] = (byte)(sp->h[0] >> 16); + data[ 2] = (byte)(sp->h[0] >> 8); + data[ 3] = (byte)(sp->h[0] >> 0); + data[ 4] = (byte)(sp->h[1] >> 24); + data[ 5] = (byte)(sp->h[1] >> 16); + data[ 6] = (byte)(sp->h[1] >> 8); + data[ 7] = (byte)(sp->h[1] >> 0); + data[ 8] = (byte)(sp->h[2] >> 24); + data[ 9] = (byte)(sp->h[2] >> 16); + data[10] = (byte)(sp->h[2] >> 8); + data[11] = (byte)(sp->h[2] >> 0); + data[12] = (byte)(sp->h[3] >> 24); + data[13] = (byte)(sp->h[3] >> 16); + data[14] = (byte)(sp->h[3] >> 8); + data[15] = (byte)(sp->h[3] >> 0); + data[16] = (byte)(sp->h[4] >> 24); + data[17] = (byte)(sp->h[4] >> 16); + data[18] = (byte)(sp->h[4] >> 8); + data[19] = (byte)(sp->h[4] >> 0); + data[20] = (byte)(sp->h[5] >> 24); + data[21] = (byte)(sp->h[5] >> 16); + data[22] = (byte)(sp->h[5] >> 8); + data[23] = (byte)(sp->h[5] >> 0); + data[24] = (byte)(sp->h[6] >> 24); + data[25] = (byte)(sp->h[6] >> 16); + data[26] = (byte)(sp->h[6] >> 8); + data[27] = (byte)(sp->h[6] >> 0); + data[28] = (byte)(sp->h[7] >> 24); + data[29] = (byte)(sp->h[7] >> 16); + data[30] = (byte)(sp->h[7] >> 8); + data[31] = (byte)(sp->h[7] >> 0); + + sha256Reset(sp); return 0; } diff --git a/beecrypt/sha256.h b/beecrypt/sha256.h index 65a1b08..9c3db97 100644 --- a/beecrypt/sha256.h +++ b/beecrypt/sha256.h @@ -26,14 +26,23 @@ #ifndef _SHA256_H #define _SHA256_H -#include "beecrypt.h" +#include "beecrypt/beecrypt.h" -/** \ingroup HASH_sha256_m +/*!\brief Holds all the parameters necessary for the SHA-256 algorithm. + * \ingroup HASH_sha256_m */ typedef struct { + /*!\var h + */ uint32_t h[8]; + /*!\var data + */ uint32_t data[64]; + /*!\var length + * \brief Multi-precision integer counter for the bits that have been + * processed so far. + */ #if (MP_WBITS == 64) mpw length[1]; #elif (MP_WBITS == 32) @@ -41,6 +50,10 @@ typedef struct #else # error #endif + /*!\var offset + * \brief Offset into \a data; points to the place where new data will be + * copied before it is processed. + */ uint32_t offset; } sha256Param; @@ -48,55 +61,48 @@ typedef struct extern "C" { #endif -/** \ingroup HASH_sha256_m - * Holds the full API description of the SHA-256 algorithm. +/*!\var sha256 + * \brief Holds the full API description of the SHA-256 algorithm. */ -/*@observer@*/ /*@checked@*/ extern BEECRYPTAPI const hashFunction sha256; -/*@-exportlocal@*/ -/** \ingroup HASH_sha256_m - * This function performs the SHA-256 hash algorithm on 64 byte blocks of data. - * @param sp hash parameter block +/*!\fn void sha256Process(sha256Param* sp) + * \brief This function performs the core of the SHA-256 hash algorithm; it + * processes a block of 64 bytes. + * \param sp The hash function's parameter block. */ BEECRYPTAPI -void sha256Process(sha256Param* sp) - /*@globals internalState @*/ - /*@modifies sp, internalState @*/; +void sha256Process(sha256Param* sp); -/** \ingroup HASH_sha256_m - * This function resets the parameter block so that it's ready for a new hash. - * @param sp hash parameter block - * @return 0 on success +/*!\fn int sha256Reset(sha256Param* sp) + * \brief This function resets the parameter block so that it's ready for a + * new hash. + * \param sp The hash function's parameter block. + * \retval 0 on success. */ BEECRYPTAPI -int sha256Reset (sha256Param* sp) - /*@modifies sp @*/; +int sha256Reset (sha256Param* sp); -/** \ingroup HASH_sha256_m - * This function should be used to pass successive blocks of data to be hashed. - * @param sp hash parameter block - * @param *data bytes to hash - * @param size no. of bytes to hash - * @return 0 on success +/*!\fn int sha256Update(sha256Param* sp, const byte* data, size_t size) + * \brief This function should be used to pass successive blocks of data + * to be hashed. + * \param sp The hash function's parameter block. + * \param data + * \param size + * \retval 0 on success. */ BEECRYPTAPI -int sha256Update (sha256Param* sp, const byte* data, size_t size) - /*@globals internalState @*/ - /*@modifies sp, internalState @*/; +int sha256Update (sha256Param* sp, const byte* data, size_t size); -/** \ingroup HASH_sha256_m - * This function finishes the current hash computation, returning the digest - * value in \a digest. - * @param sp hash parameter block - * @retval *digest 32 byte SHA-256 digest - * @return 0 on success +/*!\fn int sha256Digest(sha256Param* sp, byte* digest) + * \brief This function finishes the current hash computation and copies + * the digest value into \a digest. + * \param sp The hash function's parameter block. + * \param digest The place to store the 32-byte digest. + * \retval 0 on success. */ BEECRYPTAPI -int sha256Digest (sha256Param* sp, /*@out@*/ byte* digest) - /*@globals internalState @*/ - /*@modifies sp, digest, internalState @*/; -/*@=exportlocal@*/ +int sha256Digest (sha256Param* sp, byte* digest); #ifdef __cplusplus } diff --git a/beecrypt/stamp-h.in b/beecrypt/stamp-h.in deleted file mode 100644 index 9788f70..0000000 --- a/beecrypt/stamp-h.in +++ /dev/null @@ -1 +0,0 @@ -timestamp diff --git a/beecrypt/system.h b/beecrypt/system.h deleted file mode 100644 index 7776030..0000000 --- a/beecrypt/system.h +++ /dev/null @@ -1,89 +0,0 @@ -/** - * \file beecrypt/system.h - */ - -#ifndef H_SYSTEM -#define H_SYSTEM - -#define BEECRYPT_DLL_EXPORT - -#if defined(_WIN32) && !defined(WIN32) -# define WIN32 1 -#endif - -#if WIN32 && !__CYGWIN32__ -# include "config.win.h" -#else -# ifdef HAVE_CONFIG_H -# include "config.h" -# endif -#endif - -#if defined(__LCLINT__) -/* XXX from /usr/include/bits/sigest.h in glibc-2.2.4 */ -/*@-sizeoftype@*/ -# define _SIGSET_NWORDS (1024 / (8 * sizeof (unsigned long int))) -/*@-redef@*/ -typedef struct - { - unsigned long int __val[_SIGSET_NWORDS]; - } __sigset_t; -/*@=redef@*/ -/*@=sizeoftype@*/ -#endif - -#include "beecrypt.gnu.h" - -#if HAVE_SYS_STAT_H -# include -# include -#endif - -#include - -#ifdef HAVE_UNISTD_H -# include -#endif - -#if TIME_WITH_SYS_TIME -# include -# include -#else -# if HAVE_SYS_TIME_H -# include -# else -# include -# endif -#endif - -#if HAVE_TIME_H -# include -#endif - -#ifdef HAVE_STRING_H -# include -#endif - -#if HAVE_ERRNO_H -# include -#endif - -#if HAVE_STDLIB_H -# include -#endif - -#ifdef HAVE_FCNTL_H -# include -#else -# include -#endif - -#if HAVE_CTYPE_H -# include -#endif - -#if HAVE_MALLOC_H && !defined(__LCLINT__) -# include -#endif - -#endif /* H_SYSTEM */ diff --git a/beecrypt/tests/.cvsignore b/beecrypt/tests/.cvsignore deleted file mode 100644 index 5e7d056..0000000 --- a/beecrypt/tests/.cvsignore +++ /dev/null @@ -1,37 +0,0 @@ -.deps -.depend -.depend-done -.libs -Makefile -Makefile.in -config.cache -config.guess -config.log -config.status -config.sub -configure -libtool -ltconfig -ltmain.sh -*.o -*.lo -stamp-h -stamp-h.in -base64bug -beetest -benchbc -benchhf -benchme -openpgp -testaes -testblowfish -testdldp -testdsa -testhmacmd5 -testhmacsha1 -testmd5 -testmp -testmpinv -testrsa -testsha1 -testsha256 diff --git a/beecrypt/tests/Makefile.am b/beecrypt/tests/Makefile.am index 9f04620..beefd28 100644 --- a/beecrypt/tests/Makefile.am +++ b/beecrypt/tests/Makefile.am @@ -53,7 +53,7 @@ testrsa_SOURCES = testrsa.c testdldp_SOURCES = testdldp.c -EXTRA_PROGRAMS = benchme benchhf benchbc +EXTRA_PROGRAMS = benchme benchhf benchbc testconv benchme_SOURCES = benchme.c @@ -61,6 +61,8 @@ benchhf_SOURCES = benchhf.c benchbc_SOURCES = benchbc.c +testconv_SOURCES = testconv.c + # Run every benchmark test twice bench: benchme benchhf benchbc ./benchme diff --git a/beecrypt/tests/beetest.c b/beecrypt/tests/beetest.c deleted file mode 100644 index 3a63590..0000000 --- a/beecrypt/tests/beetest.c +++ /dev/null @@ -1,793 +0,0 @@ -/*@-compdef@*/ -/* - * beetest.c - * - * BeeCrypt test and benchmark application - * - * Copyright (c) 1999, 2000, 2001, 2002 Virtual Unlimited B.V. - * - * Author: Bob Deblier - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#include "system.h" -#include "beecrypt.h" -#include "blockmode.h" -#include "aes.h" -#include "blowfish.h" -#include "mpbarrett.h" -#include "dhaes.h" -#include "dlkp.h" -#include "dsa.h" -#include "elgamal.h" -#include "hmacmd5.h" -#include "md5.h" -#include "rsa.h" -#include "sha1.h" -#include "sha256.h" -#include "mp.h" -#include "debug.h" - -/*@unchecked@*/ /*@observer@*/ /*@unused@*/ -static const char* dsa_p = "8df2a494492276aa3d25759bb06869cbeac0d83afb8d0cf7cbb8324f0d7882e5d0762fc5b7210eafc2e9adac32ab7aac49693dfbf83724c2ec0736ee31c80291"; -/*@unchecked@*/ /*@observer@*/ /*@unused@*/ -static const char* dsa_q = "c773218c737ec8ee993b4f2ded30f48edace915f"; -/*@unchecked@*/ /*@observer@*/ /*@unused@*/ -static const char* dsa_g = "626d027839ea0a13413163a55b4cb500299d5522956cefcb3bff10f399ce2c2e71cb9de5fa24babf58e5b79521925c9cc42e9f6f464b088cc572af53e6d78802"; -/*@unchecked@*/ /*@observer@*/ /*@unused@*/ -static const char* dsa_x = "2070b3223dba372fde1c0ffc7b2e3b498b260614"; -/*@unchecked@*/ /*@observer@*/ /*@unused@*/ -static const char* dsa_y = "19131871d75b1612a819f29d78d1b0d7346f7aa77bb62a859bfd6c5675da9d212d3a36ef1672ef660b8c7c255cc0ec74858fba33f44c06699630a76b030ee333"; -/*@unchecked@*/ /*@observer@*/ /*@unused@*/ -static const char* elg_n = "8df2a494492276aa3d25759bb06869cbeac0d83afb8d0cf7cbb8324f0d7882e5d0762fc5b7210eafc2e9adac32ab7aac49693dfbf83724c2ec0736ee31c80290"; - -/*@unused@*/ -static int testVectorInvMod(const dlkp_p* keypair) - /*@*/ -{ - randomGeneratorContext rngc; - int rc = -1; - -/*@-branchstate@*/ - /*@-modobserver -usedef @*/ - if (randomGeneratorContextInit(&rngc, randomGeneratorDefault()) == 0) - /*@=modobserver =usedef @*/ - { - register size_t size = keypair->param.p.size; - register mpw* temp = (mpw*) malloc((8*size+6) * sizeof(*temp)); - - assert(temp != NULL); - mpbrndinv_w(&keypair->param.n, &rngc, temp, temp+size, temp+2*size); - - mpbmulmod_w(&keypair->param.n, size, temp, size, temp+size, temp, temp+2*size); - - rc = mpisone(size, temp); - - free(temp); - - /*@-modobserver -usedef @*/ - (void) randomGeneratorContextFree(&rngc); - /*@=modobserver =usedef @*/ - } -/*@=branchstate@*/ - return rc; -} - -/*@unused@*/ -static int testVectorExpMod(const dlkp_p* keypair) - /*@*/ -{ - int rc; - mpnumber y; - - mpnzero(&y); - - mpbnpowmod(&keypair->param.p, &keypair->param.g, &keypair->x, &y); - - rc = mpeqx(y.size, y.data, keypair->y.size, keypair->y.data); - - mpnfree(&y); - - return rc; -} - -/*@unused@*/ -static int testVectorElGamalV1(const dlkp_p* keypair) - /*@*/ -{ - int rc = 0; - - randomGeneratorContext rngc; - -/*@-branchstate@*/ - /*@-modobserver -usedef @*/ - if (randomGeneratorContextInit(&rngc, randomGeneratorDefault()) == 0) - /*@=modobserver =usedef @*/ - { - mpnumber digest, r, s; - - mpnzero(&digest); - mpnzero(&r); - mpnzero(&s); - - mpnsize(&digest, 5); - memset(digest.data, 0, digest.size * sizeof(*digest.data)); - -/*@-noeffectuncon@*/ - (void) rngc.rng->next(rngc.param, digest.data, digest.size); -/*@=noeffectuncon@*/ - - (void) elgv1sign(&keypair->param.p, &keypair->param.n, &keypair->param.g, &rngc, &digest, &keypair->x, &r, &s); - - rc = elgv1vrfy(&keypair->param.p, &keypair->param.n, &keypair->param.g, &digest, &keypair->y, &r, &s); - - mpnfree(&digest); - mpnfree(&r); - mpnfree(&s); - - /*@-modobserver -usedef @*/ - (void) randomGeneratorContextFree(&rngc); - /*@=modobserver =usedef @*/ - } -/*@=branchstate@*/ - return rc; -} - -/*@unused@*/ -static int testVectorElGamalV3(const dlkp_p* keypair) - /*@*/ -{ - int rc = 0; - - randomGeneratorContext rngc; - -/*@-branchstate@*/ - /*@-modobserver -usedef @*/ - if (randomGeneratorContextInit(&rngc, randomGeneratorDefault()) == 0) - /*@=modobserver =usedef @*/ - { - mpnumber digest, r, s; - - mpnzero(&digest); - mpnzero(&r); - mpnzero(&s); - - mpnsize(&digest, 5); - memset(digest.data, 0, digest.size * sizeof(*digest.data)); - -/*@-noeffectuncon@*/ - (void) rngc.rng->next(rngc.param, digest.data, digest.size); -/*@=noeffectuncon@*/ - - (void) elgv3sign(&keypair->param.p, &keypair->param.n, &keypair->param.g, &rngc, &digest, &keypair->x, &r, &s); - - rc = elgv3vrfy(&keypair->param.p, &keypair->param.n, &keypair->param.g, &digest, &keypair->y, &r, &s); - - mpnfree(&digest); - mpnfree(&r); - mpnfree(&s); - - /*@-modobserver -usedef @*/ - (void) randomGeneratorContextFree(&rngc); - /*@=modobserver =usedef @*/ - } -/*@=branchstate@*/ - return rc; -} - -/*@unchecked@*/ /*@observer@*/ -static uint32_t keyValue[] = -{ - 0x00010203, - 0x04050607, - 0x08090a0b, - 0x0c0d0e0f, - 0x10111213, - 0x14151617, - 0x18191a1b, - 0x1c1d1e1f, - 0x20212223, - 0x24252627, - 0x28292a2b, - 0x2c2d2e2f, - 0x30313233, - 0x34353637, - 0x38393a3b, - 0x3c3d3e3f -}; - -static void testBlockInit(uint8_t* block, size_t length) - /*@modifies *block @*/ -{ - register unsigned int i; - for (i = 1U; i <= length; i++) { - *block = (uint8_t) i; - block++; - } -} - -static void testBlockCiphers(void) - /*@globals fileSystem, internalState @*/ - /*@modifies fileSystem, internalState @*/ -{ - unsigned int k; - int i; - - printf("Timing the blockciphers:\n"); - - for (i = 0; i < blockCipherCount(); i++) - { - const blockCipher* tmp = blockCipherGet(i); - - if (tmp) - { - size_t blockwords = tmp->blocksize >> 2; - - mpw* src_block = (mpw*) calloc(1, 2 * blockwords * sizeof(*src_block)); - mpw* enc_block = (mpw*) malloc(2 * blockwords * sizeof(*enc_block)); - mpw* dec_block = (mpw*) malloc(2 * blockwords * sizeof(*dec_block)); - mpw* spd_block = (mpw*) malloc(1024 * 1024 * blockwords * sizeof(*spd_block)); - - void* encrypt_param = (void*) malloc(tmp->paramsize); - void* decrypt_param = (void*) malloc(tmp->paramsize); - - assert(src_block != NULL); - assert(enc_block != NULL); - assert(dec_block != NULL); - assert(spd_block != NULL); - assert(encrypt_param != NULL); - assert(decrypt_param != NULL); - - printf(" %s:\n", tmp->name); - - for (k = tmp->keybitsmin; k <= tmp->keybitsmax; k += tmp->keybitsinc) - { - printf(" setup encrypt (%u bits key): ", k); - if (tmp->setup(encrypt_param, keyValue, k, ENCRYPT) < 0) - { - printf("failed\n"); - /*@innercontinue@*/ continue; - } - printf("ok\n"); - printf(" setup decrypt (%u bits key): ", k); - if (tmp->setup(decrypt_param, keyValue, k, DECRYPT) < 0) - { - printf("failed\n"); - /*@innercontinue@*/ continue; - } - printf("ok\n"); - printf(" encrypt/decrypt test block: "); - testBlockInit((uint8_t*) src_block, tmp->blocksize >> 2); - - (void) blockEncryptCBC(tmp, encrypt_param, enc_block, src_block, 2U); - (void) blockDecryptCBC(tmp, decrypt_param, dec_block, enc_block, 2U); - - if (memcmp(dec_block, src_block, tmp->blocksize >> 2)) - { - printf("failed\n"); - /*@innercontinue@*/ continue; - } - printf("ok\n"); - printf(" speed measurement:\n"); - { - #if HAVE_TIME_H - double ttime; - clock_t tstart, tstop; - #endif - - #if HAVE_TIME_H - tstart = clock(); - #endif - (void) blockEncryptECB(tmp, encrypt_param, spd_block, spd_block, 1024U * 1024U); - #if HAVE_TIME_H - tstop = clock(); - ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC; - printf(" ECB encrypts 1M blocks of %u bits in %.3f seconds (%.3f MB/s)\n", tmp->blocksize << 3, ttime, (tmp->blocksize) / ttime); - #endif - #if HAVE_TIME_H - tstart = clock(); - #endif - (void) blockDecryptECB(tmp, decrypt_param, spd_block, spd_block, 1024U * 1024U); - #if HAVE_TIME_H - tstop = clock(); - ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC; - printf(" ECB decrypts 1M blocks of %u bits in %.3f seconds (%.3f MB/s)\n", tmp->blocksize << 3, ttime, (tmp->blocksize) / ttime); - #endif - #if HAVE_TIME_H - tstart = clock(); - #endif - (void) blockEncryptCBC(tmp, encrypt_param, spd_block, spd_block, 1024U * 1024U); - #if HAVE_TIME_H - tstop = clock(); - ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC; - printf(" CBC encrypts 1M blocks of %u bits in %.3f seconds (%.3f MB/s)\n", tmp->blocksize << 3, ttime, (tmp->blocksize) / ttime); - #endif - #if HAVE_TIME_H - tstart = clock(); - #endif - (void) blockDecryptCBC(tmp, decrypt_param, spd_block, spd_block, 1024U * 1024U); - #if HAVE_TIME_H - tstop = clock(); - ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC; - printf(" CBC decrypts 1M blocks of %u bits in %.3f seconds (%.3f MB/s)\n", tmp->blocksize << 3, ttime, (tmp->blocksize) / ttime); - #endif - } - } - free(spd_block); - free(dec_block); - free(enc_block); - free(src_block); - free(decrypt_param); - free(encrypt_param); - } - } -} - -static void testHashFunctions(void) - /*@globals fileSystem, internalState @*/ - /*@modifies fileSystem, internalState @*/ -{ - int i, j; - - uint8_t* data = (uint8_t*) malloc(32 * 1024 * 1024); - - if (data) - { - hashFunctionContext hfc; - - printf("Timing the hash functions:\n"); - - for (i = 0; i < hashFunctionCount(); i++) - { - const hashFunction* tmp = hashFunctionGet(i); - -/*@-branchstate@*/ - if (tmp) - { - #if HAVE_TIME_H - double ttime; - clock_t tstart, tstop; - #endif - mpnumber digest; - - mpnzero(&digest); - - printf(" %s:\n", tmp->name); - - /*@-modobserver -usedef @*/ - if (hashFunctionContextInit(&hfc, tmp) == 0) - /*@=modobserver =usedef @*/ - { - for (j = 0; j < 4; j++) - { - #if HAVE_TIME_H - tstart = clock(); - #endif - - (void) hashFunctionContextUpdate(&hfc, data, 32 * 1024 * 1024); - (void) hashFunctionContextDigestMP(&hfc, &digest); - - #if HAVE_TIME_H - tstop = clock(); - ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC; - printf(" hashes 32 MB in %.3f seconds (%.3f MB/s)\n", ttime, 32.0 / ttime); - #endif - } - - /*@-modobserver -usedef @*/ - (void) hashFunctionContextFree(&hfc); - /*@=modobserver =usedef @*/ - } - - mpnfree(&digest); - } -/*@=branchstate@*/ - } - free(data); - } -} - -static void testExpMods(void) - /*@globals fileSystem, internalState @*/ - /*@modifies fileSystem, internalState @*/ -{ - /*@unchecked@*/ /*@observer@*/ - static const char* p_512 = "ffcf0a0767f18f9b659d92b9550351430737c3633dc6ae7d52445d937d8336e07a7ccdb119e9ab3e011a8f938151230e91187f84ac05c3220f335193fc5e351b"; - - /*@unchecked@*/ /*@observer@*/ - static const char* p_768 = "f9c3dc0b8e199094e3e69386e01de863908348196d6ad2557065e6ba36d10412579f394d1114c954ee647c84551d52f214e1e1682a75e7074b91085cfaf20b2888aa056bf760948a0b678bc253633eccfca86556ddb90f000ef93041b0d53171"; - - /*@unchecked@*/ /*@observer@*/ - static const char* p_1024 = "c615c47a56b47d869010256171ab164525f2ef4b887a4e0cdfc87043a9dd8894f2a18fa56729448e700f4b7420470b61257d11ecefa9ff518dc9fed5537ec6a9665ba73c948674320ff61b29c4cfa61e5baf47dfc1b80939e1bffb51787cc3252c4d1190a7f13d1b0f8d4aa986571ce5d4de5ecede1405e9bc0b5bf040a46d99"; - - randomGeneratorContext rngc; - - mpbarrett p; - mpnumber tmp; - mpnumber g; - mpnumber x; - mpnumber y; - - mpbzero(&p); - mpnzero(&g); - mpnzero(&x); - mpnzero(&y); - mpnzero(&tmp); - -/*@-branchstate@*/ - /*@-modobserver -usedef @*/ - if (randomGeneratorContextInit(&rngc, randomGeneratorDefault()) == 0) - /*@=modobserver =usedef @*/ - { - int i; - #if HAVE_TIME_H - double ttime; - clock_t tstart, tstop; - #endif - - printf("Timing modular exponentiations:\n"); - printf(" (512 bits ^ 512 bits) mod 512 bits:"); - mpnsethex(&tmp, p_512); - mpbset(&p, tmp.size, tmp.data); - mpnsize(&g, p.size); - mpnsize(&x, p.size); - mpbnrnd(&p, &rngc, &g); - mpbnrnd(&p, &rngc, &x); - #if HAVE_TIME_H - tstart = clock(); - #endif - for (i = 0; i < 100; i++) - mpbnpowmod(&p, &g, &x, &y); - #if HAVE_TIME_H - tstop = clock(); - ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC; - printf(" 100x in %.3f seconds\n", ttime); - #endif - printf(" (768 bits ^ 768 bits) mod 768 bits:"); - mpnsethex(&tmp, p_768); - mpbset(&p, tmp.size, tmp.data); - mpnsize(&g, p.size); - mpnsize(&x, p.size); - mpbnrnd(&p, &rngc, &g); - mpbnrnd(&p, &rngc, &x); - #if HAVE_TIME_H - tstart = clock(); - #endif - for (i = 0; i < 100; i++) - mpbnpowmod(&p, &g, &x, &y); - #if HAVE_TIME_H - tstop = clock(); - ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC; - printf(" 100x in %.3f seconds\n", ttime); - #endif - printf(" (1024 bits ^ 1024 bits) mod 1024 bits:"); - mpnsethex(&tmp, p_1024); - mpbset(&p, tmp.size, tmp.data); - mpnsize(&g, p.size); - mpnsize(&x, p.size); - mpbnrnd(&p, &rngc, &g); - mpbnrnd(&p, &rngc, &x); - #if HAVE_TIME_H - tstart = clock(); - #endif - for (i = 0; i < 100; i++) - mpbnpowmod(&p, &g, &x, &y); - #if HAVE_TIME_H - tstop = clock(); - ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC; - printf(" 100x in %.3f seconds\n", ttime); - #endif - /* now run a test with x having 160 bits */ - mpnsize(&x, 5); -/*@-noeffectuncon@*/ - (void) rngc.rng->next(rngc.param, x.data, x.size); -/*@=noeffectuncon@*/ - printf(" (1024 bits ^ 160 bits) mod 1024 bits:"); - #if HAVE_TIME_H - tstart = clock(); - #endif - for (i = 0; i < 100; i++) - mpbnpowmod(&p, &g, &x, &y); - #if HAVE_TIME_H - tstop = clock(); - ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC; - printf(" 100x in %.3f seconds\n", ttime); - #endif - mpbfree(&p); - mpnfree(&g); - mpnfree(&x); - mpnfree(&y); - mpnfree(&tmp); - - /*@-modobserver -usedef @*/ - (void) randomGeneratorContextFree(&rngc); - /*@=modobserver =usedef @*/ - } - else - printf("random generator setup problem\n"); -/*@=branchstate@*/ -} - -static void testRSA(void) - /*@globals fileSystem, internalState @*/ - /*@modifies fileSystem, internalState @*/ -{ - randomGeneratorContext rngc; - mpnumber hm, s; - rsakp kp; - int xx; - - mpnzero(&hm); - mpnzero(&s); - - printf("Timing RSA:\n"); - - (void) rsakpInit(&kp); - -/*@-branchstate@*/ - /*@-modobserver -usedef @*/ - if (randomGeneratorContextInit(&rngc, randomGeneratorDefault()) == 0) - /*@=modobserver =usedef @*/ - { - int i; - - #if HAVE_TIME_H - double ttime; - clock_t tstart, tstop; - #endif - - printf(" generating 1024 bit crt keypair\n"); - - #if HAVE_TIME_H - tstart = clock(); - #endif - (void) rsakpMake(&kp, &rngc, (1024 >> 5)); - #if HAVE_TIME_H - tstop = clock(); - ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC; - printf(" done in %.3f seconds\n", ttime); - #endif - - mpnsize(&hm, 4); -/*@-noeffectuncon@*/ - (void) rngc.rng->next(rngc.param, hm.data, hm.size); -/*@=noeffectuncon@*/ - - printf(" RSA sign:"); - #if HAVE_TIME_H - tstart = clock(); - #endif - for (i = 0; i < 100; i++) - { - xx = rsapricrt(&kp, &hm, &s); - } - #if HAVE_TIME_H - tstop = clock(); - ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC; - printf(" 100x in %.3f seconds\n", ttime); - #endif - - printf(" RSA verify:"); - #if HAVE_TIME_H - tstart = clock(); - #endif - for (i = 0; i < 1000; i++) - { - xx = rsavrfy((rsapk*) &kp, &hm, &s); - } - #if HAVE_TIME_H - tstop = clock(); - ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC; - printf(" 1000x in %.3f seconds\n", ttime); - #endif - - (void) rsakpFree(&kp); - - /*@-modobserver -usedef @*/ - (void) randomGeneratorContextFree(&rngc); - /*@=modobserver =usedef @*/ - } -/*@=branchstate@*/ -} - -static void testDLAlgorithms(void) - /*@globals fileSystem, internalState @*/ - /*@modifies fileSystem, internalState @*/ -{ - randomGeneratorContext rngc; - mpnumber hm, r, s; - dldp_p dp; - dlkp_p kp; - int xx; - - mpnzero(&hm); - mpnzero(&r); - mpnzero(&s); - - (void) dldp_pInit(&dp); - (void) dlkp_pInit(&kp); - - printf("Timing Discrete Logarithm algorithms:\n"); - -/*@-branchstate@*/ - /*@-modobserver -usedef @*/ - if (randomGeneratorContextInit(&rngc, randomGeneratorDefault()) == 0) - /*@=modobserver =usedef @*/ - { - int i; - - #if HAVE_TIME_H - double ttime; - clock_t tstart, tstop; - #endif - printf(" generating P (1024 bits) Q (160 bits) G with order Q\n"); - #if HAVE_TIME_H - tstart = clock(); - #endif - (void) dldp_pgoqMake(&dp, &rngc, 1024 >> 5, 160 >> 5, 1); - #if HAVE_TIME_H - tstop = clock(); - ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC; - printf(" done in %.3f seconds\n", ttime); - #endif - - (void) dlkp_pInit(&kp); - printf(" generating keypair\n"); - #if HAVE_TIME_H - tstart = clock(); - #endif - (void) dlkp_pPair(&kp, &rngc, &dp); - #if HAVE_TIME_H - tstop = clock(); - ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC; - printf(" done in %.3f seconds\n", ttime); - #endif - - mpnsize(&hm, 5); -/*@-noeffectuncon@*/ - (void) rngc.rng->next(rngc.param, hm.data, hm.size); -/*@=noeffectuncon@*/ - - printf(" DSA sign:"); - #if HAVE_TIME_H - tstart = clock(); - #endif - for (i = 0; i < 100; i++) - { - xx = dsasign(&kp.param.p, &kp.param.q, &kp.param.g, &rngc, &hm, &kp.x, &r, &s); - } - #if HAVE_TIME_H - tstop = clock(); - ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC; - printf(" 100x in %.3f seconds\n", ttime); - #endif - - printf(" DSA verify:"); - #if HAVE_TIME_H - tstart = clock(); - #endif - for (i = 0; i < 100; i++) - { - xx = dsavrfy(&kp.param.p, &kp.param.q, &kp.param.g, &hm, &kp.y, &r, &s); - } - #if HAVE_TIME_H - tstop = clock(); - ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC; - printf(" 100x in %.3f seconds\n", ttime); - #endif - (void) dlkp_pFree(&kp); -/*@-usedef@*/ - (void) dldp_pFree(&dp); -/*@=usedef@*/ - - printf(" generating P (1024 bits) Q (768 bits) G with order (P-1)\n"); - #if HAVE_TIME_H - tstart = clock(); - #endif -/*@-usereleased@*/ - (void) dldp_pgonMake(&dp, &rngc, 1024 >> 5, 768 >> 5); -/*@=usereleased@*/ - #if HAVE_TIME_H - tstop = clock(); - ttime = ((double)(tstop - tstart)) / CLOCKS_PER_SEC; - printf(" done in %.3f seconds\n", ttime); - #endif -/*@-usedef@*/ - (void) dldp_pFree(&dp); -/*@=usedef@*/ - - /*@-modobserver -usedef @*/ - (void) randomGeneratorContextFree(&rngc); - /*@=modobserver =usedef @*/ - } -/*@=branchstate@*/ -} - -int main(/*@unused@*/ int argc, /*@unused@*/ char *argv[]) - /*@globals fileSystem, internalState @*/ - /*@modifies fileSystem, internalState @*/ -{ - unsigned int j; - int i; - - printf("the beecrypt library implements:\n"); - printf(" %d entropy source%s:\n", entropySourceCount(), entropySourceCount() == 1 ? "" : "s"); - for (i = 0; i < entropySourceCount(); i++) - { - const entropySource* tmp = entropySourceGet(i); - if (tmp) - printf(" %s\n", tmp->name); - else - printf("*** error: library corrupt\n"); - } - printf(" %d random generator%s:\n", randomGeneratorCount(), randomGeneratorCount() == 1 ? "" : "s"); - for (i = 0; i < randomGeneratorCount(); i++) - { - const randomGenerator* tmp = randomGeneratorGet(i); - if (tmp) - printf(" %s\n", tmp->name); - else - printf("*** error: library corrupt\n"); - } - printf(" %d hash function%s:\n", hashFunctionCount(), hashFunctionCount() == 1 ? "" : "s"); - for (i = 0; i < hashFunctionCount(); i++) - { - const hashFunction* tmp = hashFunctionGet(i); - if (tmp) - printf(" %s\n", tmp->name); - else - printf("*** error: library corrupt\n"); - } - printf(" %d keyed hash function%s:\n", keyedHashFunctionCount(), keyedHashFunctionCount() == 1 ? "" : "s"); - for (i = 0; i < keyedHashFunctionCount(); i++) - { - const keyedHashFunction* tmp = keyedHashFunctionGet(i); - if (tmp) - printf(" %s\n", tmp->name); - else - printf("*** error: library corrupt\n"); - } - printf(" %d blockcipher%s:\n", blockCipherCount(), blockCipherCount() == 1 ? "" : "s"); - for (i = 0; i < blockCipherCount(); i++) - { - const blockCipher* tmp = blockCipherGet(i); - if (tmp) - { - printf(" %s ", tmp->name); - for (j = tmp->keybitsmin; j <= tmp->keybitsmax; j += tmp->keybitsinc) - { - printf("%u", j); - if (j < tmp->keybitsmax) - printf("/"); - else - printf(" bit keys\n"); - } - } - else - printf("*** error: library corrupt\n"); - } - testBlockCiphers(); - testHashFunctions(); - testExpMods(); - testRSA(); - testDLAlgorithms(); - - printf("done\n"); - - return 0; -} -/*@=compdef@*/ diff --git a/beecrypt/tests/benchbc.c b/beecrypt/tests/benchbc.c index f99cfc1..f0191e1 100644 --- a/beecrypt/tests/benchbc.c +++ b/beecrypt/tests/benchbc.c @@ -22,10 +22,10 @@ * \author Bob Deblier */ -#include "system.h" #include "beecrypt.h" #include "timestamp.h" -#include "debug.h" + +#include #define SECONDS 10 diff --git a/beecrypt/tests/benchhf.c b/beecrypt/tests/benchhf.c index 479e13d..8a3fb76 100644 --- a/beecrypt/tests/benchhf.c +++ b/beecrypt/tests/benchhf.c @@ -22,10 +22,10 @@ * \author Bob Deblier */ -#include "system.h" #include "beecrypt.h" #include "timestamp.h" -#include "debug.h" + +#include #define SECONDS 10 diff --git a/beecrypt/tests/benchme.c b/beecrypt/tests/benchme.c index f42df0d..b32ed0c 100644 --- a/beecrypt/tests/benchme.c +++ b/beecrypt/tests/benchme.c @@ -22,11 +22,11 @@ * \author Bob Deblier */ -#include "system.h" #include "beecrypt.h" #include "dldp.h" #include "timestamp.h" -#include "debug.h" + +#include #define SECONDS 10 diff --git a/beecrypt/tests/openpgp.c b/beecrypt/tests/openpgp.c deleted file mode 100644 index 9339998..0000000 --- a/beecrypt/tests/openpgp.c +++ /dev/null @@ -1,741 +0,0 @@ -/** - * \file tests/openpgp.c - */ - -static int _debug = 0; - -#include "system.h" -#include "base64.h" -#include "debug.h" - -static inline int grab(const byte *s, int nbytes) -{ - int i = 0; - int nb = (nbytes <= sizeof(i) ? nbytes : sizeof(i)); - while (nb--) - i = (i << 8) | *s++; - return i; -} - -#define GRAB(_a) grab((_a), sizeof(_a)) - -typedef struct { - byte nbits[2]; - byte bits[1]; -} MPI_t; - -static inline int mpi_nbits(const byte *p) { return ((p[0] << 8) | p[1]); } -static inline int mpi_len(const byte *p) { return (2 + ((mpi_nbits(p)+7)>>3)); } - -static char * pr_pfmt(char *t, const byte *s, int nbytes) -{ - static char hex[] = "0123456789abcdef"; - while (nbytes-- > 0) { - *t++ = hex[ (*s >> 4) & 0xf ]; - *t++ = hex[ (*s++ ) & 0xf ]; - } - *t = '\0'; - return t; -} - -static char prbuf[2048]; - -static char * pr_hex(const byte *p, unsigned plen) -{ - char *t = prbuf; - - t = pr_pfmt(t, p, plen); - return prbuf; -} - -static const char * pr_mpi(const byte *p) -{ - char *t = prbuf; - - sprintf(t, "[%d]: ", grab(p,2)); - t += strlen(t); - t = pr_pfmt(t, p+2, mpi_len(p)-2); - return prbuf; -} - -static const char * pr_sigtype(byte sigtype) { - switch (sigtype) { - case 0x00: return("Signature of a binary document"); break; - case 0x01: return("Signature of a canonical text document"); break; - case 0x02: return("Standalone signature"); break; - case 0x10: return("Generic certification of a User ID and Public Key"); break; - case 0x11: return("Persona certification of a User ID and Public Key"); break; - case 0x12: return("Casual certification of a User ID and Public Key"); break; - case 0x13: return("Positive certification of a User ID and Public Key"); break; - case 0x18: return("Subkey Binding Signature"); break; - case 0x1F: return("Signature directly on a key"); break; - case 0x20: return("Key revocation signature"); break; - case 0x28: return("Subkey revocation signature"); break; - case 0x30: return("Certification revocation signature"); break; - case 0x40: return("Timestamp signature"); break; - } - return "Unknown signature type"; -} - -static const char * pr_pubkey_algo(byte pubkey_algo) { - switch (pubkey_algo) { - case 1: return("RSA"); break; - case 2: return("RSA(Encrypt-Only)"); break; - case 3 : return("RSA(Sign-Only)"); break; - case 16: return("Elgamal(Encrypt-Only)"); break; - case 17: return("DSA"); break; - case 18: return("Elliptic Curve"); break; - case 19: return("ECDSA"); break; - case 20: return("Elgamal"); break; - case 21: return("Diffie-Hellman (X9.42)"); break; - } - return "Unknown public key algorithm"; -} - -static const char * pr_symkey_algo(byte symkey_algo) { - switch (symkey_algo) { - case 0: return("Plaintext"); break; - case 1: return("IDEA"); break; - case 2: return("DES-EDE"); break; - case 3: return("CAST5"); break; - case 4: return("BLOWFISH"); break; - case 5: return("SAFER"); break; - case 10: return("TWOFISH"); break; - } - return "Unknown symmetric key algorithm"; -}; - -static const char * pr_compression_algo(byte compression_algo) { - switch (compression_algo) { - case 0: return("Uncompressed"); break; - case 1: return("ZIP"); break; - case 2: return("ZLIB"); break; - } - return "Unknown compression algorithm"; -}; - -static const char * pr_hash_algo(byte hash_algo) { - switch (hash_algo) { - case 1: return("MD5"); break; - case 2: return("SHA1"); break; - case 3: return("RIPEMD160"); break; - case 5: return("MD2"); break; - case 6: return("TIGER192"); break; - case 7: return("HAVAL-5-160"); break; - } - return "Unknown hash algorithm"; -} - -static const char * pr_keyserv_pref (byte keyserv_pref) { - switch(keyserv_pref) { - case 0x80: return("No-modify"); break; - } - return "Unknown key server preference"; -}; - -static const char * pr_sigsubkeytype (byte sigsubkeytype) { - switch(sigsubkeytype) { - case 2: return("signature creation time"); break; - case 3: return("signature expiration time"); break; - case 4: return("exportable certification"); break; - case 5: return("trust signature"); break; - case 6: return("regular expression"); break; - case 7: return("revocable"); break; - case 9: return("key expiration time"); break; - case 10: return("placeholder for backward compatibility"); break; - case 11: return("preferred symmetric algorithms"); break; - case 12: return("revocation key"); break; - case 16: return("issuer key ID"); break; - case 20: return("notation data"); break; - case 21: return("preferred hash algorithms"); break; - case 22: return("preferred compression algorithms"); break; - case 23: return("key server preferences"); break; - case 24: return("preferred key server"); break; - case 25: return("primary user id"); break; - case 26: return("policy URL"); break; - case 27: return("key flags"); break; - case 28: return("signer's user id"); break; - case 29: return("reason for revocation"); break; - } - return "Unknown signature subkey type"; -} - -const char *ptags[] = { - "Reserved - a packet tag must not have this value", - "Public-Key Encrypted Session Key", - "Signature", - "Symmetric-Key Encrypted Session Key", - "One-Pass Signature", - "Secret Key", - "Public Key", - "Secret Subkey", - "Compressed Data", - "Symmetrically Encrypted Data", - "Marker", - "Literal Data", - "Trust", - "User ID", - "Public Subkey", - "??? TAG15 ???", -}; - -typedef enum { - RPMKEYPKT_SIGNATURE = 2, - RPMKEYPKT_SECRET_KEY = 5, - RPMKEYPKT_PUBLIC_KEY = 6, - RPMKEYPKT_SECRET_SUBKEY = 7, - RPMKEYPKT_USER_ID = 13, - RPMKEYPKT_PUBLIC_SUBKEY = 14 -} rpmKeyPkt; - -/* -5.2.2. Version 3 Signature Packet Format - The body of a version 3 Signature Packet contains: - - One-octet version number (3). - - One-octet length of following hashed material. MUST be 5. - - One-octet signature type. - - Four-octet creation time. - - Eight-octet key ID of signer. - - One-octet public key algorithm. - - One-octet hash algorithm. - - Two-octet field holding left 16 bits of signed hash value. - - One or more multi-precision integers comprising the signature. - This portion is algorithm specific, as described below. -*/ - -struct signature_v3 { - byte version; /*!< version number (3). */ - byte hashlen; /*!< length of following hashed material. MUST be 5. */ - byte sigtype; /*!< signature type. */ - byte time[4]; /*!< 4 byte creation time. */ - byte signer[8]; /*!< key ID of signer. */ - byte pubkey_algo; /*!< public key algorithm. */ - byte hash_algo; /*!< hash algorithm. */ - byte signhash16[2]; /*!< left 16 bits of signed hash value. */ - byte data[1]; /*!< One or more multi-precision integers. */ -}; - -static int pr_signature_v3(rpmKeyPkt ptag, const byte *h, unsigned hlen) -{ - struct signature_v3 *v = (struct signature_v3 *)h; - byte *p; - unsigned plen; - int i; - -fprintf(stderr, "%s(%d)", ptags[ptag], ptag); - if (v->version != 3) { - fprintf(stderr, " version(%d) != 3\n", v->version); - return 1; - } - if (v->hashlen != 5) { - fprintf(stderr, " hashlen(%d) != 5\n", v->hashlen); - return 1; - } -fprintf(stderr, " %s(%d)", pr_pubkey_algo(v->pubkey_algo), v->pubkey_algo); -fprintf(stderr, " %s(%d)", pr_hash_algo(v->hash_algo), v->hash_algo); - -fprintf(stderr, " %s(%d)", pr_sigtype(v->sigtype), v->sigtype); - - plen = GRAB(v->time); -fprintf(stderr, " time %08x", plen); -fprintf(stderr, " signer keyid %02x%02x%02x%02x%02x%02x%02x%02x", - v->signer[0], v->signer[1], v->signer[2], v->signer[3], - v->signer[4], v->signer[5], v->signer[6], v->signer[7]); - plen = GRAB(v->signhash16); -fprintf(stderr, " signhash16 %04x", plen); -fprintf(stderr, "\n"); - - p = &v->data[0]; - for (i = 0; p < &h[hlen]; i++, p += mpi_len(p)) - fprintf(stderr, "%7d %s\n", i, pr_mpi(p)); - - return 0; -} - -/* -5.2.3.1. Signature Subpacket Specification - - The subpacket fields consist of zero or more signature subpackets. - Each set of subpackets is preceded by a two-octet scalar count of the - length of the set of subpackets. - - Each subpacket consists of a subpacket header and a body. The header - consists of: - - - the subpacket length (1, 2, or 5 octets) - - - the subpacket type (1 octet) - - and is followed by the subpacket specific data. - - The length includes the type octet but not this length. Its format is - similar to the "new" format packet header lengths, but cannot have - partial body lengths. That is: - - if the 1st octet < 192, then - lengthOfLength = 1 - subpacketLen = 1st_octet - - if the 1st octet >= 192 and < 255, then - lengthOfLength = 2 - subpacketLen = ((1st_octet - 192) << 8) + (2nd_octet) + 192 - - if the 1st octet = 255, then - lengthOfLength = 5 - subpacket length = [four-octet scalar starting at 2nd_octet] - -*/ - -static int pr_sigsubkeys(const byte *h, unsigned hlen) -{ - const byte *p = h; - unsigned plen; - int i; - - while (hlen > 0) { - if (*p < 192) { - plen = *p++; - hlen -= 1; - } else if (*p < 255) { - plen = ((p[0] - 192) << 8) + p[1] + 192; - p += 2; - hlen -= 2; - } else { - p++; - plen = grab(p, 4); - p += 4; - hlen -= 5; - } -fprintf(stderr, " %s(%d)", pr_sigsubkeytype(*p), *p); - switch (*p) { - case 11: /* preferred symmetric algorithms */ - for (i = 1; i < plen; i++) - fprintf(stderr, " %s(%d)", pr_symkey_algo(p[i]), p[i]); - fprintf(stderr, "\n"); - break; - case 21: /* preferred hash algorithms */ - for (i = 1; i < plen; i++) - fprintf(stderr, " %s(%d)", pr_hash_algo(p[i]), p[i]); - fprintf(stderr, "\n"); - break; - case 22: /* preferred compression algorithms */ - for (i = 1; i < plen; i++) - fprintf(stderr, " %s(%d)", pr_compression_algo(p[i]), p[i]); - fprintf(stderr, "\n"); - break; - case 23: /* key server preferences */ - for (i = 1; i < plen; i++) - fprintf(stderr, " %s(%d)", pr_keyserv_pref(p[i]), p[i]); - fprintf(stderr, "\n"); - break; - case 16: /* issuer key ID */ - default: - fprintf(stderr, " %s", pr_hex(p+1, plen-1)); - fprintf(stderr, "\n"); - break; - } - p += plen; - hlen -= plen; - } - return 0; -} - -/* -5.2.3. Version 4 Signature Packet Format - The body of a version 4 Signature Packet contains: - - One-octet version number (4). - - One-octet signature type. - - One-octet public key algorithm. - - One-octet hash algorithm. - - Two-octet scalar octet count for following hashed subpacket - data. Note that this is the length in octets of all of the hashed - subpackets; a pointer incremented by this number will skip over - the hashed subpackets. - - Hashed subpacket data. (zero or more subpackets) - - Two-octet scalar octet count for following unhashed subpacket - data. Note that this is the length in octets of all of the - unhashed subpackets; a pointer incremented by this number will - skip over the unhashed subpackets. - - Unhashed subpacket data. (zero or more subpackets) - - Two-octet field holding left 16 bits of signed hash value. - - One or more multi-precision integers comprising the signature. - This portion is algorithm specific, as described above. -*/ - -struct signature_v4 { - byte version; /*!< version number (4). */ - byte sigtype; /*!< signature type. */ - byte pubkey_algo; /*!< public key algorithm. */ - byte hash_algo; /*!< hash algorithm. */ - byte hashlen[2]; /*!< length of following hashed material. */ - byte data[1]; /*!< Hashed subpacket data. (zero or more subpackets) */ -}; - -static int pr_signature_v4(rpmKeyPkt ptag, const byte *h, unsigned hlen) -{ - struct signature_v4 *v = (struct signature_v4 *)h; - byte * p; - unsigned plen; - int i; - -fprintf(stderr, "%s(%d)", ptags[ptag], ptag); - if (v->version != 4) { - fprintf(stderr, " version(%d) != 4\n", v->version); - return 1; - } -fprintf(stderr, " %s(%d)", pr_pubkey_algo(v->pubkey_algo), v->pubkey_algo); -fprintf(stderr, " %s(%d)", pr_hash_algo(v->hash_algo), v->hash_algo); - -fprintf(stderr, " %s(%d)", pr_sigtype(v->sigtype), v->sigtype); -fprintf(stderr, "\n"); - - p = &v->hashlen[0]; - plen = GRAB(v->hashlen); - p += 2; -fprintf(stderr, " hash[%d] -- %s\n", plen, pr_hex(p, plen)); - pr_sigsubkeys(p, plen); - p += plen; - plen = grab(p,2); - p += 2; -fprintf(stderr, " unhash[%d] -- %s\n", plen, pr_hex(p, plen)); - pr_sigsubkeys(p, plen); - p += plen; - plen = grab(p,2); - p += 2; -fprintf(stderr, " signhash16 %04x\n", plen); - - for (i = 0; p < &h[hlen]; i++, p += mpi_len(p)) - fprintf(stderr, "%7d %s\n", i, pr_mpi(p)); - - return 0; -} - -static int pr_signature(rpmKeyPkt ptag, const byte *h, unsigned hlen) -{ - byte version = *h; - switch (version) { - case 3: - pr_signature_v3(ptag, h, hlen); - break; - case 4: - pr_signature_v4(ptag, h, hlen); - break; - } - return 0; -} - -/* - A version 3 public key or public subkey packet contains: - - A one-octet version number (3). - - A four-octet number denoting the time that the key was created. - - A two-octet number denoting the time in days that this key is - valid. If this number is zero, then it does not expire. - - A one-octet number denoting the public key algorithm of this key - - A series of multi-precision integers comprising the key - material: - - MPI of RSA public modulus n; - - MPI of RSA public encryption exponent e. - - Algorithm Specific Fields for RSA signatures: - - multiprecision integer (MPI) of RSA signature value m**d. - - Algorithm Specific Fields for DSA signatures: - - MPI of DSA value r. - - MPI of DSA value s. - -*/ - -struct key_v3 { - byte version; /*!< version number (3). */ - byte time[4]; /*!< time that the key was created. */ - byte valid[2]; /*!< time in days that this key is valid. */ - byte pubkey_algo; /*!< public key algorithm. */ - byte data[1]; /*!< One or more multi-precision integers. */ -}; - -static int pr_key_v3(rpmKeyPkt ptag, const byte *h, unsigned hlen) -{ - struct key_v3 *v = (struct key_v3 *)h; - byte * p; - unsigned plen; - int i; - -fprintf(stderr, "%s(%d)", ptags[ptag], ptag); - if (v->version != 3) { - fprintf(stderr, " version(%d) != 3\n", v->version); - return 1; - } - plen = GRAB(v->time); -fprintf(stderr, " time %08x", plen); -fprintf(stderr, " %s(%d)", pr_pubkey_algo(v->pubkey_algo), v->pubkey_algo); - - plen = GRAB(v->valid); - if (plen != 0) - fprintf(stderr, " valid %d days", plen); - -fprintf(stderr, "\n"); - - p = &v->data[0]; - for (i = 0; p < &h[hlen]; i++, p += mpi_len(p)) - fprintf(stderr, "%7d %s\n", i, pr_mpi(p)); - - return 0; -} - -/* - A version 4 packet contains: - - A one-octet version number (4). - - A four-octet number denoting the time that the key was created. - - A one-octet number denoting the public key algorithm of this key - - A series of multi-precision integers comprising the key - material. This algorithm-specific portion is: - - Algorithm Specific Fields for RSA public keys: - - MPI of RSA public modulus n; - - MPI of RSA public encryption exponent e. - - Algorithm Specific Fields for DSA public keys: - - MPI of DSA prime p; - - MPI of DSA group order q (q is a prime divisor of p-1); - - MPI of DSA group generator g; - - MPI of DSA public key value y (= g**x where x is secret). - - Algorithm Specific Fields for Elgamal public keys: - - MPI of Elgamal prime p; - - MPI of Elgamal group generator g; - - MPI of Elgamal public key value y (= g**x where x is - secret). -*/ - -struct key_v4 { - byte version; /*!< version number (4). */ - byte time[4]; /*!< time that the key was created. */ - byte pubkey_algo; /*!< public key algorithm. */ - byte data[1]; /*!< One or more multi-precision integers. */ -}; - -static int pr_key_v4(rpmKeyPkt ptag, const byte *h, unsigned hlen) -{ - struct key_v4 *v = (struct key_v4 *)h; - byte * p; - unsigned plen; - int i; - -fprintf(stderr, "%s(%d)", ptags[ptag], ptag); - if (v->version != 4) { - fprintf(stderr, " version(%d) != 4\n", v->version); - return 1; - } - plen = GRAB(v->time); -fprintf(stderr, " time %08x", plen); -fprintf(stderr, " %s(%d)", pr_pubkey_algo(v->pubkey_algo), v->pubkey_algo); -fprintf(stderr, "\n"); - - p = &v->data[0]; - for (i = 0; p < &h[hlen]; i++, p += mpi_len(p)) - fprintf(stderr, "%7d %s\n", i, pr_mpi(p)); - - return 0; -} - -static int pr_key(rpmKeyPkt ptag, const byte *h, unsigned hlen) -{ - byte version = *h; - switch (version) { - case 3: - pr_key_v3(ptag, h, hlen); - break; - case 4: - pr_key_v4(ptag, h, hlen); - break; - } - return 0; -} - -/* -5.11. User ID Packet (Tag 13) - - A User ID packet consists of data that is intended to represent the - name and email address of the key holder. By convention, it includes - an RFC 822 mail name, but there are no restrictions on its content. - The packet length in the header specifies the length of the user id. - If it is text, it is encoded in UTF-8. -*/ - -static int pr_user_id(rpmKeyPkt ptag, const byte *h, unsigned hlen) -{ -fprintf(stderr, "%s(%d)", ptags[ptag], ptag); -fprintf(stderr, " \"%*s\"\n", hlen, h); - return 0; -} - -static int pr_keypkt(const byte *p) -{ - unsigned int val = *p; - unsigned int mark = (val >> 7) & 0x1; - unsigned int new = (val >> 6) & 0x1; - rpmKeyPkt ptag = (val >> 2) & 0xf; - unsigned int plen = (1 << (val & 0x3)); - const byte *h; - unsigned int hlen = 0; - unsigned int i; - - /* XXX can't deal with these. */ - if (!mark || new || plen > 8) - return -1; - - for (i = 1; i <= plen; i++) - hlen = (hlen << 8) | p[i]; - - h = p + plen + 1; - switch (ptag) { - case RPMKEYPKT_SIGNATURE: - pr_signature(ptag, h, hlen); - break; - case RPMKEYPKT_PUBLIC_KEY: - case RPMKEYPKT_PUBLIC_SUBKEY: - case RPMKEYPKT_SECRET_KEY: - case RPMKEYPKT_SECRET_SUBKEY: - pr_key(ptag, h, hlen); - break; - case RPMKEYPKT_USER_ID: - pr_user_id(ptag, h, hlen); - break; - default: - fprintf(stderr, "%s(%d) plen %02x hlen %x\n", - ptags[ptag], ptag, plen, hlen); - break; - } - - return plen+hlen+1; -} - -/* This is the unarmored RPM-GPG-KEY public key. */ -const char * gpgsig = "\ -mQGiBDfqVDgRBADBKr3Bl6PO8BQ0H8sJoD6p9U7Yyl7pjtZqioviPwXP+DCWd4u8\n\ -HQzcxAZ57m8ssA1LK1Fx93coJhDzM130+p5BG9mYSWShLabR3N1KXdXQYYcowTOM\n\ -GxdwYRGr1Spw8QydLhjVfU1VSl4xt6bupPbWJbyjkg5Z3P7BlUOUJmrx3wCgobNV\n\ -EDGaWYJcch5z5B1of/41G8kEAKii6q7Gu/vhXXnLS6m15oNnPVybyngiw/23dKjS\n\ -ZVG7rKANEK2mxg1VB+vc/uUc4k49UxJJfCZg1gu1sPFV3GSa+Y/7jsiLktQvCiLP\n\ -lncQt1dV+ENmHR5BdIDPWDzKBVbgWnSDnqQ6KrZ7T6AlZ74VMpjGxxkWU6vV2xsW\n\ -XCLPA/9P/vtImA8CZN3jxGgtK5GGtDNJ/cMhhuv5tnfwFg4b/VGo2Jr8mhLUqoIb\n\ -E6zeGAmZbUpdckDco8D5fiFmqTf5+++pCEpJLJkkzel/32N2w4qzPrcRMCiBURES\n\ -PjCLd4Y5rPoU8E4kOHc/4BuHN903tiCsCPloCrWsQZ7UdxfQ5LQiUmVkIEhhdCwg\n\ -SW5jIDxzZWN1cml0eUByZWRoYXQuY29tPohVBBMRAgAVBQI36lQ4AwsKAwMVAwID\n\ -FgIBAheAAAoJECGRgM3bQqYOsBQAnRVtg7B25Hm11PHcpa8FpeddKiq2AJ9aO8sB\n\ -XmLDmPOEFI75mpTrKYHF6rkCDQQ36lRyEAgAokgI2xJ+3bZsk8jRA8ORIX8DH05U\n\ -lMH27qFYzLbT6npXwXYIOtVn0K2/iMDj+oEB1Aa2au4OnddYaLWp06v3d+XyS0t+\n\ -5ab2ZfIQzdh7wCwxqRkzR+/H5TLYbMG+hvtTdylfqIX0WEfoOXMtWEGSVwyUsnM3\n\ -Jy3LOi48rQQSCKtCAUdV20FoIGWhwnb/gHU1BnmES6UdQujFBE6EANqPhp0coYoI\n\ -hHJ2oIO8ujQItvvNaU88j/s/izQv5e7MXOgVSjKe/WX3s2JtB/tW7utpy12wh1J+\n\ -JsFdbLV/t8CozUTpJgx5mVA3RKlxjTA+On+1IEUWioB+iVfT7Ov/0kcAzwADBQf9\n\ -E4SKCWRand8K0XloMYgmipxMhJNnWDMLkokvbMNTUoNpSfRoQJ9EheXDxwMpTPwK\n\ -ti/PYrrL2J11P2ed0x7zm8v3gLrY0cue1iSba+8glY+p31ZPOr5ogaJw7ZARgoS8\n\ -BwjyRymXQp+8Dete0TELKOL2/itDOPGHW07SsVWOR6cmX4VlRRcWB5KejaNvdrE5\n\ -4XFtOd04NMgWI63uqZc4zkRa+kwEZtmbz3tHSdRCCE+Y7YVP6IUf/w6YPQFQriWY\n\ -FiA6fD10eB+BlIUqIw80VgjsBKmCwvKkn4jg8kibXgj4/TzQSx77uYokw1EqQ2wk\n\ -OZoaEtcubsNMquuLCMWijYhGBBgRAgAGBQI36lRyAAoJECGRgM3bQqYOhyYAnj7h\n\ -VDY/FJAGqmtZpwVp9IlitW5tAJ4xQApr/jNFZCTksnI+4O1765F7tA==\n\ -"; - -/* This is the unarmored RPM-PGP-KEY public key. */ -const char * pgpsig = "\ -mQCNAzEpXjUAAAEEAKG4/V9oUSiDc9wIge6Bmg6erDGCLzmFyioAho8kDIJSrcmi\n\ -F9qTdPq+fj726pgW1iSb0Y7syZn9Y2lgQm5HkPODfNi8eWyTFSxbr8ygosLRClTP\n\ -xqHVhtInGrfZNLoSpv1LdWOme0yOpOQJnghdOMzKXpgf5g84vaUg6PHLopv5AAUR\n\ -tCpSZWQgSGF0IFNvZnR3YXJlLCBJbmMuIDxyZWRoYXRAcmVkaGF0LmNvbT6JAJUD\n\ -BRAyA5tUoyDApfg4JKEBAUzSA/9QdcVsu955vVyZDk8uvOXWV0X3voT9B3aYMFvj\n\ -UNHUD6F1VFruwQHVKbGJEq1o5MOA6OXKR3vJZStXEMF47TWXJfQaflgl8ywZTH5W\n\ -+eMlKau6Nr0labUV3lmsAE4Vsgu8NCkzIrp2wNVbeW2ZAXtrKswV+refLquUhp7l\n\ -wMpH9IkAdQMFEDGttkRNdXhbO1TgGQEBAGoC/j6C22PqXIyqZc6fG6J6Jl/T5kFG\n\ -xH1pKIzua5WCDDugAgnuOJgywa4pegT4UqwEZiMTAlwT6dmG1CXgKB+5V7lnCjDc\n\ -JZLni0iztoe08ig6fJrjNGXljf7KYXzgwBftQokAlQMFEDMQzo2MRVM9rfPulQEB\n\ -pLoD/1/MWv3u0Paiu14XRvDrBaJ7BmG2/48bA5vKOzpvvoNRO95YS7ZEtqErXA7Y\n\ -DRO8+C8f6PAILMk7kCk4lNMscS/ZRzu5+J8cv4ejsFvxgJBBU3Zgp8AWdWOpvZ0I\n\ -wW//HoDUGhOxlEtymljIMFBkj4SysHWhCBUfA9Xy86kouTJQiQCVAwUQMxDOQ50a\n\ -feTWLUSJAQFnYQQAkt9nhMTeioREB1DvJt+vsFyOj//o3ThqK5ySEP3dgj62iaQp\n\ -JrBmAe5XZPw25C/TXAf+x27H8h2QbKgq49VtsElFexc6wO+uq85fAPDdyE+2XyNE\n\ -njGZkY/TP2F/jTB0sAwJO+xFCHmSYkcBjzxK/2LMD+O7rwp2UCUhhl9QhhqJAJUD\n\ -BRAx5na6pSDo8cuim/kBARmjA/4lDVnV2h9KiNabp9oE38wmGgu5m5XgUHW8L6du\n\ -iQDnwO5IgXN2vDpKGxbgtwv6iYYmGd8IRQ66uJvOsxSv3OR7J7LkCHuI2b/s0AZn\n\ -c79DZaJ2ChUCZlbNQBMeEdrFWif9NopY+d5+2tby1onu9XOFMMvomxL3NhctElYR\n\ -HC8Xw4kAlQMFEDHmdTtURTdEKY1MpQEBEtEEAMZbp1ZFrjiHkj2aLFC1S8dGRbSH\n\ -GUdnLP9qLPFgmWekp9E0o8ZztALGVdqPfPF3N/JJ+AL4IMrfojd7+eZKw36Mdvtg\n\ -dPI+Oz4sxHDbDynZ2qspD9Om5yYuxuz/Xq+9nO2IlsAnEYw3ag3cxat0kvxpOPRe\n\ -Yy+vFpgfDNizr3MgiQBVAwUQMXNMXCjtrosVMemRAQEDnwH7BsJrnnh91nI54LAK\n\ -Gcq3pr8ld0PAtWJmNRGQvUlpEMXUSnu59j2P1ogPNjL3PqKdVxk5Jqgcr8TPQMf3\n\ -V4fqXokAlQMFEDFy+8YiEmsRQ3LyzQEB+TwD/03QDslXLg5F3zj4zf0yI6ikT0be\n\ -5OhZv2pnkb80qgdHzFRxBOYmSoueRKdQJASd8F9ue4b3bmf/Y7ikiY0DblvxcXB2\n\ -sz1Pu8i2Zn9u8SKuxNIoVvM8/STRVkgPfvL5QjAWMHT9Wvg81XcI2yXJzrt/2f2g\n\ -mNpWIvVOOT85rVPIiQCVAwUQMVPRlBlzviMjNHElAQG1nwP/fpVX6nKRWJCSFeB7\n\ -leZ4lb+y1uMsMVv0n7agjJVw13SXaA267y7VWCBlnhsCemxEugqEIkI4lu/1mgtw\n\ -WPWSE0BOIVjj0AA8zp2T0H3ZCCMbiFAFJ1P2Gq2rKr8QrOb/08oH1lEzyz0j/jKh\n\ -qiXAxdlB1wojQB6yLbHvTIe3rZGJAHUDBRAxKetfzauiKSJ6LJEBAed/AvsEiGgj\n\ -TQzhsZcUuRNrQpV0cDGH9Mpril7P7K7yFIzju8biB+Cu6nEknSOHlMLl8usObVlk\n\ -d8Wf14soHC7SjItiGSKtI8JhauzBJPl6fDDeyHGsJKo9f9adKeBMCipCFOuJAJUD\n\ -BRAxKeqWRHFTaIK/x+0BAY6eA/4m5X4gs1UwOUIRnljo9a0cVs6ITL554J9vSCYH\n\ -Zzd87kFwdf5W1Vd82HIkRzcr6cp33E3IDkRzaQCMVw2me7HePP7+4Ry2q3EeZMbm\n\ -NE++VzkxjikzpRb2+F5nGB2UdsElkgbXinswebiuOwOrocLbz6JFdDsJPcT5gVfi\n\ -z15FuA==\n\ -"; - -static int doit(const char *sig) -{ - const char *s, *t; - unsigned char * dec; - unsigned char * d; - size_t declen; - char * enc; - int rc; - int len = 0; - int i; - -if (_debug) -fprintf(stderr, "*** sig is\n%s\n", sig); - - if ((rc = b64decode(sig, (void **)&dec, &declen)) != 0) { - fprintf(stderr, "*** B64decode returns %d\n", rc); - exit(rc); - } - - for (d = dec; d < (dec + declen); d += len) { - len = pr_keypkt(d); - if (len <= 0) - exit(len); - } - - if ((enc = b64encode(dec, declen)) == NULL) { - fprintf(stderr, "*** B64encode returns %d\n", rc); - exit(4); - } - -if (_debug) -fprintf(stderr, "*** enc is\n%s\n", enc); - -rc = 0; -for (i = 0, s = sig, t = enc; *s & *t; i++, s++, t++) { - if (*s == '\n') s++; - if (*t == '\n') t++; - if (*s == *t) continue; -fprintf(stderr, "??? %5d %02x != %02x '%c' != '%c'\n", i, (*s & 0xff), (*t & 0xff), *s, *t); - rc = 5; -} - - return rc; -} - -int -main (int argc, char *argv[]) -{ - int rc; - -fprintf(stderr, "============================================== RPM-GPG-KEY\n"); - if ((rc = doit(gpgsig)) != 0) - return rc; - -fprintf(stderr, "============================================== RPM-PGP-KEY\n"); - if ((rc = doit(pgpsig)) != 0) - return rc; - - return rc; -} diff --git a/beecrypt/tests/testaes.c b/beecrypt/tests/testaes.c index 41dcdbf..04b706b 100644 --- a/beecrypt/tests/testaes.c +++ b/beecrypt/tests/testaes.c @@ -23,13 +23,10 @@ * \ingroup UNIT_m */ -#include "system.h" +#include -#include "beecrypt.h" #include "aes.h" -#include "debug.h" - extern int fromhex(byte*, const char*); struct vector diff --git a/beecrypt/tests/testblowfish.c b/beecrypt/tests/testblowfish.c index d806d19..f5bc73d 100644 --- a/beecrypt/tests/testblowfish.c +++ b/beecrypt/tests/testblowfish.c @@ -23,12 +23,10 @@ * \ingroup UNIT_m */ -#include "system.h" +#include #include "blowfish.h" -#include "debug.h" - extern int fromhex(byte*, const char*); struct vector @@ -82,9 +80,6 @@ int main() switch (table[i].op) { - case NOCRYPT: - return -1; - break; case ENCRYPT: if (blowfishEncrypt(¶m, (uint32_t*) dst, (const uint32_t*) src)) return -1; diff --git a/beecrypt/tests/testconv.c b/beecrypt/tests/testconv.c new file mode 100644 index 0000000..c8f8914 --- /dev/null +++ b/beecrypt/tests/testconv.c @@ -0,0 +1,35 @@ +#include "mp.h" + +void hexdump(byte* b, int count) +{ + int i; + + for (i = 0; i < count; i++) + { + printf("%02x", b[i]); + if ((i & 0xf) == 0xf) + printf("\n"); + } + if (i & 0xf) + printf("\n"); +} + +int main() +{ + int rc; + mpw x[4]; + byte o[9]; + + mpsetw(4, x, 255); + mpmultwo(4, x); + rc = i2osp(o, 9, x, 4); + + printf("rc = %d\n", rc); + hexdump(o, 9); + + rc = os2ip(x, 4, o, 9); + printf("rc = %d\n", rc); + mpprintln(4, x); + + exit(0); +} diff --git a/beecrypt/tests/testdldp.c b/beecrypt/tests/testdldp.c index 8afb23f..1fce545 100644 --- a/beecrypt/tests/testdldp.c +++ b/beecrypt/tests/testdldp.c @@ -23,10 +23,10 @@ * \ingroup UNIT_m */ -#include "system.h" +#include + #include "beecrypt.h" #include "dldp.h" -#include "debug.h" int main() { @@ -57,7 +57,7 @@ int main() mpnfree(&gq); dldp_pFree(¶ms); - + randomGeneratorContextFree(&rngc); } else diff --git a/beecrypt/tests/testdsa.c b/beecrypt/tests/testdsa.c index c252ad8..b8f9045 100644 --- a/beecrypt/tests/testdsa.c +++ b/beecrypt/tests/testdsa.c @@ -23,65 +23,84 @@ * \ingroup UNIT_m */ -#include "system.h" +#include + #include "beecrypt.h" #include "dlkp.h" #include "dsa.h" -#include "debug.h" - -static const char* dsa_p = "8df2a494492276aa3d25759bb06869cbeac0d83afb8d0cf7cbb8324f0d7882e5d0762fc5b7210eafc2e9adac32ab7aac49693dfbf83724c2ec0736ee31c80291"; -static const char* dsa_q = "c773218c737ec8ee993b4f2ded30f48edace915f"; -static const char* dsa_g = "626d027839ea0a13413163a55b4cb500299d5522956cefcb3bff10f399ce2c2e71cb9de5fa24babf58e5b79521925c9cc42e9f6f464b088cc572af53e6d78802"; -static const char* dsa_x = "2070b3223dba372fde1c0ffc7b2e3b498b260614"; -static const char* dsa_y = "19131871d75b1612a819f29d78d1b0d7346f7aa77bb62a859bfd6c5675da9d212d3a36ef1672ef660b8c7c255cc0ec74858fba33f44c06699630a76b030ee333"; - -static const char* dsa_k = "358dad571462710f50e254cf1a376b2bdeaadfbf"; -static const char* dsa_hm = "a9993e364706816aba3e25717850c26c9cd0d89d"; - -static const char* expect_r = "8bac1ab66410435cb7181f95b16ab97c92b341c0"; -static const char* expect_s = "41e2345f1f56df2458f426d155b4ba2db6dcd8c8"; +struct vector +{ + const char* p; + const char* q; + const char* g; + const char* y; + const char* m; + const char* r; + const char* s; +}; + +#define NVECTORS 2 + +struct vector table[NVECTORS] = { + { "8df2a494492276aa3d25759bb06869cbeac0d83afb8d0cf7cbb8324f0d7882e5d0762fc5b7210eafc2e9adac32ab7aac49693dfbf83724c2ec0736ee31c80291", + "c773218c737ec8ee993b4f2ded30f48edace915f", + "626d027839ea0a13413163a55b4cb500299d5522956cefcb3bff10f399ce2c2e71cb9de5fa24babf58e5b79521925c9cc42e9f6f464b088cc572af53e6d78802", + "19131871d75b1612a819f29d78d1b0d7346f7aa77bb62a859bfd6c5675da9d212d3a36ef1672ef660b8c7c255cc0ec74858fba33f44c06699630a76b030ee333", + "a9993e364706816aba3e25717850c26c9cd0d89d", + "8bac1ab66410435cb7181f95b16ab97c92b341c0", + "41e2345f1f56df2458f426d155b4ba2db6dcd8c8" }, + { "A62927E72F9F12CD31C50E30D0E9B580539C4F7CA2AC3E2EE244C834303B039A1A388FDE4DCD42B5402807047FBEC0DB09ECF897CD2B8546A893499B3A8A409C52476708EAD0124E43F31CA2495A950731D254F56F4F39AC379E0620E15A9CC5A8EA5100CD1137012093E11F73A1E38FAEB95588BB54A48913977D1A1EC6986F", + "C4243BE451ECBA6F87F539A7F899D4047208B091", + "9C8D21312FD7358D86D82E8F237E99A9DFC375529456420F159361C40A76A891DA8D6CEE8EB1BDEC97CA60CCBE921BED5EB29EC35A2EFCA295311585753EFABBADF599620EA0FB8489FBEE60EDE6D5A99DD3506F37CC21741D306BEE15BBB8EAA1261C2DC18221FB5C6A08602B3E1084029285DF161A2CB6B179830C31C351A3", + "7602862B1A4F6F154BE21AFD86CF2AADD6393AE0EBBB5781CB82758C9A360A540BBCC3CBBF014509FD0ED2FC30C6ED0959C43954CF058854B8469DD4247AC463D4C10B6479C8B4FBE56E97067A7FC4E7F1A95507A0B6D70328534C37B590DB8ED12BB460FC3232758F9B64D7BD63BD320FF1FA635A3F77D13D71A8AD4E8B5469", + "73F6679451E5F98CA60235E6B4C58FC14043C56D", + "22EDDAD362C3209DF597070D144E8FDDB8B65E53", + "3AB093E7A7CD30125036B384C6C114317F10E10D" } +}; int main() { - int failures = 0; + int i, failures = 0; dlkp_p keypair; mpnumber hm, r, s, k, e_r, e_s; - dlkp_pInit(&keypair); + for (i = 0; i < NVECTORS; i++) + { + dlkp_pInit(&keypair); - mpbsethex(&keypair.param.p, dsa_p); - mpbsethex(&keypair.param.q, dsa_q); - mpnsethex(&keypair.param.g, dsa_g); - mpnsethex(&keypair.y, dsa_y); - mpnsethex(&keypair.x, dsa_x); + mpbsethex(&keypair.param.p, table[i].p); + mpbsethex(&keypair.param.q, table[i].q); + mpnsethex(&keypair.param.g, table[i].g); + mpnsethex(&keypair.y, table[i].y); - mpnzero(&e_r); - mpnzero(&e_s); + mpnzero(&hm); + mpnsethex(&hm, table[i].m); - mpnsethex(&e_r, expect_r); - mpnsethex(&e_s, expect_s); + mpnzero(&e_r); + mpnzero(&e_s); - mpnzero(&hm); - mpnsethex(&hm, dsa_hm); + mpnsethex(&e_r, table[i].r); + mpnsethex(&e_s, table[i].s); - mpnzero(&r); - mpnzero(&s); + mpnzero(&r); + mpnzero(&s); - /* first test, verify the signature result from NIST FIPS 186-1 */ - if (!dsavrfy(&keypair.param.p, &keypair.param.q, &keypair.param.g, &hm, &keypair.y, &e_r, &e_s)) - failures++; + /* first test, verify the signature result from NIST FIPS 186-1 */ + if (!dsavrfy(&keypair.param.p, &keypair.param.q, &keypair.param.g, &hm, &keypair.y, &e_r, &e_s)) + failures++; - mpnfree(&s); - mpnfree(&r); + mpnfree(&s); + mpnfree(&r); - mpnfree(&hm); + mpnfree(&hm); - mpnfree(&e_s); - mpnfree(&e_r); + mpnfree(&e_s); + mpnfree(&e_r); - dlkp_pFree(&keypair); + dlkp_pFree(&keypair); + } return failures; } diff --git a/beecrypt/tests/testhmacmd5.c b/beecrypt/tests/testhmacmd5.c index 8c17b16..3b2d0a0 100644 --- a/beecrypt/tests/testhmacmd5.c +++ b/beecrypt/tests/testhmacmd5.c @@ -24,9 +24,9 @@ * \ingroup UNIT_m */ -#include "system.h" +#include + #include "hmacmd5.h" -#include "debug.h" struct vector { @@ -40,40 +40,40 @@ struct vector struct vector table[7] = { { 128, - "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b", + (byte*) "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b", 8, - "Hi There", - "\x92\x94\x72\x7a\x36\x38\xbb\x1c\x13\xf4\x8e\xf8\x15\x8b\xfc\x9d" }, + (byte*) "Hi There", + (byte*) "\x92\x94\x72\x7a\x36\x38\xbb\x1c\x13\xf4\x8e\xf8\x15\x8b\xfc\x9d" }, { 32, - "Jefe", + (byte*) "Jefe", 28, - "what do ya want for nothing?", - "\x75\x0c\x78\x3e\x6a\xb0\xb5\x03\xea\xa8\x6e\x31\x0a\x5d\xb7\x38" }, + (byte*) "what do ya want for nothing?", + (byte*) "\x75\x0c\x78\x3e\x6a\xb0\xb5\x03\xea\xa8\x6e\x31\x0a\x5d\xb7\x38" }, { 128, - "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", + (byte*) "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 50, - "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd", - "\x56\xbe\x34\x52\x1d\x14\x4c\x88\xdb\xb8\xc7\x33\xf0\xe8\xb3\xf6" }, + (byte*) "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd", + (byte*) "\x56\xbe\x34\x52\x1d\x14\x4c\x88\xdb\xb8\xc7\x33\xf0\xe8\xb3\xf6" }, { 200, - "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19", + (byte*) "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19", 50, - "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd", - "\x69\x7e\xaf\x0a\xca\x3a\x3a\xea\x3a\x75\x16\x47\x46\xff\xaa\x79" }, + (byte*) "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd", + (byte*) "\x69\x7e\xaf\x0a\xca\x3a\x3a\xea\x3a\x75\x16\x47\x46\xff\xaa\x79" }, { 128, - "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c", + (byte*) "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c", 20, - "Test With Truncation", - "\x56\x46\x1e\xf2\x34\x2e\xdc\x00\xf9\xba\xb9\x95\x69\x0e\xfd\x4c"}, + (byte*) "Test With Truncation", + (byte*) "\x56\x46\x1e\xf2\x34\x2e\xdc\x00\xf9\xba\xb9\x95\x69\x0e\xfd\x4c"}, { 640, - "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", + (byte*) "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 54, - "Test Using Larger Than Block-Size Key - Hash Key First", - "\x6b\x1a\xb7\xfe\x4b\xd7\xbf\x8f\x0b\x62\xe6\xce\x61\xb9\xd0\xcd" }, + (byte*) "Test Using Larger Than Block-Size Key - Hash Key First", + (byte*) "\x6b\x1a\xb7\xfe\x4b\xd7\xbf\x8f\x0b\x62\xe6\xce\x61\xb9\xd0\xcd" }, { 640, - "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", + (byte*) "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 73, - "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data", - "\x6f\x63\x0f\xad\x67\xcd\xa0\xee\x1f\xb1\xf5\x62\xdb\x3a\xa5\x3e" } + (byte*) "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data", + (byte*) "\x6f\x63\x0f\xad\x67\xcd\xa0\xee\x1f\xb1\xf5\x62\xdb\x3a\xa5\x3e" } }; int main() diff --git a/beecrypt/tests/testhmacsha1.c b/beecrypt/tests/testhmacsha1.c index c9fce13..93d80b5 100644 --- a/beecrypt/tests/testhmacsha1.c +++ b/beecrypt/tests/testhmacsha1.c @@ -24,9 +24,9 @@ * \ingroup UNIT_m */ -#include "system.h" +#include + #include "hmacsha1.h" -#include "debug.h" struct vector { @@ -40,40 +40,40 @@ struct vector struct vector table[7] = { { 160, - "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b", + (byte*) "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b", 8, - "Hi There", - "\xb6\x17\x31\x86\x55\x05\x72\x64\xe2\x8b\xc0\xb6\xfb\x37\x8c\x8e\xf1\x46\xbe\x00" }, + (byte*) "Hi There", + (byte*) "\xb6\x17\x31\x86\x55\x05\x72\x64\xe2\x8b\xc0\xb6\xfb\x37\x8c\x8e\xf1\x46\xbe\x00" }, { 32, - "Jefe", + (byte*) "Jefe", 28, - "what do ya want for nothing?", - "\xef\xfc\xdf\x6a\xe5\xeb\x2f\xa2\xd2\x74\x16\xd5\xf1\x84\xdf\x9c\x25\x9a\x7c\x79" }, + (byte*) "what do ya want for nothing?", + (byte*) "\xef\xfc\xdf\x6a\xe5\xeb\x2f\xa2\xd2\x74\x16\xd5\xf1\x84\xdf\x9c\x25\x9a\x7c\x79" }, { 160, - "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", + (byte*) "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 50, - "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd", - "\x12\x5d\x73\x42\xb9\xac\x11\xcd\x91\xa3\x9a\xf4\x8a\xa1\x7b\x4f\x63\xf1\x75\xd3" }, + (byte*) "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd", + (byte*) "\x12\x5d\x73\x42\xb9\xac\x11\xcd\x91\xa3\x9a\xf4\x8a\xa1\x7b\x4f\x63\xf1\x75\xd3" }, { 200, - "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19", + (byte*) "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19", 50, - "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd", - "\x4c\x90\x07\xf4\x02\x62\x50\xc6\xbc\x84\x14\xf9\xbf\x50\xc8\x6c\x2d\x72\x35\xda" }, + (byte*) "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd", + (byte*) "\x4c\x90\x07\xf4\x02\x62\x50\xc6\xbc\x84\x14\xf9\xbf\x50\xc8\x6c\x2d\x72\x35\xda" }, { 160, - "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c", + (byte*) "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c", 20, - "Test With Truncation", - "\x4c\x1a\x03\x42\x4b\x55\xe0\x7f\xe7\xf2\x7b\xe1\xd5\x8b\xb9\x32\x4a\x9a\x5a\x04" }, + (byte*) "Test With Truncation", + (byte*) "\x4c\x1a\x03\x42\x4b\x55\xe0\x7f\xe7\xf2\x7b\xe1\xd5\x8b\xb9\x32\x4a\x9a\x5a\x04" }, { 640, - "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", + (byte*) "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 54, - "Test Using Larger Than Block-Size Key - Hash Key First", - "\xaa\x4a\xe5\xe1\x52\x72\xd0\x0e\x95\x70\x56\x37\xce\x8a\x3b\x55\xed\x40\x21\x12" }, + (byte*) "Test Using Larger Than Block-Size Key - Hash Key First", + (byte*) "\xaa\x4a\xe5\xe1\x52\x72\xd0\x0e\x95\x70\x56\x37\xce\x8a\x3b\x55\xed\x40\x21\x12" }, { 640, - "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", + (byte*) "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 73, - "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data", - "\xe8\xe9\x9d\x0f\x45\x23\x7d\x78\x6d\x6b\xba\xa7\x96\x5c\x78\x08\xbb\xff\x1a\x91" } + (byte*) "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data", + (byte*) "\xe8\xe9\x9d\x0f\x45\x23\x7d\x78\x6d\x6b\xba\xa7\x96\x5c\x78\x08\xbb\xff\x1a\x91" } }; int main() diff --git a/beecrypt/tests/testmd5.c b/beecrypt/tests/testmd5.c index f5e1ef3..1fe29d8 100644 --- a/beecrypt/tests/testmd5.c +++ b/beecrypt/tests/testmd5.c @@ -24,9 +24,9 @@ * \ingroup UNIT_m */ -#include "system.h" +#include + #include "md5.h" -#include "debug.h" struct vector { diff --git a/beecrypt/tests/testmp.c b/beecrypt/tests/testmp.c index 9b9d267..a4d1d82 100644 --- a/beecrypt/tests/testmp.c +++ b/beecrypt/tests/testmp.c @@ -1,7 +1,7 @@ -#include "system.h" +#include + #include "beecrypt.h" #include "mp.h" -#include "debug.h" #define INIT 0xdeadbeefU; @@ -13,6 +13,7 @@ int main() { int i, carry; mpw x[4]; + mpw y[4]; mpw r[8]; for (i = 0; i < 4; i++) diff --git a/beecrypt/tests/testmpinv.c b/beecrypt/tests/testmpinv.c index 1297189..f1c10af 100644 --- a/beecrypt/tests/testmpinv.c +++ b/beecrypt/tests/testmpinv.c @@ -23,50 +23,78 @@ * \ingroup UNIT_m */ -#include "system.h" +#include #include "beecrypt.h" -#include "mpbarrett.h" +#include "mpnumber.h" -#include "debug.h" +struct vector +{ + const char* m; + const char* k; + const char* inv_k; +}; + +#define NVECTORS 5 + +struct vector table[NVECTORS] = { + { "c773218c737ec8ee993b4f2ded30f48edace915f", + "358dad571462710f50e254cf1a376b2bdeaadfbf", + "0d5167298202e49b4116ac104fc3f415ae52f917" }, + { "fe95df16069b516859ba036ef0e563a7b6a86409", + "eedd5539e982b570a5f8efc73f243a04f312920d", + "f64a00a9ce43f4128e5eee1991b2e08c6008ba4e" }, + { "fe95df16069b516859ba036ef0e563a7b6a86409", + "d75f6d17eb243613eacc0dcbb41db4e5a3364b07", + "e90aa0a992ebd4c9176f0e20a885101218111a73" }, + { "fe95df16069b516859ba036ef0e563a7b6a86409", + "759ea04b65f66184af22fcabfe99a1cda3a79236", + "2c701a52078afe539a281cba7f35df34a7a125a4" }, + { "80277b4855a39cb9a98b2107cc1efb29f1832f727df05931cdd4a64cd78363134bf2abe78723784d2013a26875afe13f04526399c6b0cee659abb60dc8263400", + "10001", + "6e5f92b24defc7ffafa20024b30ccbcce810d0408f6efda3035f6e8b27e224e66db6e78f54b89bd7f11477fff7bc2f071335d24a92f19c8090226f7d97303001" } -static const char* dsa_q = "c773218c737ec8ee993b4f2ded30f48edace915f"; -static const char* dsa_k = "358dad571462710f50e254cf1a376b2bdeaadfbf"; -static const char* dsa_inv_k = "0d5167298202e49b4116ac104fc3f415ae52f917"; +}; int main() { - int failures = 0; + int i, failures = 0; - mpnumber q; + mpnumber m; mpnumber k; mpnumber inv_k; mpnumber inv; - mpnzero(&q); + mpnzero(&m); mpnzero(&k); mpnzero(&inv_k); mpnzero(&inv); - mpnsethex(&q, dsa_q); - mpnsethex(&k, dsa_k); - mpnsethex(&inv_k, dsa_inv_k); - - if (mpninv(&inv, &k, &q)) + for (i = 0; i < NVECTORS; i++) { - if (mpnex(inv.size, inv.data, inv_k.size, inv_k.data)) + mpnsethex(&m, table[i].m); + mpnsethex(&k, table[i].k); + mpnsethex(&inv_k, table[i].inv_k); + + if (mpninv(&inv, &k, &m)) { - printf("mpninv return unexpected result\n"); - mpprintln(inv_k.size, inv_k.data); - mpprintln(inv.size, inv.data); + if (mpnex(inv.size, inv.data, inv_k.size, inv_k.data)) + { + printf("mpninv return unexpected result\n"); + failures++; + } + } + else + { + printf("mpninv failed\n"); failures++; } } - else - { - printf("mpninv failed\n"); - failures++; - } + + mpnfree(&m); + mpnfree(&k); + mpnfree(&inv_k); + mpnfree(&inv); return failures; } diff --git a/beecrypt/tests/testrsa.c b/beecrypt/tests/testrsa.c index 8fcc8be..c5e756f 100644 --- a/beecrypt/tests/testrsa.c +++ b/beecrypt/tests/testrsa.c @@ -23,10 +23,10 @@ * \ingroup UNIT_m */ -#include "system.h" +#include + #include "beecrypt.h" #include "rsa.h" -#include "debug.h" static const char* rsa_n = "bbf82f090682ce9c2338ac2b9da871f7368d07eed41043a440d6b6f07454f51fb8dfbaaf035c02ab61ea48ceeb6fcd4876ed520d60e1ec4619719d8a5b8b807fafb8e0a3dfc737723ee6b4b7d93a2584ee6a649d060953748834b2454598394ee0aab12d7b61a51f527a9a41f6c1687fe2537298ca2a8f5946f8e5fd091dbdcb"; static const char* rsa_e = "11"; @@ -44,39 +44,64 @@ int main() rsakp keypair; mpnumber m, cipher, decipher; + randomGeneratorContext rngc; + + if (randomGeneratorContextInit(&rngc, randomGeneratorDefault()) == 0) + { + /* First we do the fixed value verification */ + rsakpInit(&keypair); + + mpbsethex(&keypair.n, rsa_n); + mpnsethex(&keypair.e, rsa_e); + mpbsethex(&keypair.p, rsa_p); + mpbsethex(&keypair.q, rsa_q); + mpnsethex(&keypair.dp, rsa_d1); + mpnsethex(&keypair.dq, rsa_d2); + mpnsethex(&keypair.qi, rsa_c); + + mpnzero(&m); + mpnzero(&cipher); + mpnzero(&decipher); + + mpnsethex(&m, rsa_m); + + /* it's safe to cast the keypair to a public key */ + if (rsapub(&keypair.n, &keypair.e, &m, &cipher)) + failures++; + + if (rsapricrt(&keypair.n, &keypair.p, &keypair.q, &keypair.dp, &keypair.dq, &keypair.qi, &cipher, &decipher)) + failures++; + + if (mpnex(m.size, m.data, decipher.size, decipher.data)) + failures++; - rsakpInit(&keypair); + mpnfree(&decipher); + mpnfree(&cipher); + mpnfree(&m); - mpbsethex(&keypair.n, rsa_n); - mpnsethex(&keypair.e, rsa_e); - /* we don't set n, as we're going to use CRT */ - mpbsethex(&keypair.p, rsa_p); - mpbsethex(&keypair.q, rsa_q); - mpnsethex(&keypair.d1, rsa_d1); - mpnsethex(&keypair.d2, rsa_d2); - mpnsethex(&keypair.c, rsa_c); + rsakpFree(&keypair); - mpnzero(&m); - mpnzero(&cipher); - mpnzero(&decipher); + mpnzero(&m); + mpnzero(&cipher); + mpnzero(&decipher); - mpnsethex(&m, rsa_m); + /* Now we generate a keypair and do some tests on it */ + rsakpMake(&keypair, &rngc, 512); - /* it's safe to cast the keypair to a public key */ - if (rsapub((rsapk*) &keypair, &m, &cipher)) - failures++; + /* generate a random m in the range 0 < m < n */ + mpbnrnd(&keypair.n, &rngc, &m); - if (rsapricrt(&keypair, &cipher, &decipher)) - failures++; - - if (mpnex(m.size, m.data, decipher.size, decipher.data)) - failures++; + /* it's safe to cast the keypair to a public key */ + if (rsapub(&keypair.n, &keypair.e, &m, &cipher)) + failures++; - mpnfree(&decipher); - mpnfree(&cipher); - mpnfree(&m); + if (rsapricrt(&keypair.n, &keypair.p, &keypair.q, &keypair.dp, &keypair.dq, &keypair.qi, &cipher, &decipher)) + failures++; - rsakpFree(&keypair); + if (mpnex(m.size, m.data, decipher.size, decipher.data)) + failures++; + rsakpFree(&keypair); + } return failures; } diff --git a/beecrypt/tests/testsha1.c b/beecrypt/tests/testsha1.c index f2c3796..d65e7eb 100644 --- a/beecrypt/tests/testsha1.c +++ b/beecrypt/tests/testsha1.c @@ -24,10 +24,10 @@ * \ingroup UNIT_m */ -#include "system.h" +#include + #include "sha1.h" #include "memchunk.h" -#include "debug.h" struct vector { diff --git a/beecrypt/tests/testsha256.c b/beecrypt/tests/testsha256.c index 9d67021..da3670d 100644 --- a/beecrypt/tests/testsha256.c +++ b/beecrypt/tests/testsha256.c @@ -21,9 +21,9 @@ * */ -#include "system.h" +#include + #include "sha256.h" -#include "debug.h" struct vector { diff --git a/beecrypt/tests/testutil.c b/beecrypt/tests/testutil.c index 8754744..4fe5ac9 100644 --- a/beecrypt/tests/testutil.c +++ b/beecrypt/tests/testutil.c @@ -17,11 +17,9 @@ * */ -#include "system.h" - #include "beecrypt.h" -#include "debug.h" +#include int fromhex(byte* data, const char* hexdata) { diff --git a/beecrypt/timestamp.c b/beecrypt/timestamp.c index 4f75451..093e221 100644 --- a/beecrypt/timestamp.c +++ b/beecrypt/timestamp.c @@ -19,12 +19,27 @@ /*!\file timestamp.c * \brief Java compatible 64-bit timestamp. - * \author Bob Deblier + * \author Bob Deblier */ -#include "system.h" -#include "timestamp.h" -#include "debug.h" +#define BEECRYPT_DLL_EXPORT + +#if HAVE_CONFIG_H +# include "config.h" +#endif + +#include "beecrypt/timestamp.h" + +#if TIME_WITH_SYS_TIME +# include +# include +#else +# if HAVE_SYS_TIME_H +# include +# elif HAVE_TIME_H +# include +# endif +#endif javalong timestamp() { @@ -33,7 +48,7 @@ javalong timestamp() # if HAVE_GETTIMEOFDAY struct timeval now; - (void) gettimeofday(&now, 0); + gettimeofday(&now, 0); tmp = ((javalong) now.tv_sec) * 1000 + (now.tv_usec / 1000); # else diff --git a/beecrypt/timestamp.h b/beecrypt/timestamp.h index 4e4b2da..2616e64 100644 --- a/beecrypt/timestamp.h +++ b/beecrypt/timestamp.h @@ -1,12 +1,12 @@ -/** \ingroup JAVA_m - * \file timestamp.h - * - * Java-compatible 64 bit timestamp, header. - */ - /* + * timestamp.h + * + * Java-compatible 64 bit timestamp, header + * * Copyright (c) 1999, 2000 Virtual Unlimited B.V. * + * Author: Bob Deblier + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either @@ -26,7 +26,7 @@ #ifndef _TIMESTAMP_H #define _TIMESTAMP_H -#include "beecrypt.h" +#include "beecrypt/beecrypt.h" #if HAVE_LONG_LONG # define ONE_SECOND 1000LL @@ -48,9 +48,7 @@ extern "C" { #endif -/** - */ -BEECRYPTAPI /*@unused@*/ +BEECRYPTAPI javalong timestamp(void); #ifdef __cplusplus diff --git a/beecrypt/win.h b/beecrypt/win.h new file mode 100644 index 0000000..40a79e4 --- /dev/null +++ b/beecrypt/win.h @@ -0,0 +1,139 @@ +/* + * Copyright (c) 2000, 2001, 2002 Virtual Unlimited B.V. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/*!\file win.h + * \brief BeeCrypt API, windows headers. + * \author Bob Deblier + */ + +#ifndef _BEECRYPT_WIN_H +#define _BEECRYPT_WIN_H + +#define _REENTRANT + +#if !defined(_WIN32_WINNT) +#define _WIN32_WINNT 0x0400 +#endif + +#include + +#if __MWERKS__ +# if __INTEL__ +# define WORDS_BIGENDIAN 0 +# else +# error Unknown CPU type in MetroWerks CodeWarrior +# endif +#elif defined(_MSC_VER) +# if defined(_M_IX86) +# define WORDS_BIGENDIAN 0 +# define ROTL32(x, s) _rotl(x, s) +# define ROTR32(x, s) _rotr(x, s) +# else +# error Unknown CPU type in Microsoft Visual C +# endif +#else +# error Unknown compiler for WIN32 +#endif + +#if defined(_MSC_VER) || __MWERKS__ +#include +#include +#include + +#define HAVE_ERRNO_H 1 +#define HAVE_CTYPE_H 1 +#define HAVE_FCNTL_H 1 +#define HAVE_TIME_H 1 + +#define HAVE_SYS_TYPES_H 0 +#define HAVE_SYS_TIME_H 0 + +#define HAVE_THREAD_H 0 +#define HAVE_SYNCH_H 0 +#define HAVE_PTHREAD_H 0 +#define HAVE_SEMAPHORE_H 0 + +#define HAVE_TERMIO_H 0 +#define HAVE_SYS_AUDIOIO_H 0 +#define HAVE_SYS_IOCTL_H 0 +#define HAVE_SYS_SOUNDCARD_H 0 + +#define HAVE_GETTIMEOFDAY 0 +#define HAVE_GETHRTIME 0 + +#define HAVE_DEV_TTY 0 +#define HAVE_DEV_AUDIO 0 +#define HAVE_DEV_DSP 0 +#define HAVE_DEV_RANDOM 0 +#define HAVE_DEV_URANDOM 0 +#define HAVE_DEV_TTY 0 + +#else +#error Not set up for this compiler +#endif + +#if __MWERKS__ +#define HAVE_SYS_STAT_H 0 + +#define HAVE_LONG_LONG 1 +#define HAVE_UNSIGNED_LONG_LONG 1 + +#define HAVE_64_BIT_INT 1 +#define HAVE_64_BIT_UINT 1 + +typedef char int8_t; +typedef short int16_t; +typedef long int32_t; +typedef long long int64_t; + +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned long uint32_t; +typedef unsigned long long uint64_t; + +#elif defined(_MSC_VER) +#define HAVE_SYS_STAT_H 1 + +#define HAVE_LONG_LONG 0 +#define HAVE_UNSIGNED_LONG_LONG 0 + +#define HAVE_64_BIT_INT 1 +#define HAVE_64_BIT_UINT 1 + +typedef signed char int8_t; +typedef signed short int16_t; +typedef signed int int32_t; +typedef signed __int64 int64_t; + +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned int uint32_t; +typedef unsigned __int64 uint64_t; + +typedef long off_t; + +#endif + +#define MP_WBITS 32U + +typedef HANDLE bc_cond_t; +typedef HANDLE bc_mutex_t; +typedef DWORD bc_thread_t; + +#endif -- 2.7.4