├── .github ├── CONTRIBUTING.md ├── ISSUE_TEMPLATE.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── .mailmap ├── AUTHORS ├── COPYING ├── COPYING.LIB ├── ChangeLog ├── ChangeLog-2011 ├── INSTALL ├── LICENSES ├── Makefile.am ├── NEWS ├── README ├── README.GIT ├── README.markdown ├── SMP ├── .gitattributes ├── .gitignore ├── SMP.patch ├── appveyor.yml ├── cipher │ └── gost-sb.h ├── config.h ├── gcrypt.h ├── libgcrypt.sln ├── libgcrypt.vcxproj ├── libgcrypt.vcxproj.filters ├── libgcrypt_deps.sln ├── libgcrypt_deps_with_latest_sdk.bat ├── libgcrypt_files.props ├── libgcrypt_winrt.vcxproj ├── libgcrypt_winrt.vcxproj.filters ├── libgcrypt_with_latest_sdk.bat ├── mpi │ ├── asm-syntax.h │ ├── mod-source-info.h │ ├── mpi-asm-defs.h │ └── sysdep.h ├── project_get_dependencies.bat ├── readme.txt ├── smp_deps.props ├── smp_winrt_deps.props ├── version.h └── versioninfo.rc ├── THANKS ├── TODO ├── acinclude.m4 ├── autogen.rc ├── autogen.sh ├── build-aux ├── ChangeLog-2011 ├── compile ├── config.guess ├── config.rpath ├── config.sub ├── db2any ├── depcomp ├── distfiles ├── git-hooks │ └── commit-msg ├── git-log-fix ├── git-log-footer ├── install-sh ├── libtool-patch.sed ├── ltmain.sh ├── mdate-sh ├── missing └── texinfo.tex ├── cipher ├── ChangeLog-2011 ├── Makefile.am ├── arcfour-amd64.S ├── arcfour.c ├── aria-aesni-avx-amd64.S ├── aria-aesni-avx2-amd64.S ├── aria-gfni-avx512-amd64.S ├── aria.c ├── asm-common-aarch64.h ├── asm-common-amd64.h ├── asm-common-i386.h ├── asm-common-s390x.h ├── asm-inline-s390x.h ├── asm-poly1305-aarch64.h ├── asm-poly1305-amd64.h ├── asm-poly1305-s390x.h ├── bithelp.h ├── blake2.c ├── blake2b-amd64-avx2.S ├── blake2b-amd64-avx512.S ├── blake2s-amd64-avx.S ├── blake2s-amd64-avx512.S ├── blowfish-amd64.S ├── blowfish-arm.S ├── blowfish.c ├── bufhelp.h ├── bulkhelp.h ├── camellia-aarch64-ce.c ├── camellia-aarch64.S ├── camellia-aesni-avx-amd64.S ├── camellia-aesni-avx2-amd64.S ├── camellia-aesni-avx2-amd64.h ├── camellia-arm.S ├── camellia-gfni-avx2-amd64.S ├── camellia-gfni-avx512-amd64.S ├── camellia-glue.c ├── camellia-ppc8le.c ├── camellia-ppc9le.c ├── camellia-simd128.h ├── camellia-vaes-avx2-amd64.S ├── camellia.c ├── camellia.h ├── cast5-amd64.S ├── cast5-arm.S ├── cast5.c ├── chacha20-aarch64.S ├── chacha20-amd64-avx2.S ├── chacha20-amd64-avx512.S ├── chacha20-amd64-ssse3.S ├── chacha20-armv7-neon.S ├── chacha20-p10le-8x.s ├── chacha20-ppc.c ├── chacha20-s390x.S ├── chacha20.c ├── cipher-aeswrap.c ├── cipher-cbc.c ├── cipher-ccm.c ├── cipher-cfb.c ├── cipher-cmac.c ├── cipher-ctr.c ├── cipher-eax.c ├── cipher-gcm-armv7-neon.S ├── cipher-gcm-armv8-aarch32-ce.S ├── cipher-gcm-armv8-aarch64-ce.S ├── cipher-gcm-intel-pclmul.c ├── cipher-gcm-ppc.c ├── cipher-gcm-siv.c ├── cipher-gcm.c ├── cipher-internal.h ├── cipher-ocb.c ├── cipher-ofb.c ├── cipher-poly1305.c ├── cipher-siv.c ├── cipher-xts.c ├── cipher.c ├── crc-armv8-aarch64-ce.S ├── crc-armv8-ce.c ├── crc-intel-pclmul.c ├── crc-ppc.c ├── crc.c ├── des-amd64.S ├── des.c ├── dsa-common.c ├── dsa.c ├── ecc-common.h ├── ecc-curves.c ├── ecc-ecdh.c ├── ecc-ecdsa.c ├── ecc-eddsa.c ├── ecc-gost.c ├── ecc-misc.c ├── ecc-sm2.c ├── ecc.c ├── elgamal.c ├── gost-s-box.c ├── gost.h ├── gost28147.c ├── gostr3411-94.c ├── hash-common.c ├── hash-common.h ├── idea.c ├── kdf-internal.h ├── kdf.c ├── keccak-amd64-avx512.S ├── keccak-armv7-neon.S ├── keccak.c ├── keccak_permute_32.h ├── keccak_permute_64.h ├── kem-ecc.c ├── kem-ecc.h ├── kem.c ├── kyber-common.c ├── kyber-kdep.c ├── kyber.c ├── kyber.h ├── mac-cmac.c ├── mac-gmac.c ├── mac-hmac.c ├── mac-internal.h ├── mac-poly1305.c ├── mac.c ├── mceliece6688128f.c ├── mceliece6688128f.h ├── md.c ├── md2.c ├── md4.c ├── md5.c ├── poly1305-amd64-avx512.S ├── poly1305-internal.h ├── poly1305-p10le.s ├── poly1305-s390x.S ├── poly1305.c ├── primegen.c ├── pubkey-internal.h ├── pubkey-util.c ├── pubkey.c ├── rfc2268.c ├── rijndael-aarch64.S ├── rijndael-aesni.c ├── rijndael-amd64.S ├── rijndael-arm.S ├── rijndael-armv8-aarch32-ce.S ├── rijndael-armv8-aarch64-ce.S ├── rijndael-armv8-ce.c ├── rijndael-gcm-p10le.s ├── rijndael-internal.h ├── rijndael-p10le.c ├── rijndael-padlock.c ├── rijndael-ppc-common.h ├── rijndael-ppc-functions.h ├── rijndael-ppc.c ├── rijndael-ppc9le.c ├── rijndael-s390x.c ├── rijndael-ssse3-amd64-asm.S ├── rijndael-ssse3-amd64.c ├── rijndael-tables.h ├── rijndael-vaes-avx2-amd64.S ├── rijndael-vaes-avx2-i386.S ├── rijndael-vaes-i386.c ├── rijndael-vaes.c ├── rijndael.c ├── rmd160.c ├── rsa-common.c ├── rsa.c ├── salsa20-amd64.S ├── salsa20-armv7-neon.S ├── salsa20.c ├── scrypt.c ├── seed.c ├── serpent-armv7-neon.S ├── serpent-avx2-amd64.S ├── serpent-avx512-x86.c ├── serpent-sse2-amd64.S ├── serpent.c ├── sha1-armv7-neon.S ├── sha1-armv8-aarch32-ce.S ├── sha1-armv8-aarch64-ce.S ├── sha1-avx-amd64.S ├── sha1-avx-bmi2-amd64.S ├── sha1-avx2-bmi2-amd64.S ├── sha1-intel-shaext.c ├── sha1-ssse3-amd64.S ├── sha1.c ├── sha1.h ├── sha256-armv8-aarch32-ce.S ├── sha256-armv8-aarch64-ce.S ├── sha256-avx-amd64.S ├── sha256-avx2-bmi2-amd64.S ├── sha256-intel-shaext.c ├── sha256-ppc.c ├── sha256-ssse3-amd64.S ├── sha256.c ├── sha512-arm.S ├── sha512-armv7-neon.S ├── sha512-armv8-aarch64-ce.S ├── sha512-avx-amd64.S ├── sha512-avx2-bmi2-amd64.S ├── sha512-avx512-amd64.S ├── sha512-ppc.c ├── sha512-ssse3-amd64.S ├── sha512-ssse3-i386.c ├── sha512.c ├── sm3-aarch64.S ├── sm3-armv8-aarch64-ce.S ├── sm3-avx-bmi2-amd64.S ├── sm3.c ├── sm4-aarch64.S ├── sm4-aesni-avx-amd64.S ├── sm4-aesni-avx2-amd64.S ├── sm4-armv8-aarch64-ce.S ├── sm4-armv9-aarch64-sve-ce.S ├── sm4-gfni-avx2-amd64.S ├── sm4-gfni-avx512-amd64.S ├── sm4-ppc.c ├── sm4.c ├── sntrup761.c ├── sntrup761.h ├── stribog.c ├── test-getrusage.c ├── tiger.c ├── twofish-aarch64.S ├── twofish-amd64.S ├── twofish-arm.S ├── twofish-avx2-amd64.S ├── twofish.c ├── whirlpool-sse2-amd64.S └── whirlpool.c ├── compat ├── Makefile.am ├── clock.c ├── compat.c ├── getpid.c └── libcompat.h ├── configure.ac ├── doc ├── ChangeLog-2011 ├── DCO ├── HACKING ├── Makefile.am ├── Notes-wk ├── README.apichanges ├── announce-1.4.txt ├── announce.txt ├── fips-fsm.fig ├── gcrypt.texi ├── gpl.texi ├── lgpl.texi ├── libgcrypt-modules.fig └── yat2m.c ├── libgcrypt.txt ├── m4 ├── ChangeLog-2011 ├── Makefile.am ├── ax_cc_for_build.m4 ├── gpg-error.m4 ├── libtool.m4 ├── ltoptions.m4 ├── ltsugar.m4 ├── ltversion.m4 ├── lt~obsolete.m4 └── noexecstack.m4 ├── mkinstalldirs ├── mpi ├── ChangeLog-2011 ├── Makefile.am ├── aarch64 │ ├── distfiles │ ├── mpi-asm-defs.h │ ├── mpih-add1.S │ ├── mpih-mul1.S │ ├── mpih-mul2.S │ ├── mpih-mul3.S │ └── mpih-sub1.S ├── alpha │ ├── README │ ├── distfiles │ ├── mpih-add1.S │ ├── mpih-lshift.S │ ├── mpih-mul1.S │ ├── mpih-mul2.S │ ├── mpih-mul3.S │ ├── mpih-rshift.S │ ├── mpih-sub1.S │ └── udiv-qrnnd.S ├── amd64 │ ├── distfiles │ ├── func_abi.h │ ├── mpi-asm-defs.h │ ├── mpih-add1.S │ ├── mpih-lshift.S │ ├── mpih-mul1.S │ ├── mpih-mul2.S │ ├── mpih-mul3.S │ ├── mpih-rshift.S │ └── mpih-sub1.S ├── arm │ ├── distfiles │ ├── mpi-asm-defs.h │ ├── mpih-add1.S │ ├── mpih-mul1.S │ ├── mpih-mul2.S │ ├── mpih-mul3.S │ └── mpih-sub1.S ├── asm-common-aarch64.h ├── asm-common-amd64.h ├── asm-common-i386.h ├── config.links ├── ec-ed25519.c ├── ec-hw-s390x.c ├── ec-inline.h ├── ec-internal.h ├── ec-nist.c ├── ec.c ├── generic │ ├── distfiles │ ├── mpi-asm-defs.h │ ├── mpih-add1.c │ ├── mpih-lshift.c │ ├── mpih-mul1.c │ ├── mpih-mul2.c │ ├── mpih-mul3.c │ ├── mpih-rshift.c │ ├── mpih-sub1.c │ └── udiv-w-sdiv.c ├── hppa │ ├── README │ ├── distfiles │ ├── mpih-add1.S │ ├── mpih-lshift.S │ ├── mpih-rshift.S │ ├── mpih-sub1.S │ └── udiv-qrnnd.S ├── hppa1.1 │ ├── distfiles │ ├── mpih-mul1.S │ ├── mpih-mul2.S │ ├── mpih-mul3.S │ └── udiv-qrnnd.S ├── i386 │ ├── distfiles │ ├── mpih-add1.S │ ├── mpih-lshift.S │ ├── mpih-mul1.S │ ├── mpih-mul2.S │ ├── mpih-mul3.S │ ├── mpih-rshift.S │ ├── mpih-sub1.S │ └── syntax.h ├── longlong.h ├── m68k │ ├── distfiles │ ├── mc68020 │ │ ├── distfiles │ │ ├── mpih-mul1.S │ │ ├── mpih-mul2.S │ │ └── mpih-mul3.S │ ├── mpih-add1.S │ ├── mpih-lshift.S │ ├── mpih-rshift.S │ ├── mpih-sub1.S │ └── syntax.h ├── mips3 │ ├── README │ ├── distfiles │ ├── mpi-asm-defs.h │ ├── mpih-add1.S │ ├── mpih-lshift.S │ ├── mpih-mul1.S │ ├── mpih-mul2.S │ ├── mpih-mul3.S │ ├── mpih-rshift.S │ └── mpih-sub1.S ├── mpi-add.c ├── mpi-bit.c ├── mpi-cmp.c ├── mpi-div.c ├── mpi-gcd.c ├── mpi-inline.c ├── mpi-inline.h ├── mpi-internal.h ├── mpi-inv.c ├── mpi-mod.c ├── mpi-mpow.c ├── mpi-mul.c ├── mpi-pow.c ├── mpi-scan.c ├── mpicoder.c ├── mpih-const-time.c ├── mpih-div.c ├── mpih-mul.c ├── mpiutil.c ├── pa7100 │ ├── distfiles │ ├── mpih-lshift.S │ └── mpih-rshift.S ├── power │ ├── distfiles │ ├── mpih-add1.S │ ├── mpih-lshift.S │ ├── mpih-mul1.S │ ├── mpih-mul2.S │ ├── mpih-mul3.S │ ├── mpih-rshift.S │ └── mpih-sub1.S ├── powerpc32 │ ├── distfiles │ ├── mpih-add1.S │ ├── mpih-lshift.S │ ├── mpih-mul1.S │ ├── mpih-mul2.S │ ├── mpih-mul3.S │ ├── mpih-rshift.S │ ├── mpih-sub1.S │ └── syntax.h ├── powerpc64 │ └── distfiles ├── sparc32 │ ├── distfiles │ ├── mpih-add1.S │ ├── mpih-lshift.S │ ├── mpih-rshift.S │ └── udiv.S ├── sparc32v8 │ ├── distfiles │ ├── mpih-mul1.S │ ├── mpih-mul2.S │ └── mpih-mul3.S └── supersparc │ ├── distfiles │ └── udiv.S ├── random ├── ChangeLog-2011 ├── Makefile.am ├── jitterentropy-base-user.h ├── jitterentropy-base.c ├── jitterentropy-base.h ├── jitterentropy-gcd.c ├── jitterentropy-gcd.h ├── jitterentropy-health.c ├── jitterentropy-health.h ├── jitterentropy-noise.c ├── jitterentropy-noise.h ├── jitterentropy-sha3.c ├── jitterentropy-sha3.h ├── jitterentropy-timer.c ├── jitterentropy-timer.h ├── jitterentropy.h ├── rand-internal.h ├── random-csprng.c ├── random-drbg.c ├── random-system.c ├── random.c ├── random.h ├── rndegd.c ├── rndgetentropy.c ├── rndhw.c ├── rndjent.c ├── rndoldlinux.c ├── rndunix.c ├── rndw32.c ├── rndw32ce.c └── rndw32uwp.cpp ├── src ├── ChangeLog-2011 ├── Makefile.am ├── cipher-proto.h ├── cipher.h ├── const-time.c ├── const-time.h ├── context.c ├── context.h ├── dumpsexp.c ├── ec-context.h ├── fips.c ├── g10lib.h ├── gcrypt-int.h ├── gcrypt-testapi.h ├── gcrypt.h.in ├── gen-note-integrity.sh ├── global.c ├── hmac256.c ├── hmac256.h ├── hwf-arm.c ├── hwf-common.h ├── hwf-ppc.c ├── hwf-s390x.c ├── hwf-x86.c ├── hwfeatures.c ├── libgcrypt-config.in ├── libgcrypt.def ├── libgcrypt.m4 ├── libgcrypt.pc.in ├── libgcrypt.vers ├── misc.c ├── missing-string.c ├── mpi.h ├── mpicalc.c ├── secmem.c ├── secmem.h ├── sexp.c ├── stdmem.c ├── stdmem.h ├── types.h ├── versioninfo.rc.in ├── visibility.c └── visibility.h ├── stamp-h.in └── tests ├── ChangeLog-2011 ├── Makefile.am ├── README ├── aeswrap.c ├── basic-disable-all-hwf.in ├── basic.c ├── basic_all_hwfeature_combinations.sh ├── bench-slope.c ├── benchmark.c ├── blake2b.h ├── blake2s.h ├── curves.c ├── dsa-rfc6979.c ├── fips186-dsa.c ├── fipsdrv.c ├── fipsrngdrv.c ├── gchash.c ├── genhashdata.c ├── hashtest-256g.in ├── hashtest-6g.in ├── hashtest.c ├── hmac.c ├── keygen.c ├── keygrip.c ├── mpitests.c ├── pkbench.c ├── pkcs1v2-oaep.h ├── pkcs1v2-pss.h ├── pkcs1v2-v15c.h ├── pkcs1v2-v15s.h ├── pkcs1v2.c ├── pkcstv2c.awk ├── prime.c ├── pubkey.c ├── random.c ├── rsa-16k.key ├── rsacvt.c ├── sha3-224.h ├── sha3-256.h ├── sha3-384.h ├── sha3-512.h ├── stopwatch.h ├── t-common.h ├── t-convert.c ├── t-cv25519.c ├── t-dsa.c ├── t-dsa.inp ├── t-ecdsa.c ├── t-ecdsa.inp ├── t-ed25519.c ├── t-ed25519.inp ├── t-ed448.c ├── t-ed448.inp ├── t-kdf.c ├── t-kem.c ├── t-lock.c ├── t-mlkem.c ├── t-mlkem.inp ├── t-mpi-bit.c ├── t-mpi-point.c ├── t-rsa-15.c ├── t-rsa-15.inp ├── t-rsa-pss.c ├── t-rsa-pss.inp ├── t-rsa-testparm.c ├── t-secmem.c ├── t-sexp.c ├── t-x448.c ├── testapi.c ├── testdrv.c └── version.c /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Context 4 | 5 | 6 | ## Expected Behavior 7 | 8 | 9 | ## Actual Behavior 10 | 11 | 12 | ## Steps to Reproduce 13 | 14 | 1. 15 | 2. 16 | 3. 17 | 4. 18 | 19 | ## Your Environment 20 | 21 | * Version Used: 22 | * Operating System and Version: 23 | * Compiler and Version(s): 24 | 25 | ## Possible Fix 26 | 27 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Context 4 | 5 | 6 | ## Current and Suggested Behavior 7 | 8 | 9 | ## Steps to Explain Enhancement 10 | 11 | 1. 12 | 2. 13 | 3. 14 | 4. 15 | 16 | ## Your Test Environment 17 | 18 | * Version Used: 19 | * Operating System and Version(s): 20 | * Compiler and version(s): -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.lo 2 | *.o 3 | .deps/ 4 | .libs/ 5 | po/*.gmo 6 | po/messages.mo 7 | /aclocal.m4 8 | /autom4te.cache 9 | /config.h.in 10 | /config.h 11 | /config.log 12 | /config.status 13 | /configure 14 | /libtool 15 | /stamp-h1 16 | /Makefile.in 17 | /VERSION 18 | cipher/Makefile.in 19 | cipher/gost-s-box 20 | cipher/gost-sb.h 21 | compat/Makefile.in 22 | doc/Makefile.in 23 | m4/Makefile.in 24 | mpi/Makefile.in 25 | random/Makefile.in 26 | src/Makefile.in 27 | tests/Makefile.in 28 | /Makefile 29 | m4/Makefile 30 | cipher/Makefile 31 | cipher/libcipher.la 32 | compat/Makefile 33 | compat/libcompat.la 34 | doc/gcrypt.info 35 | doc/gcrypt.info-1 36 | doc/gcrypt.info-2 37 | doc/stamp-vti 38 | doc/version.texi 39 | doc/Makefile 40 | doc/fips-fsm.eps 41 | doc/fips-fsm.pdf 42 | doc/fips-fsm.png 43 | doc/hmac256.1 44 | doc/libgcrypt-modules.eps 45 | doc/libgcrypt-modules.pdf 46 | doc/libgcrypt-modules.png 47 | doc/yat2m 48 | doc/yat2m-stamp 49 | mpi/Makefile 50 | mpi/asm-syntax.h 51 | mpi/libmpi.la 52 | mpi/mod-source-info.h 53 | mpi/mpi-asm-defs.h 54 | mpi/mpih-add1-asm.S 55 | mpi/mpih-lshift-asm.S 56 | mpi/mpih-mul1-asm.S 57 | mpi/mpih-mul2-asm.S 58 | mpi/mpih-mul3-asm.S 59 | mpi/mpih-rshift-asm.S 60 | mpi/mpih-sub1-asm.S 61 | mpi/sysdep.h 62 | random/Makefile 63 | random/librandom.la 64 | src/Makefile 65 | src/dumpsexp 66 | src/gcrypt.h 67 | src/hmac256 68 | src/libgcrypt-config 69 | src/libgcrypt.la 70 | src/libgcrypt.pc 71 | src/mpicalc 72 | src/versioninfo.rc 73 | src/*.exe 74 | tests/Makefile 75 | tests/ac 76 | tests/ac-data 77 | tests/ac-schemes 78 | tests/aeswrap 79 | tests/basic 80 | tests/basic-disable-all-hwf 81 | tests/bench-slope 82 | tests/benchmark 83 | tests/curves 84 | tests/dsa-rfc6979 85 | tests/fips186-dsa 86 | tests/fipsdrv 87 | tests/gchash 88 | tests/genhashdata 89 | tests/hashtest 90 | tests/hashtest-6g 91 | tests/hashtest-256g 92 | tests/hmac 93 | tests/keygen 94 | tests/keygrip 95 | tests/mpitests 96 | tests/pkcs1v2 97 | tests/prime 98 | tests/pubkey 99 | tests/random 100 | tests/register 101 | tests/rsacvt 102 | tests/t-convert 103 | tests/t-cv25519 104 | tests/t-ed25519 105 | tests/t-kdf 106 | tests/t-kem 107 | tests/t-lock 108 | tests/t-mpi-bit 109 | tests/t-mpi-point 110 | tests/t-sexp 111 | tests/t-secmem 112 | tests/t-x448 113 | tests/tsexp 114 | tests/version 115 | tests/*.exe 116 | -------------------------------------------------------------------------------- /.mailmap: -------------------------------------------------------------------------------- 1 | Dmitry Baryshkov 2 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | No more ChangeLog files 2 | ======================== 3 | 4 | Do not modify any of the ChangeLog files in Libgcrypt. Starting on 5 | December 1st, 2011 we put change information only in the GIT commit 6 | log, and generate a top-level ChangeLog file from logs at "make dist" 7 | time. As such, there are strict requirements on the form of the 8 | commit log messages. See doc/HACKING for details. The old ChangeLog 9 | files have all be renamed to ChangeLog-2011. 10 | 11 | 12 | 13 | Local Variables: 14 | buffer-read-only: t 15 | mode: text 16 | End: 17 | -------------------------------------------------------------------------------- /ChangeLog-2011: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/libgcrypt/4a997384e4bf0bb04e0fb6c61976c67c27bc8612/ChangeLog-2011 -------------------------------------------------------------------------------- /README.GIT: -------------------------------------------------------------------------------- 1 | If you are building from GIT, run the script 2 | 3 | ./autogen.sh 4 | 5 | first, to make sure that you have all the necessary maintainer tools 6 | are installed and to build the actual configuration files. If you 7 | have just checked out from GIT, you should add the option "--force" to 8 | autogen.sh so that meta data is noticed by autom4te.cache. Then run 9 | 10 | ./configure --enable-maintainer-mode 11 | 12 | followed by the usual make. 13 | 14 | If autogen.sh complains about insufficient versions of the required 15 | tools, or the tools are not installed, you may use environment 16 | variables to override the default tool names: 17 | 18 | AUTOMAKE_SUFFIX is used as a suffix for all tools from the automake 19 | package. For example 20 | AUTOMAKE_SUFFIX="-1.7" ./autogen.sh 21 | uses "automake-1.7" and "aclocal-1.7. 22 | AUTOMAKE_PREFIX is used as a prefix for all tools from the automake 23 | page and may be combined with AUTOMAKE_SUFFIX. e.g.: 24 | AUTOMAKE_PREFIX=/usr/foo/bin ./autogen.sh 25 | uses "automake" and "aclocal" in the /usr/foo/bin 26 | directory. 27 | AUTOCONF_SUFFIX is used as a suffix for all tools from the automake 28 | package 29 | AUTOCONF_PREFIX is used as a prefix for all tools from the automake 30 | package 31 | GETTEXT_SUFFIX is used as a suffix for all tools from the gettext 32 | package 33 | GETTEXT_PREFIX is used as a prefix for all tools from the gettext 34 | package 35 | 36 | It is also possible to use the variable name AUTOMAKE, AUTOCONF, 37 | ACLOCAL, AUTOHEADER, GETTEXT and MSGMERGE to directly specify the name 38 | of the programs to run. It is however better to use the suffix and 39 | prefix forms as described above because that does not require 40 | knowledge about the actual tools used by autogen.sh. 41 | 42 | 43 | Please don't use autopoint, libtoolize or autoreconf unless you are 44 | the current maintainer and want to update the standard configuration 45 | files. All those files should be in GIT and only updated manually 46 | if the maintainer decides that newer versions are required. The 47 | maintainer should also make sure that the required version of automake 48 | et al. are properly indicated at the top of configure.ac and take care 49 | to copy the files and not merely use symlinks. 50 | -------------------------------------------------------------------------------- /SMP/.gitattributes: -------------------------------------------------------------------------------- 1 | *.sln text eol=crlf 2 | *.vcxproj text eol=crlf 3 | *.vcxproj.filters text eol=crlf 4 | *.bat text eol=crlf -------------------------------------------------------------------------------- /SMP/.gitignore: -------------------------------------------------------------------------------- 1 | *.obj 2 | *.lib 3 | *.log 4 | *.tlog 5 | *.pdb 6 | *.ildb 7 | *.pgd 8 | *.pch 9 | *.manifest 10 | *.suo 11 | *.user 12 | *.sdf 13 | *.opensdf 14 | [Oo]bj/ 15 | *.exe 16 | !*.h 17 | !*.c 18 | !*.asm 19 | !*.def 20 | !*.rc 21 | *.sbr 22 | *.iobj 23 | *.ipdb 24 | .vs/ 25 | *.VC.db 26 | *.opendb 27 | *.ilk 28 | [Bb]in/ -------------------------------------------------------------------------------- /SMP/SMP.patch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/libgcrypt/4a997384e4bf0bb04e0fb6c61976c67c27bc8612/SMP/SMP.patch -------------------------------------------------------------------------------- /SMP/libgcrypt_deps_with_latest_sdk.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | SET PROJECT=libgcrypt_deps 4 | 5 | @REM Detect the newest available Windows SDK 6 | CALL :GetWindowsSdkVer 7 | 8 | @REM Open the project 9 | %PROJECT%.sln 10 | 11 | EXIT /B 0 12 | 13 | :GetWindowsSdkVer 14 | SET WindowsTargetPlatformVersion= 15 | 16 | IF "%WindowsTargetPlatformVersion%"=="" CALL :GetWin10SdkVer 17 | IF "%WindowsTargetPlatformVersion%"=="" CALL :GetWin81SdkVer 18 | EXIT /B 0 19 | 20 | :GetWin10SdkVer 21 | CALL :GetWin10SdkVerHelper HKLM\SOFTWARE\Wow6432Node > nul 2>&1 22 | IF errorlevel 1 CALL :GetWin10SdkVerHelper HKCU\SOFTWARE\Wow6432Node > nul 2>&1 23 | IF errorlevel 1 CALL :GetWin10SdkVerHelper HKLM\SOFTWARE > nul 2>&1 24 | IF errorlevel 1 CALL :GetWin10SdkVerHelper HKCU\SOFTWARE > nul 2>&1 25 | IF errorlevel 1 EXIT /B 1 26 | EXIT /B 0 27 | 28 | :GetWin10SdkVerHelper 29 | @REM Get Windows 10 SDK installed folder 30 | FOR /F "tokens=1,2*" %%i IN ('reg query "%1\Microsoft\Microsoft SDKs\Windows\v10.0" /v "InstallationFolder"') DO ( 31 | IF "%%i"=="InstallationFolder" ( 32 | SET WindowsSdkDir=%%~k 33 | ) 34 | ) 35 | 36 | @REM get windows 10 sdk version number 37 | SETLOCAL enableDelayedExpansion 38 | IF NOT "%WindowsSdkDir%"=="" FOR /f %%i IN ('dir "%WindowsSdkDir%include\" /b /ad-h /on') DO ( 39 | @REM Skip if Windows.h is not found in %%i\um. This would indicate that only the UCRT MSIs were 40 | @REM installed for this Windows SDK version. 41 | IF EXIST "%WindowsSdkDir%include\%%i\um\Windows.h" ( 42 | SET result=%%i 43 | IF "!result:~0,3!"=="10." ( 44 | SET SDK=!result! 45 | IF "!result!"=="%VSCMD_ARG_WINSDK%" SET findSDK=1 46 | ) 47 | ) 48 | ) 49 | 50 | IF "%findSDK%"=="1" SET SDK=%VSCMD_ARG_WINSDK% 51 | ENDLOCAL & SET WindowsTargetPlatformVersion=%SDK% 52 | IF "%WindowsTargetPlatformVersion%"=="" ( 53 | EXIT /B 1 54 | ) 55 | EXIT /B 0 56 | 57 | :GetWin81SdkVer 58 | SET WindowsTargetPlatformVersion=8.1 59 | EXIT /B 0 60 | -------------------------------------------------------------------------------- /SMP/libgcrypt_with_latest_sdk.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | SET PROJECT=libgcrypt 4 | 5 | @REM Detect the newest available Windows SDK 6 | CALL :GetWindowsSdkVer 7 | 8 | @REM Open the project 9 | %PROJECT%.sln 10 | 11 | EXIT /B 0 12 | 13 | :GetWindowsSdkVer 14 | SET WindowsTargetPlatformVersion= 15 | 16 | IF "%WindowsTargetPlatformVersion%"=="" CALL :GetWin10SdkVer 17 | IF "%WindowsTargetPlatformVersion%"=="" CALL :GetWin81SdkVer 18 | EXIT /B 0 19 | 20 | :GetWin10SdkVer 21 | CALL :GetWin10SdkVerHelper HKLM\SOFTWARE\Wow6432Node > nul 2>&1 22 | IF errorlevel 1 CALL :GetWin10SdkVerHelper HKCU\SOFTWARE\Wow6432Node > nul 2>&1 23 | IF errorlevel 1 CALL :GetWin10SdkVerHelper HKLM\SOFTWARE > nul 2>&1 24 | IF errorlevel 1 CALL :GetWin10SdkVerHelper HKCU\SOFTWARE > nul 2>&1 25 | IF errorlevel 1 EXIT /B 1 26 | EXIT /B 0 27 | 28 | :GetWin10SdkVerHelper 29 | @REM Get Windows 10 SDK installed folder 30 | FOR /F "tokens=1,2*" %%i IN ('reg query "%1\Microsoft\Microsoft SDKs\Windows\v10.0" /v "InstallationFolder"') DO ( 31 | IF "%%i"=="InstallationFolder" ( 32 | SET WindowsSdkDir=%%~k 33 | ) 34 | ) 35 | 36 | @REM get windows 10 sdk version number 37 | SETLOCAL enableDelayedExpansion 38 | IF NOT "%WindowsSdkDir%"=="" FOR /f %%i IN ('dir "%WindowsSdkDir%include\" /b /ad-h /on') DO ( 39 | @REM Skip if Windows.h is not found in %%i\um. This would indicate that only the UCRT MSIs were 40 | @REM installed for this Windows SDK version. 41 | IF EXIST "%WindowsSdkDir%include\%%i\um\Windows.h" ( 42 | SET result=%%i 43 | IF "!result:~0,3!"=="10." ( 44 | SET SDK=!result! 45 | IF "!result!"=="%VSCMD_ARG_WINSDK%" SET findSDK=1 46 | ) 47 | ) 48 | ) 49 | 50 | IF "%findSDK%"=="1" SET SDK=%VSCMD_ARG_WINSDK% 51 | ENDLOCAL & SET WindowsTargetPlatformVersion=%SDK% 52 | IF "%WindowsTargetPlatformVersion%"=="" ( 53 | EXIT /B 1 54 | ) 55 | EXIT /B 0 56 | 57 | :GetWin81SdkVer 58 | SET WindowsTargetPlatformVersion=8.1 59 | EXIT /B 0 60 | -------------------------------------------------------------------------------- /SMP/mpi/asm-syntax.h: -------------------------------------------------------------------------------- 1 | /* Host: generic */ 2 | /* No working assembler modules available */ 3 | -------------------------------------------------------------------------------- /SMP/mpi/mod-source-info.h: -------------------------------------------------------------------------------- 1 | /* Created by config.links - do not edit */ 2 | /* Host: generic */ 3 | static char mod_source_info[] = 4 | ":generic/mpih-add1.c" 5 | ":generic/mpih-sub1.c" 6 | ":generic/mpih-mul1.c" 7 | ":generic/mpih-mul2.c" 8 | ":generic/mpih-mul3.c" 9 | ":generic/mpih-lshift.c" 10 | ":generic/mpih-rshift.c" 11 | ; 12 | -------------------------------------------------------------------------------- /SMP/mpi/mpi-asm-defs.h: -------------------------------------------------------------------------------- 1 | /* This file defines some basic constants for the MPI machinery. We 2 | * need to define the types on a per-CPU basis, so it is done with 3 | * this file here. */ 4 | #if (__GNUC__ >= 3 && defined(__x86_64__) && defined(__ILP32__)) || (defined(_WIN64) || defined(_MSC_VER) && (defined(__x86_64__) || defined(__x86_64) || defined(_M_X64))) 5 | #define BYTES_PER_MPI_LIMB 8 6 | #else 7 | #define BYTES_PER_MPI_LIMB (SIZEOF_UNSIGNED_LONG) 8 | #endif 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /SMP/mpi/sysdep.h: -------------------------------------------------------------------------------- 1 | #define C_SYMBOL_NAME(name) name 2 | -------------------------------------------------------------------------------- /SMP/readme.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a small list of steps in order to build libgcrypt into a msvc dll and/or lib file. 3 | 4 | The project contains Release and Debug builds for static lib files (Debug/Release) 5 | as well as dynamic shared dll files (DebugDLL/ReleaseDLL). Along with the standard 6 | windows dll/lib configurations mentioned above there are also equivalent variants that 7 | can be used to compile for WinRT/UWP (These configurations have a WinRT suffix). 8 | There are also architecture configurations for either 32bit (x86) or 64bit (x64) compilation. 9 | Choose whichever project configuration meets your requirements. 10 | 11 | The project configurations support being built with various different windows SDK versions. 12 | By default they will use the lowest SDK version that would be available for Visual Studio 13 | version 2013 and up (This is the 8.1 SDK). However a batch file is also included 14 | (libgcrypt_with_latest_sdk.bat) which can be used to auto detect the newest available SDK 15 | installed on the host machine and then open the project using that as the compilation SDK. 16 | 17 | When using the WinRT/UWP project configurations the projects will automatically compile towards 18 | the default application target for the Version of Visual Studio being used: 19 | VS 2013: 8.1 20 | VS 2015: 8.1 21 | VS 2017+: 10.0.10240.0 22 | 23 | -------------------------------------------------------------------------------- /SMP/version.h: -------------------------------------------------------------------------------- 1 | /* Define to the version of this package. */ 2 | #define PACKAGE_VERSION "1.11.0" 3 | 4 | /* Version of this package */ 5 | #define VERSION "1.11.0" 6 | 7 | /* GIT commit id revision used to build this package */ 8 | #define BUILD_REVISION "9d94d78" 9 | 10 | /* The time this package was configured for a build */ 11 | #define BUILD_TIMESTAMP "2024-06-29T11:20+0000" 12 | -------------------------------------------------------------------------------- /SMP/versioninfo.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/libgcrypt/4a997384e4bf0bb04e0fb6c61976c67c27bc8612/SMP/versioninfo.rc -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | # What's left to do -*- org -*- 2 | 3 | * Next API break: 4 | ** gcry_ac_io_t 5 | Remove use of anonymous union. 6 | ** gcry_ac 7 | Consider to remove it. 8 | 9 | * udiv-qrnbd.o should get build as *.lo [HPUX] 10 | 11 | * Allow operation using RSA keys consisting of the OpenSSL keys. 12 | This requires the introduction of a parameter names (say) U which 13 | is calculated according to OpenSSL/PKCS#1 rules. 14 | 15 | * linker script test 16 | Write an autoconf test to check whether the linker supports a 17 | version script. 18 | 19 | * Add attributes to the MPI functions. 20 | 21 | * cipher/pubkey.c and pubkey implementations. 22 | Don't rely on the secure memory based wiping function but add an 23 | extra wiping. 24 | 25 | * Use builtin bit functions of gcc 3.4 26 | 27 | * Consider using a daemon to maintain the random pool 28 | [Partly done] The down side of this is that we can't assume that the 29 | random has has always been stored in "secure memory". And we rely 30 | on that sniffing of Unix domain sockets is not possible. We can 31 | implement this simply by detecting a special prefixed random seed 32 | name and divert in this case to the daemon. There are several 33 | benefits with such an approach: We keep the state of the RNG over 34 | invocations of libgcrypt based applications, don't need time 35 | consuming initialization of the pool and in case the entropy 36 | collectros need to run that bunch of Unix utilities we don't waste 37 | their precious results. 38 | 39 | * gcryptrnd.c 40 | Requires a test for pth [done] as well as some other tests. 41 | 42 | * secmem.c 43 | Check whether the memory block is valid before releasing it and 44 | print a diagnosic, like glibc does. 45 | 46 | * threads 47 | ** We need to document fork problems 48 | In particular that reinitialization is required in random.c 49 | However, there is no code yet to do it. 50 | 51 | * Tests 52 | We need a lot more tests. Lets keep an ever growing list here. 53 | ** Write tests for the progress function 54 | ** mpitests does no real checks yet. 55 | ** pthreads 56 | To catch simple errors like the one fixed on 2007-03-16. 57 | ** C++ tests 58 | We have some code to allow using libgcrypt from C++, so we also 59 | should have a test case. 60 | -------------------------------------------------------------------------------- /autogen.rc: -------------------------------------------------------------------------------- 1 | # autogen.sh configuration for Libgcrypt -*- sh -*- 2 | 3 | case "$myhost" in 4 | w32) 5 | configure_opts="" 6 | ;; 7 | 8 | amd64) 9 | configure_opts="" 10 | ;; 11 | esac 12 | 13 | final_info="./configure --enable-maintainer-mode && make" 14 | -------------------------------------------------------------------------------- /build-aux/distfiles: -------------------------------------------------------------------------------- 1 | db2any 2 | -------------------------------------------------------------------------------- /build-aux/git-log-fix: -------------------------------------------------------------------------------- 1 | # This file is expected to be used via gitlog-to-changelog's --amend=FILE 2 | # option. It specifies what changes to make to each given SHA1's commit 3 | # log and metadata, using Perl-eval'able expressions. 4 | 5 | eb4937914db3fb7317502e97e4f0e40c1857f59d 6 | # Fix bad formatted entry dated 2013-05-20 7 | s/(?s)mpi_sub.*$/cipher: Fix segv in last ECC change. 8 | * cipher\/ecc.c (generate_key): Make sure R is initialized./ 9 | 10 | 296f38a2bd2e25788643a42e4881faed00884a40 11 | # Fix bad formatted entry dated 2013-05-09 12 | s/(?s)Generate ECC.*$/cipher: Generate compliant ECC keys. 13 | * cipher\/ecc.c (generate_key): Make sure a key is compliant for 14 | using the compact representation./ 15 | -------------------------------------------------------------------------------- /build-aux/git-log-footer: -------------------------------------------------------------------------------- 1 | 2 | 2011-12-01 Werner Koch 3 | 4 | NB: Changes done before December 1st, 2011 are described in 5 | per directory files named ChangeLog-2011. See doc/HACKING for 6 | details. 7 | 8 | ----- 9 | Copyright (C) 2011 Free Software Foundation, Inc. 10 | 11 | Copying and distribution of this file and/or the original GIT 12 | commit log messages, with or without modification, are 13 | permitted provided the copyright notice and this notice are 14 | preserved. 15 | -------------------------------------------------------------------------------- /build-aux/libtool-patch.sed: -------------------------------------------------------------------------------- 1 | # 2 | # This is a sed script to patch the generated libtool, 3 | # which works well against both of libtool 2.4.2 and 2.4.7. 4 | # 5 | # You may use this work under the terms of a Creative Commons CC0 1.0 6 | # License/Waiver. 7 | # 8 | # CC0 Public Domain Dedication 9 | # https://creativecommons.org/publicdomain/zero/1.0/ 10 | 11 | # 12 | # This sed script applys two hunks of the patch: 13 | # 14 | # Part1: after the comment "# bleh windows" 15 | # Part2: after the comment "#extension on DOS 8.3..." 16 | # 17 | # Only when those two parts are patched correctly, it exits with 0 or 18 | # else, it exits with 1 19 | # 20 | 21 | # Find the part 1, by the comment 22 | /^[ \t]*# bleh windows$/b part1_start 23 | # Not found the part1, raise an error 24 | $ q1 25 | b 26 | 27 | :part1_start 28 | n 29 | # The first line in the part 1 must be the begining of the case statement. 30 | /^[ \t]*case \$host in$/! q1 31 | n 32 | # Insert the entry for x86_64-*mingw32*, for modified versuffix. 33 | i\ 34 | x86_64-*mingw32*) 35 | i\ 36 | func_arith $current - $age 37 | i\ 38 | major=$func_arith_result 39 | i\ 40 | versuffix="6-$major" 41 | i\ 42 | ;; 43 | :part1_0 44 | # Find the end of the case statement 45 | /^[ \t]*esac$/b find_part2 46 | # Not found the end of the case statement, raise an error 47 | $ q1 48 | n 49 | b part1_0 50 | 51 | :find_part2 52 | /^[ \t]*# extension on DOS 8.3 file.*systems.$/b part2_process 53 | # Not found the part2, raise an error 54 | $ q1 55 | n 56 | b find_part2 57 | 58 | :part2_process 59 | $ q1 60 | s/^[ \t]*\(versuffix=\)\(.*\)\(-$major\)\(.*\)$/\t case \$host in\n\t x86_64-*mingw32*)\n\t \1\26\3\4\n\t ;;\n\t *)\n\t \1\2\3\4\n\t ;;\n\t esac/ 61 | t part2_done 62 | n 63 | b part2_process 64 | 65 | :part2_done 66 | $ q0 67 | n 68 | b part2_done 69 | -------------------------------------------------------------------------------- /cipher/camellia-aarch64-ce.c: -------------------------------------------------------------------------------- 1 | /* camellia-aarch64-ce.c - ARMv8/CE Camellia implementation 2 | * Copyright (C) 2023 Jussi Kivilinna 3 | * 4 | * This file is part of Libgcrypt. 5 | * 6 | * Libgcrypt is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Libgcrypt is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | */ 19 | 20 | #include 21 | 22 | #if defined(__AARCH64EL__) && \ 23 | defined(HAVE_COMPATIBLE_GCC_AARCH64_PLATFORM_AS) && \ 24 | defined(HAVE_GCC_INLINE_ASM_AARCH64_CRYPTO) && \ 25 | defined(HAVE_COMPATIBLE_CC_AARCH64_NEON_INTRINSICS) && \ 26 | (__GNUC__ >= 4) 27 | 28 | #ifdef HAVE_GCC_ATTRIBUTE_OPTIMIZE 29 | # define FUNC_ATTR_OPT __attribute__((optimize("-O2"))) 30 | #else 31 | # define FUNC_ATTR_OPT 32 | #endif 33 | 34 | #define SIMD128_OPT_ATTR FUNC_ATTR_OPT 35 | 36 | #define FUNC_ENC_BLK16 _gcry_camellia_aarch64ce_encrypt_blk16 37 | #define FUNC_DEC_BLK16 _gcry_camellia_aarch64ce_decrypt_blk16 38 | #define FUNC_KEY_SETUP _gcry_camellia_aarch64ce_keygen 39 | 40 | #include "camellia-simd128.h" 41 | 42 | #endif /* __AARCH64EL__ */ 43 | -------------------------------------------------------------------------------- /cipher/camellia-aesni-avx2-amd64.S: -------------------------------------------------------------------------------- 1 | /* camellia-aesni-avx2-amd64.S - AES-NI/AVX2 implementation of Camellia cipher 2 | * 3 | * Copyright (C) 2021 Jussi Kivilinna 4 | * 5 | * This file is part of Libgcrypt. 6 | * 7 | * Libgcrypt is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation; either version 2.1 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * Libgcrypt is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this program; if not, see . 19 | */ 20 | 21 | #include 22 | 23 | #ifdef __x86_64 24 | #if (defined(HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS) || \ 25 | defined(HAVE_COMPATIBLE_GCC_WIN64_PLATFORM_AS)) && \ 26 | defined(ENABLE_AESNI_SUPPORT) && defined(ENABLE_AVX2_SUPPORT) 27 | 28 | #undef CAMELLIA_VAES_BUILD 29 | #define FUNC_NAME(func) _gcry_camellia_aesni_avx2_ ## func 30 | 31 | #include "camellia-aesni-avx2-amd64.h" 32 | 33 | #endif /* defined(ENABLE_AESNI_SUPPORT) && defined(ENABLE_AVX2_SUPPORT) */ 34 | #endif /* __x86_64 */ 35 | -------------------------------------------------------------------------------- /cipher/camellia-gfni-avx2-amd64.S: -------------------------------------------------------------------------------- 1 | /* camellia-vaes-avx2-amd64.S - GFNI/AVX2 implementation of Camellia cipher 2 | * 3 | * Copyright (C) 2022 Jussi Kivilinna 4 | * 5 | * This file is part of Libgcrypt. 6 | * 7 | * Libgcrypt is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation; either version 2.1 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * Libgcrypt is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this program; if not, see . 19 | */ 20 | 21 | #include 22 | 23 | #ifdef __x86_64 24 | #if (defined(HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS) || \ 25 | defined(HAVE_COMPATIBLE_GCC_WIN64_PLATFORM_AS)) && \ 26 | defined(ENABLE_GFNI_SUPPORT) && defined(ENABLE_AVX2_SUPPORT) 27 | 28 | #define CAMELLIA_GFNI_BUILD 1 29 | #define FUNC_NAME(func) _gcry_camellia_gfni_avx2_ ## func 30 | 31 | #include "camellia-aesni-avx2-amd64.h" 32 | 33 | #endif /* defined(ENABLE_GFNI_SUPPORT) && defined(ENABLE_AVX2_SUPPORT) */ 34 | #endif /* __x86_64 */ 35 | -------------------------------------------------------------------------------- /cipher/camellia-ppc8le.c: -------------------------------------------------------------------------------- 1 | /* camellia-ppc8le.c - POWER8 Vector Crypto Camellia implementation 2 | * Copyright (C) 2023 Jussi Kivilinna 3 | * 4 | * This file is part of Libgcrypt. 5 | * 6 | * Libgcrypt is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Libgcrypt is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | */ 19 | 20 | #include 21 | 22 | #if !defined(WORDS_BIGENDIAN) && defined(ENABLE_PPC_CRYPTO_SUPPORT) && \ 23 | defined(HAVE_COMPATIBLE_CC_PPC_ALTIVEC) && \ 24 | defined(HAVE_GCC_INLINE_ASM_PPC_ALTIVEC) && \ 25 | (SIZEOF_UNSIGNED_LONG == 8) && (__GNUC__ >= 4) 26 | 27 | #ifdef HAVE_GCC_ATTRIBUTE_OPTIMIZE 28 | # define FUNC_ATTR_OPT __attribute__((optimize("-O2"))) 29 | #else 30 | # define FUNC_ATTR_OPT 31 | #endif 32 | 33 | #if defined(__clang__) && defined(HAVE_CLANG_ATTRIBUTE_PPC_TARGET) 34 | # define SIMD128_OPT_ATTR __attribute__((target("arch=pwr8"))) FUNC_ATTR_OPT 35 | #elif defined(HAVE_GCC_ATTRIBUTE_PPC_TARGET) 36 | # define SIMD128_OPT_ATTR __attribute__((target("cpu=power8"))) FUNC_ATTR_OPT 37 | #else 38 | # define SIMD128_OPT_ATTR FUNC_ATTR_OPT 39 | #endif 40 | 41 | #define FUNC_ENC_BLK16 _gcry_camellia_ppc8_encrypt_blk16 42 | #define FUNC_DEC_BLK16 _gcry_camellia_ppc8_decrypt_blk16 43 | #define FUNC_KEY_SETUP _gcry_camellia_ppc8_keygen 44 | 45 | #include "camellia-simd128.h" 46 | 47 | #endif /* ENABLE_PPC_CRYPTO_SUPPORT */ 48 | -------------------------------------------------------------------------------- /cipher/camellia-ppc9le.c: -------------------------------------------------------------------------------- 1 | /* camellia-ppc9le.c - POWER9 Vector Crypto Camellia implementation 2 | * Copyright (C) 2023 Jussi Kivilinna 3 | * 4 | * This file is part of Libgcrypt. 5 | * 6 | * Libgcrypt is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Libgcrypt is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | */ 19 | 20 | #include 21 | 22 | #if !defined(WORDS_BIGENDIAN) && defined(ENABLE_PPC_CRYPTO_SUPPORT) && \ 23 | defined(HAVE_COMPATIBLE_CC_PPC_ALTIVEC) && \ 24 | defined(HAVE_GCC_INLINE_ASM_PPC_ALTIVEC) && \ 25 | (SIZEOF_UNSIGNED_LONG == 8) && (__GNUC__ >= 4) 26 | 27 | #ifdef HAVE_GCC_ATTRIBUTE_OPTIMIZE 28 | # define FUNC_ATTR_OPT __attribute__((optimize("-O2"))) 29 | #else 30 | # define FUNC_ATTR_OPT 31 | #endif 32 | 33 | #if defined(__clang__) && defined(HAVE_CLANG_ATTRIBUTE_PPC_TARGET) 34 | # define SIMD128_OPT_ATTR __attribute__((target("arch=pwr9"))) FUNC_ATTR_OPT 35 | #elif defined(HAVE_GCC_ATTRIBUTE_PPC_TARGET) 36 | # define SIMD128_OPT_ATTR __attribute__((target("cpu=power9"))) FUNC_ATTR_OPT 37 | #else 38 | # define SIMD128_OPT_ATTR FUNC_ATTR_OPT 39 | #endif 40 | 41 | #define FUNC_ENC_BLK16 _gcry_camellia_ppc9_encrypt_blk16 42 | #define FUNC_DEC_BLK16 _gcry_camellia_ppc9_decrypt_blk16 43 | #define FUNC_KEY_SETUP _gcry_camellia_ppc9_keygen 44 | 45 | #include "camellia-simd128.h" 46 | 47 | #endif /* ENABLE_PPC_CRYPTO_SUPPORT */ 48 | -------------------------------------------------------------------------------- /cipher/camellia-vaes-avx2-amd64.S: -------------------------------------------------------------------------------- 1 | /* camellia-vaes-avx2-amd64.S - VAES/AVX2 implementation of Camellia cipher 2 | * 3 | * Copyright (C) 2021 Jussi Kivilinna 4 | * 5 | * This file is part of Libgcrypt. 6 | * 7 | * Libgcrypt is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation; either version 2.1 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * Libgcrypt is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this program; if not, see . 19 | */ 20 | 21 | #include 22 | 23 | #ifdef __x86_64 24 | #if (defined(HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS) || \ 25 | defined(HAVE_COMPATIBLE_GCC_WIN64_PLATFORM_AS)) && \ 26 | defined(ENABLE_AESNI_SUPPORT) && defined(ENABLE_AVX2_SUPPORT) && \ 27 | defined(HAVE_GCC_INLINE_ASM_VAES_VPCLMUL) 28 | 29 | #define CAMELLIA_VAES_BUILD 1 30 | #define FUNC_NAME(func) _gcry_camellia_vaes_avx2_ ## func 31 | 32 | #include "camellia-aesni-avx2-amd64.h" 33 | 34 | #endif /* defined(ENABLE_AESNI_SUPPORT) && defined(ENABLE_AVX2_SUPPORT) */ 35 | #endif /* __x86_64 */ 36 | -------------------------------------------------------------------------------- /cipher/gost.h: -------------------------------------------------------------------------------- 1 | /* gost.h - GOST 28147-89 implementation 2 | * Copyright (C) 2012 Free Software Foundation, Inc. 3 | * 4 | * This file is part of Libgcrypt. 5 | * 6 | * Libgcrypt is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Libgcrypt is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | */ 19 | 20 | #ifndef _GCRY_GOST_H 21 | #define _GCRY_GOST_H 22 | 23 | typedef struct { 24 | u32 key[8]; 25 | const u32 *sbox; 26 | unsigned int mesh_counter; 27 | unsigned int mesh_limit; 28 | } GOST28147_context; 29 | 30 | /* This is a simple interface that will be used by GOST R 34.11-94 */ 31 | unsigned int _gcry_gost_enc_data (const u32 *key, 32 | u32 *o1, u32 *o2, u32 n1, u32 n2, int cryptopro); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /cipher/hash-common.h: -------------------------------------------------------------------------------- 1 | /* hash-common.h - Declarations of common code for hash algorithms. 2 | * Copyright (C) 2008 Free Software Foundation, Inc. 3 | * 4 | * This file is part of Libgcrypt. 5 | * 6 | * Libgcrypt is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Libgcrypt is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | */ 19 | 20 | #ifndef GCRY_HASH_COMMON_H 21 | #define GCRY_HASH_COMMON_H 22 | 23 | #include "types.h" 24 | 25 | 26 | const char * _gcry_hash_selftest_check_one 27 | /**/ (int algo, 28 | int datamode, const void *data, size_t datalen, 29 | const void *expect, size_t expectlen); 30 | 31 | /* Type for the md_write helper function. */ 32 | typedef unsigned int (*_gcry_md_block_write_t) (void *c, 33 | const unsigned char *blks, 34 | size_t nblks); 35 | 36 | #if (defined(USE_SHA512) || defined(USE_WHIRLPOOL)) 37 | /* SHA-512 and Whirlpool needs u64. SHA-512 needs larger buffer. */ 38 | # define MD_BLOCK_MAX_BLOCKSIZE 128 39 | # define MD_NBLOCKS_TYPE u64 40 | #else 41 | # define MD_BLOCK_MAX_BLOCKSIZE 64 42 | # define MD_NBLOCKS_TYPE u32 43 | #endif 44 | 45 | /* SHA1 needs 2x64 bytes and SHA-512 needs 128 bytes. */ 46 | #define MD_BLOCK_CTX_BUFFER_SIZE 128 47 | 48 | typedef struct gcry_md_block_ctx 49 | { 50 | byte buf[MD_BLOCK_CTX_BUFFER_SIZE]; 51 | MD_NBLOCKS_TYPE nblocks; 52 | MD_NBLOCKS_TYPE nblocks_high; 53 | int count; 54 | unsigned int blocksize_shift; 55 | _gcry_md_block_write_t bwrite; 56 | } gcry_md_block_ctx_t; 57 | 58 | 59 | void 60 | _gcry_md_block_write( void *context, const void *inbuf_arg, size_t inlen); 61 | 62 | #endif /*GCRY_HASH_COMMON_H*/ 63 | -------------------------------------------------------------------------------- /cipher/kdf-internal.h: -------------------------------------------------------------------------------- 1 | /* kdf-internal.h - Internal defs for kdf.c 2 | * Copyright (C) 2013 g10 Code GmbH 3 | * 4 | * This file is part of Libgcrypt. 5 | * 6 | * Libgcrypt is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Libgcrypt is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | */ 19 | 20 | #ifndef GCRY_KDF_INTERNAL_H 21 | #define GCRY_KDF_INTERNAL_H 22 | 23 | /*-- kdf.c --*/ 24 | gpg_err_code_t 25 | _gcry_kdf_pkdf2 (const void *passphrase, size_t passphraselen, 26 | int hashalgo, 27 | const void *salt, size_t saltlen, 28 | unsigned long iterations, 29 | size_t keysize, void *keybuffer); 30 | 31 | /*-- scrypt.c --*/ 32 | gcry_err_code_t 33 | _gcry_kdf_scrypt (const unsigned char *passwd, size_t passwdlen, 34 | int algo, int subalgo, 35 | const unsigned char *salt, size_t saltlen, 36 | unsigned long iterations, 37 | size_t dklen, unsigned char *dk); 38 | 39 | #endif /*GCRY_KDF_INTERNAL_H*/ 40 | -------------------------------------------------------------------------------- /cipher/kem-ecc.h: -------------------------------------------------------------------------------- 1 | /* kem-ecc.h - Key Encapsulation Mechanism with ECC 2 | * Copyright (C) 2024 g10 Code GmbH 3 | * 4 | * This file is part of Libgcrypt. 5 | * 6 | * Libgcrypt is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser general Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Libgcrypt is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | * 20 | */ 21 | 22 | gpg_err_code_t _gcry_ecc_raw_keypair (int algo, 23 | void *pubkey, size_t pubkey_len, 24 | void *seckey, size_t seckey_len); 25 | gpg_err_code_t _gcry_ecc_raw_encap (int algo, 26 | const void *pubkey, size_t pubkey_len, 27 | void *ciphertext, size_t ciphertext_len, 28 | void *shared, size_t shared_len); 29 | gpg_err_code_t _gcry_ecc_raw_decap (int algo, 30 | const void *seckey, size_t seckey_len, 31 | const void *ciphertext, 32 | size_t ciphertext_len, 33 | void *shared, size_t shared_len); 34 | 35 | gpg_err_code_t _gcry_ecc_dhkem_encap (int algo, const void *pubkey, 36 | void *ciphertext, 37 | void *shared); 38 | gpg_err_code_t _gcry_ecc_dhkem_decap (int algo, const void *seckey, 39 | const void *ciphertext, 40 | void *shared, const void *optional); 41 | -------------------------------------------------------------------------------- /cipher/mceliece6688128f.h: -------------------------------------------------------------------------------- 1 | /* mceliece6688128f.h - Classic McEliece for libgcrypt 2 | * Copyright (C) 2023-2024 Simon Josefsson 3 | * 4 | * This file is part of Libgcrypt. 5 | * 6 | * Libgcrypt is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Libgcrypt is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | * 20 | */ 21 | 22 | #ifndef MCELIECE6688128F_H 23 | #define MCELIECE6688128F_H 24 | 25 | #include 26 | #include 27 | 28 | #ifdef _GCRYPT_IN_LIBGCRYPT 29 | /**** Start of the glue code to libgcrypt ****/ 30 | #include "g10lib.h" /* for GCC_ATTR_UNUSED */ 31 | #include "gcrypt-int.h" 32 | 33 | #define mceliece6688128f_keypair _gcry_mceliece6688128f_keypair 34 | #define mceliece6688128f_enc _gcry_mceliece6688128f_enc 35 | #define mceliece6688128f_dec _gcry_mceliece6688128f_dec 36 | /**** End of the glue code ****/ 37 | #else 38 | #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 5 ) 39 | #define GCC_ATTR_UNUSED __attribute__ ((unused)) 40 | #else 41 | #define GCC_ATTR_UNUSED 42 | #endif 43 | 44 | #define MCELIECE6688128F_SECRETKEY_SIZE 13932 45 | #define MCELIECE6688128F_PUBLICKEY_SIZE 1044992 46 | #define MCELIECE6688128F_CIPHERTEXT_SIZE 208 47 | #define MCELIECE6688128F_SIZE 32 48 | #endif 49 | 50 | typedef void mceliece6688128f_random_func (void *ctx, 51 | size_t length, 52 | uint8_t *dst); 53 | 54 | void 55 | mceliece6688128f_keypair (uint8_t *pk, uint8_t *sk); 56 | 57 | void 58 | mceliece6688128f_enc (uint8_t *c, uint8_t *k, const uint8_t *pk); 59 | 60 | void 61 | mceliece6688128f_dec (uint8_t *k, const uint8_t *c, const uint8_t *sk); 62 | 63 | #endif /* MCELIECE6688128F_H */ 64 | -------------------------------------------------------------------------------- /cipher/poly1305-internal.h: -------------------------------------------------------------------------------- 1 | /* poly1305-internal.h - Poly1305 internals 2 | * Copyright (C) 2014 Jussi Kivilinna 3 | * 4 | * This file is part of Libgcrypt. 5 | * 6 | * Libgcrypt is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Libgcrypt is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | */ 19 | 20 | #ifndef G10_POLY1305_INTERNAL_H 21 | #define G10_POLY1305_INTERNAL_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include "types.h" 28 | #include "g10lib.h" 29 | #include "cipher.h" 30 | #include "bufhelp.h" 31 | 32 | #define POLY1305_TAGLEN 16 33 | #define POLY1305_KEYLEN 32 34 | #define POLY1305_BLOCKSIZE 16 35 | 36 | 37 | /* POLY1305_USE_AVX512 indicates whether to compile with Intel AVX512 code. */ 38 | #undef POLY1305_USE_AVX512 39 | #if defined(__x86_64__) && defined(HAVE_GCC_INLINE_ASM_AVX512) && \ 40 | defined(HAVE_INTEL_SYNTAX_PLATFORM_AS) && \ 41 | (defined(HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS) || \ 42 | defined(HAVE_COMPATIBLE_GCC_WIN64_PLATFORM_AS)) 43 | # define POLY1305_USE_AVX512 1 44 | #endif 45 | 46 | /* POLY1305_USE_PPC_VEC indicates whether to enable PowerPC vector code. */ 47 | #undef POLY1305_USE_PPC_VEC 48 | #ifdef ENABLE_PPC_CRYPTO_SUPPORT 49 | # if defined(HAVE_COMPATIBLE_CC_PPC_ALTIVEC) && \ 50 | defined(HAVE_GCC_INLINE_ASM_PPC_ALTIVEC) && \ 51 | !defined(WORDS_BIGENDIAN) 52 | # if __GNUC__ >= 4 53 | # define POLY1305_USE_PPC_VEC 1 54 | # endif 55 | # endif 56 | #endif 57 | 58 | 59 | typedef struct 60 | { 61 | u32 k[4]; 62 | u32 r[4]; 63 | u32 h[5]; 64 | } POLY1305_STATE; 65 | 66 | typedef struct poly1305_context_s 67 | { 68 | POLY1305_STATE state; 69 | byte buffer[POLY1305_BLOCKSIZE]; 70 | unsigned int leftover; 71 | #ifdef POLY1305_USE_AVX512 72 | unsigned int use_avx512:1; 73 | #endif 74 | #ifdef POLY1305_USE_PPC_VEC 75 | unsigned int use_p10:1; 76 | #endif 77 | } poly1305_context_t; 78 | 79 | 80 | gcry_err_code_t _gcry_poly1305_init (poly1305_context_t *ctx, const byte *key, 81 | size_t keylen); 82 | 83 | void _gcry_poly1305_finish (poly1305_context_t *ctx, 84 | byte mac[POLY1305_TAGLEN]); 85 | 86 | void _gcry_poly1305_update (poly1305_context_t *ctx, const byte *buf, 87 | size_t buflen); 88 | 89 | unsigned int _gcry_poly1305_update_burn (poly1305_context_t *ctx, 90 | const byte *m, size_t bytes); 91 | 92 | #endif /* G10_POLY1305_INTERNAL_H */ 93 | -------------------------------------------------------------------------------- /cipher/poly1305-s390x.S: -------------------------------------------------------------------------------- 1 | /* poly1305-s390x.S - zSeries implementation of Poly1305 2 | * 3 | * Copyright (C) 2020 Jussi Kivilinna 4 | * 5 | * This file is part of Libgcrypt. 6 | * 7 | * Libgcrypt is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation; either version 2.1 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * Libgcrypt is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this program; if not, see . 19 | */ 20 | 21 | #include 22 | #if defined (__s390x__) && __GNUC__ >= 4 && __ARCH__ >= 9 23 | #if defined(HAVE_GCC_INLINE_ASM_S390X) 24 | 25 | #include "asm-poly1305-s390x.h" 26 | 27 | .text 28 | 29 | .balign 16 30 | .globl _gcry_poly1305_s390x_blocks1 31 | ELF(.type _gcry_poly1305_s390x_blocks1,@function;) 32 | 33 | _gcry_poly1305_s390x_blocks1: 34 | /* input: 35 | * %r2: poly1305-state 36 | * %r3: src 37 | * %r4: len 38 | * %r5: high_pad 39 | */ 40 | CFI_STARTPROC(); 41 | 42 | stmg %r6, %r14, 6 * 8(%r15); 43 | 44 | lgr POLY_RSTATE, %r2; 45 | lgr POLY_RSRC, %r3; 46 | srlg %r0, %r4, 4; 47 | 48 | cgije %r5, 0, .Lpoly_high0; 49 | 50 | POLY1305_LOAD_STATE(); 51 | 52 | .balign 4 53 | .Lpoly_loop_high1: 54 | POLY1305_BLOCK_PART1(0 * 16); 55 | INC_POLY1305_SRC(1 * 16); 56 | .Lpoly_block_part2: 57 | POLY1305_BLOCK_PART2(); 58 | POLY1305_BLOCK_PART3(); 59 | POLY1305_BLOCK_PART4(); 60 | POLY1305_BLOCK_PART5(); 61 | POLY1305_BLOCK_PART6(); 62 | POLY1305_BLOCK_PART7(); 63 | POLY1305_BLOCK_PART8(); 64 | 65 | brctg %r0, .Lpoly_loop_high1; 66 | 67 | .balign 4 68 | .Lpoly_done: 69 | POLY1305_STORE_STATE(); 70 | 71 | lmg %r6, %r14, 6 * 8(%r15); 72 | xgr %r2, %r2; 73 | br %r14; 74 | 75 | .balign 4 76 | .Lpoly_high0: 77 | lghi %r0, 1; 78 | POLY1305_LOAD_STATE(); 79 | POLY1305_BLOCK_PART1_HB(0 * 16, 0); 80 | j .Lpoly_block_part2; 81 | 82 | CFI_ENDPROC(); 83 | ELF(.size _gcry_poly1305_s390x_blocks1, 84 | .-_gcry_poly1305_s390x_blocks1;) 85 | 86 | #endif /*HAVE_GCC_INLINE_ASM_S390X*/ 87 | #endif /*__s390x__*/ 88 | -------------------------------------------------------------------------------- /cipher/sha1.h: -------------------------------------------------------------------------------- 1 | /* sha1.h - SHA-1 context definition 2 | * Copyright (C) 1998, 2001, 2002, 2003, 2008 Free Software Foundation, Inc. 3 | * 4 | * This file is part of Libgcrypt. 5 | * 6 | * Libgcrypt is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Libgcrypt is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | */ 19 | #ifndef GCRY_SHA1_H 20 | #define GCRY_SHA1_H 21 | 22 | #include "hash-common.h" 23 | 24 | 25 | /* SHA1_USE_S390X_CRYPTO indicates whether to enable zSeries code. */ 26 | #undef SHA1_USE_S390X_CRYPTO 27 | #if defined(HAVE_GCC_INLINE_ASM_S390X) 28 | # define SHA1_USE_S390X_CRYPTO 1 29 | #endif /* SHA1_USE_S390X_CRYPTO */ 30 | 31 | 32 | /* We need this here for direct use by random-csprng.c. */ 33 | typedef struct 34 | { 35 | gcry_md_block_ctx_t bctx; 36 | u32 h0,h1,h2,h3,h4; 37 | #ifdef SHA1_USE_S390X_CRYPTO 38 | u32 final_len_msb, final_len_lsb; /* needs to be right after h4. */ 39 | int use_s390x_crypto; 40 | #endif 41 | } SHA1_CONTEXT; 42 | 43 | 44 | void _gcry_sha1_mixblock_init (SHA1_CONTEXT *hd); 45 | unsigned int _gcry_sha1_mixblock (SHA1_CONTEXT *hd, void *blockof64byte); 46 | 47 | #endif /*GCRY_SHA1_H*/ 48 | -------------------------------------------------------------------------------- /cipher/sntrup761.h: -------------------------------------------------------------------------------- 1 | /* sntrup761.h - Streamlined NTRU Prime sntrup761 key-encapsulation method 2 | * Copyright (C) 2023 Simon Josefsson 3 | * 4 | * This file is part of Libgcrypt. 5 | * 6 | * Libgcrypt is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Libgcrypt is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | * 20 | * For a description of the algorithm, see: 21 | * https://ntruprime.cr.yp.to/ 22 | */ 23 | 24 | /* 25 | * Derived from public domain source, written by (in alphabetical order): 26 | * - Daniel J. Bernstein 27 | * - Chitchanok Chuengsatiansup 28 | * - Tanja Lange 29 | * - Christine van Vredendaal 30 | */ 31 | 32 | #ifndef SNTRUP761_H 33 | #define SNTRUP761_H 34 | 35 | #include 36 | #include 37 | 38 | #ifdef _GCRYPT_IN_LIBGCRYPT 39 | /**** Start of the glue code to libgcrypt ****/ 40 | #include "gcrypt-int.h" 41 | 42 | static inline void 43 | crypto_hash_sha512 (unsigned char *out, 44 | const unsigned char *in, size_t inlen) 45 | { 46 | _gcry_md_hash_buffer (GCRY_MD_SHA512, out, in, inlen); 47 | } 48 | 49 | #define sntrup761_keypair _gcry_sntrup761_keypair 50 | #define sntrup761_enc _gcry_sntrup761_enc 51 | #define sntrup761_dec _gcry_sntrup761_dec 52 | /**** End of the glue code ****/ 53 | #else 54 | #define SNTRUP761_SECRETKEY_SIZE 1763 55 | #define SNTRUP761_PUBLICKEY_SIZE 1158 56 | #define SNTRUP761_CIPHERTEXT_SIZE 1039 57 | #define SNTRUP761_SIZE 32 58 | #endif 59 | 60 | typedef void sntrup761_random_func (void *ctx, size_t length, uint8_t *dst); 61 | 62 | void 63 | sntrup761_keypair (uint8_t *pk, uint8_t *sk, 64 | void *random_ctx, sntrup761_random_func *random); 65 | 66 | void 67 | sntrup761_enc (uint8_t *c, uint8_t *k, const uint8_t *pk, 68 | void *random_ctx, sntrup761_random_func *random); 69 | 70 | void 71 | sntrup761_dec (uint8_t *k, const uint8_t *c, const uint8_t *sk); 72 | 73 | #endif /* SNTRUP761_H */ 74 | -------------------------------------------------------------------------------- /cipher/test-getrusage.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int 6 | main (int argc, char **argv) 7 | { 8 | struct rusage buf; 9 | 10 | if (argc > 1) 11 | { 12 | system (argv[1]); 13 | 14 | if (getrusage (RUSAGE_CHILDREN, &buf )) 15 | { 16 | perror ("getrusage"); 17 | return 1; 18 | } 19 | } 20 | else 21 | { 22 | if (getrusage (RUSAGE_SELF, &buf )) 23 | { 24 | perror ("getrusage"); 25 | return 1; 26 | } 27 | } 28 | 29 | printf ("ru_utime = %ld.%06ld\n", 30 | buf.ru_utime.tv_sec, buf.ru_utime.tv_usec); 31 | printf ("ru_stime = %ld.%06ld\n", 32 | buf.ru_stime.tv_sec, buf.ru_stime.tv_usec); 33 | printf ("ru_maxrss = %ld\n", buf.ru_maxrss ); 34 | printf ("ru_ixrss = %ld\n", buf.ru_ixrss ); 35 | printf ("ru_idrss = %ld\n", buf.ru_idrss ); 36 | printf ("ru_isrss = %ld\n", buf.ru_isrss ); 37 | printf ("ru_minflt = %ld\n", buf.ru_minflt ); 38 | printf ("ru_majflt = %ld\n", buf.ru_majflt ); 39 | printf ("ru_nswap = %ld\n", buf.ru_nswap ); 40 | printf ("ru_inblock = %ld\n", buf.ru_inblock ); 41 | printf ("ru_oublock = %ld\n", buf.ru_oublock ); 42 | printf ("ru_msgsnd = %ld\n", buf.ru_msgsnd ); 43 | printf ("ru_msgrcv = %ld\n", buf.ru_msgrcv ); 44 | printf ("ru_nsignals= %ld\n", buf.ru_nsignals ); 45 | printf ("ru_nvcsw = %ld\n", buf.ru_nvcsw ); 46 | printf ("ru_nivcsw = %ld\n", buf.ru_nivcsw ); 47 | 48 | return 0; 49 | } 50 | 51 | 52 | /* Codesnippet for debugging in random.c. */ 53 | #if 0 54 | static void 55 | collect_rusage_stats (struct rusage *rb) 56 | { 57 | static int idx; 58 | static struct rusage buf[100]; 59 | 60 | if (!rb) 61 | { 62 | int i; 63 | 64 | fprintf (stderr, "ru_utime ru_stime ru_minflt ru_nvcsw ru_nivcsw\n"); 65 | for (i=0; i < idx; i++) 66 | fprintf (stderr, "%ld.%06ld %ld.%06ld %5ld %5ld %5ld\n", 67 | buf[i].ru_utime.tv_sec, buf[i].ru_utime.tv_usec, 68 | buf[i].ru_stime.tv_sec, buf[i].ru_stime.tv_usec, 69 | buf[i].ru_minflt, 70 | buf[i].ru_nvcsw, 71 | buf[i].ru_nivcsw); 72 | } 73 | else if (idx < DIM(buf)) 74 | { 75 | buf[idx++] = *rb; 76 | } 77 | } 78 | #endif 79 | /* 80 | void 81 | _gcry_random_dump_stats() 82 | { 83 | @@ -233,8 +261,11 @@ 84 | rndstats.naddbytes, rndstats.addbytes, 85 | rndstats.mixkey, rndstats.ngetbytes1, rndstats.getbytes1, 86 | rndstats.ngetbytes2, rndstats.getbytes2 ); 87 | + 88 | + collect_rusage_stats (NULL); 89 | } 90 | 91 | ======== 92 | 93 | getrusage (RUSAGE_SELF, &buf ); 94 | + collect_rusage_stats (&buf); 95 | add_randomness( &buf, sizeof buf, 1 ); 96 | memset( &buf, 0, sizeof buf ); 97 | } 98 | 99 | */ 100 | -------------------------------------------------------------------------------- /compat/Makefile.am: -------------------------------------------------------------------------------- 1 | # Makefile for compat directory 2 | # Copyright (C) 2010 Free Software Foundation, Inc. 3 | # 4 | # This file is part of Libgcrypt. 5 | # 6 | # Libgcrypt is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU Lesser General Public License as 8 | # published by the Free Software Foundation; either version 2.1 of 9 | # the License, or (at your option) any later version. 10 | # 11 | # Libgcrypt is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public 17 | # License along with this program; if not, see . 18 | 19 | # Process this file with automake to produce Makefile.in 20 | 21 | # We use this libcompat to work around problems with LIBOBJ stuff. 22 | # For example, we need some of the compat files also in tests/ but the 23 | # suggested way to do this (using the automake option subdir-objects) 24 | # leads to problems with "make distclean": The distclean target in 25 | # tests is run before the one src and it removes the deps files of the 26 | # libobj files which are in src. Now when it comes to run make in src 27 | # the icnluded files are gone - bummer. Instead of try to fix this 28 | # issue it seems better not to use subdir-objects but build them all 29 | # into a compat library and always link against that library. This 30 | # also avoids the problem that a dependency on LTLIBOBJ is not setup 31 | # if -- disable-static was used. 32 | 33 | # Need to include ../src in addition to top_srcdir because gcrypt.h is 34 | # a built header. 35 | AM_CPPFLAGS = -I../src -I$(top_srcdir)/src $(GPG_ERROR_CFLAGS) 36 | 37 | noinst_LTLIBRARIES = libcompat.la 38 | 39 | # We only need one file so that the library is guaranteed to have at 40 | # least one member. 41 | libcompat_la_SOURCES = compat.c libcompat.h 42 | libcompat_la_DEPENDENCIES = @LTLIBOBJS@ 43 | libcompat_la_LIBADD = @LTLIBOBJS@ 44 | 45 | # AC_LIBOBJ files are: 46 | # getpid.c 47 | # clock.c 48 | # 49 | -------------------------------------------------------------------------------- /compat/clock.c: -------------------------------------------------------------------------------- 1 | /* clock.c - Replacement for WindowsCE 2 | Copyright (C) 2010 Free Software Foundation, Inc. 3 | 4 | This file is free software; as a special exception the author gives 5 | unlimited permission to copy and/or distribute it, with or without 6 | modifications, as long as this notice is preserved. 7 | 8 | This file is distributed in the hope that it will be useful, but 9 | WITHOUT ANY WARRANTY, to the extent permitted by law; without even 10 | the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 11 | PURPOSE. */ 12 | 13 | #if HAVE_CONFIG_H 14 | #include 15 | #endif 16 | 17 | #ifdef HAVE_W32CE_SYSTEM 18 | #include 19 | #include 20 | #include 21 | 22 | clock_t 23 | _gcry_clock (void) 24 | { 25 | assert (CLOCKS_PER_SEC == 1000); 26 | #warning Replace by a correct implementation. 27 | /* It seems that GetProcessTimes is available in the kernel but 28 | without a declaration. If that fails we would need to walk over 29 | all threads and tally up the GetThreadTimes. */ 30 | 31 | return GetTickCount (); 32 | } 33 | 34 | #else 35 | # error No replacement function for clock known 36 | #endif 37 | -------------------------------------------------------------------------------- /compat/compat.c: -------------------------------------------------------------------------------- 1 | /* compat.c - Dummy file to avoid an empty library. 2 | * Copyright (C) 2010 Free Software Foundation, Inc. 3 | * 4 | * This file is part of Libgcrypt. 5 | * 6 | * Libgcrypt is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Libgcrypt is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | */ 19 | 20 | #include 21 | 22 | #include "../src/g10lib.h" 23 | 24 | 25 | const char * 26 | _gcry_compat_identification (void) 27 | { 28 | /* For complete list of copyright holders see the file AUTHORS in 29 | the source distribution. */ 30 | static const char blurb[] = 31 | "\n\n" 32 | "This is Libgcrypt " PACKAGE_VERSION " - The GNU Crypto Library\n" 33 | "Copyright (C) 2000-2018 Free Software Foundation, Inc.\n" 34 | "Copyright (C) 2012-2024 g10 Code GmbH\n" 35 | "Copyright (C) 2013-2024 Jussi Kivilinna\n" 36 | "\n" 37 | "(" BUILD_REVISION " " BUILD_TIMESTAMP ")\n" 38 | "\n\n"; 39 | return blurb; 40 | } 41 | -------------------------------------------------------------------------------- /compat/getpid.c: -------------------------------------------------------------------------------- 1 | /* getpid.c - Replacement for WindowsCE 2 | Copyright (C) 2010 Free Software Foundation, Inc. 3 | 4 | This file is free software; as a special exception the author gives 5 | unlimited permission to copy and/or distribute it, with or without 6 | modifications, as long as this notice is preserved. 7 | 8 | This file is distributed in the hope that it will be useful, but 9 | WITHOUT ANY WARRANTY, to the extent permitted by law; without even 10 | the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 11 | PURPOSE. */ 12 | 13 | #if HAVE_CONFIG_H 14 | #include 15 | #endif 16 | 17 | #ifdef HAVE_W32CE_SYSTEM 18 | #include 19 | #include 20 | 21 | pid_t 22 | _gcry_getpid (void) 23 | { 24 | return GetCurrentProcessId (); 25 | } 26 | 27 | #else 28 | # error No replacement function for getpid known 29 | #endif 30 | -------------------------------------------------------------------------------- /compat/libcompat.h: -------------------------------------------------------------------------------- 1 | /* libcomapt.h - Prototypes for AC_REPLACE_FUNCtions. 2 | * Copyright (C) 2010 Free Software Foundation, Inc. 3 | * 4 | * This file is part of Libgcrypt. 5 | * 6 | * Libgcrypt is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Libgcrypt is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | */ 19 | 20 | #ifndef GCRY_LIBCOMPAT_H 21 | #define GCRY_LIBCOMPAT_H 22 | 23 | const char *_gcry_compat_identification (void); 24 | 25 | 26 | #ifndef HAVE_GETPID 27 | pid_t _gcry_getpid (void); 28 | #define getpid() _gcry_getpid () 29 | #endif 30 | 31 | #ifndef HAVE_CLOCK 32 | clock_t _gcry_clock (void); 33 | #define clock() _gcry_clock () 34 | #endif 35 | 36 | 37 | #endif /*GCRY_LIBCOMPAT_H*/ 38 | -------------------------------------------------------------------------------- /doc/DCO: -------------------------------------------------------------------------------- 1 | Libgcrypt Developer's Certificate of Origin. Version 1.0 2 | ========================================================= 3 | 4 | By making a contribution to the Libgcrypt project, I certify that: 5 | 6 | (a) The contribution was created in whole or in part by me and I 7 | have the right to submit it under the free software license 8 | indicated in the file; or 9 | 10 | (b) The contribution is based upon previous work that, to the 11 | best of my knowledge, is covered under an appropriate free 12 | software license and I have the right under that license to 13 | submit that work with modifications, whether created in whole 14 | or in part by me, under the same free software license 15 | (unless I am permitted to submit under a different license), 16 | as indicated in the file; or 17 | 18 | (c) The contribution was provided directly to me by some other 19 | person who certified (a), (b) or (c) and I have not modified 20 | it. 21 | 22 | (d) I understand and agree that this project and the contribution 23 | are public and that a record of the contribution (including 24 | all personal information I submit with it, including my 25 | sign-off) is maintained indefinitely and may be redistributed 26 | consistent with this project or the free software license(s) 27 | involved. 28 | 29 | Signed-off-by: [Your name and mail address] 30 | -------------------------------------------------------------------------------- /doc/Notes-wk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/libgcrypt/4a997384e4bf0bb04e0fb6c61976c67c27bc8612/doc/Notes-wk -------------------------------------------------------------------------------- /m4/ChangeLog-2011: -------------------------------------------------------------------------------- 1 | 2011-12-01 Werner Koch 2 | 3 | NB: ChangeLog files are no longer manually maintained. Starting 4 | on December 1st, 2011 we put change information only in the GIT 5 | commit log, and generate a top-level ChangeLog file from logs at 6 | "make dist". See doc/HACKING for details. 7 | 8 | 2011-02-23 Werner Koch 9 | 10 | * gpg-error.m4: New. Take from current gpg-error master. 11 | * Makefile.am (EXTRA_DIST): Add gpg-error.m4. 12 | 13 | 2009-01-22 Werner Koch 14 | 15 | * noexecstack.m4: Replace non portable grep -q. Reported by 16 | Albert Chin. 17 | 18 | 2007-02-22 Werner Koch 19 | 20 | * noexecstack.m4: Change default to enable it. 21 | 22 | 2007-02-20 Werner Koch 23 | 24 | * Makefile.am: New. 25 | 26 | * noexecstack.m4: New. Taken from gnupg 1.4 27 | 28 | 2006-10-11 Marcus Brinkmann 29 | 30 | * fallback.m4: Removed again. 31 | 32 | 2006-10-10 Marcus Brinkmann 33 | 34 | * fallback.m4: New file from Pth. 35 | 36 | 2006-07-04 Marcus Brinkmann 37 | 38 | * sys_socket_h.m4, socklen.m4, onceonly.m4: New files from gnulib. 39 | 40 | 2004-04-06 Werner Koch 41 | 42 | * libtool.m4: Updated from 1.5.4 43 | 44 | 2003-12-08 Werner Koch 45 | 46 | * libtool.m4: New. 47 | 48 | Local Variables: 49 | buffer-read-only: t 50 | End: 51 | -------------------------------------------------------------------------------- /m4/Makefile.am: -------------------------------------------------------------------------------- 1 | EXTRA_DIST = libtool.m4 noexecstack.m4 2 | EXTRA_DIST += gpg-error.m4 3 | -------------------------------------------------------------------------------- /m4/ltversion.m4: -------------------------------------------------------------------------------- 1 | # ltversion.m4 -- version numbers -*- Autoconf -*- 2 | # 3 | # Copyright (C) 2004 Free Software Foundation, Inc. 4 | # Written by Scott James Remnant, 2004 5 | # 6 | # This file is free software; the Free Software Foundation gives 7 | # unlimited permission to copy and/or distribute it, with or without 8 | # modifications, as long as this notice is preserved. 9 | 10 | # @configure_input@ 11 | 12 | # serial 3337 ltversion.m4 13 | # This file is part of GNU Libtool 14 | 15 | m4_define([LT_PACKAGE_VERSION], [2.4.2]) 16 | m4_define([LT_PACKAGE_REVISION], [1.3337]) 17 | 18 | AC_DEFUN([LTVERSION_VERSION], 19 | [macro_version='2.4.2' 20 | macro_revision='1.3337' 21 | _LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?]) 22 | _LT_DECL(, macro_revision, 0) 23 | ]) 24 | -------------------------------------------------------------------------------- /m4/noexecstack.m4: -------------------------------------------------------------------------------- 1 | # noexecstack.m4 2 | dnl Copyright (C) 1995-2006 Free Software Foundation, Inc. 3 | dnl 4 | dnl This library is free software; you can redistribute it and/or 5 | dnl modify it under the terms of the GNU Lesser General Public 6 | dnl License as published by the Free Software Foundation; either 7 | dnl version 2.1 of the License, or (at your option) any later version. 8 | dnl 9 | dnl This library is distributed in the hope that it will be useful, 10 | dnl but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | dnl Lesser General Public License for more details. 13 | dnl 14 | dnl You should have received a copy of the GNU Lesser General Public 15 | dnl License along with this library; if not, see . 16 | dnl SPDX-License-Identifier: LGPL-2.1-or-later 17 | 18 | dnl Checks whether the stack can be marked nonexecutable by passing an 19 | dnl option to the C-compiler when acting on .s files. Returns that 20 | dnl option in NOEXECSTACK_FLAGS. 21 | dnl This macro is adapted from one found in GLIBC-2.3.5. 22 | AC_DEFUN([CL_AS_NOEXECSTACK],[ 23 | AC_REQUIRE([AC_PROG_CC]) 24 | AC_REQUIRE([AM_PROG_AS]) 25 | 26 | AC_MSG_CHECKING([whether non excutable stack support is requested]) 27 | AC_ARG_ENABLE(noexecstack, 28 | AS_HELP_STRING([--disable-noexecstack], 29 | [disable non executable stack support]), 30 | noexecstack_support=$enableval, noexecstack_support=yes) 31 | AC_MSG_RESULT($noexecstack_support) 32 | 33 | AC_CACHE_CHECK([whether assembler supports --noexecstack option], 34 | cl_cv_as_noexecstack, [dnl 35 | cat > conftest.c </dev/null]) \ 40 | && grep .note.GNU-stack conftest.s >/dev/null \ 41 | && AC_TRY_COMMAND([${CCAS} $CCASFLAGS $CPPFLAGS -Wa,--noexecstack 42 | -c -o conftest.o conftest.s >/dev/null]) 43 | then 44 | cl_cv_as_noexecstack=yes 45 | else 46 | cl_cv_as_noexecstack=no 47 | fi 48 | rm -f conftest*]) 49 | if test "$noexecstack_support" = yes -a "$cl_cv_as_noexecstack" = yes; then 50 | NOEXECSTACK_FLAGS="-Wa,--noexecstack" 51 | else 52 | NOEXECSTACK_FLAGS= 53 | fi 54 | AC_SUBST(NOEXECSTACK_FLAGS) 55 | ]) 56 | -------------------------------------------------------------------------------- /mpi/aarch64/distfiles: -------------------------------------------------------------------------------- 1 | mpih-add1.S 2 | mpih-mul1.S 3 | mpih-mul2.S 4 | mpih-mul3.S 5 | mpih-sub1.S 6 | mpi-asm-defs.h 7 | -------------------------------------------------------------------------------- /mpi/aarch64/mpi-asm-defs.h: -------------------------------------------------------------------------------- 1 | /* This file defines some basic constants for the MPI machinery. We 2 | * need to define the types on a per-CPU basis, so it is done with 3 | * this file here. */ 4 | #define BYTES_PER_MPI_LIMB (SIZEOF_UNSIGNED_LONG_LONG) 5 | -------------------------------------------------------------------------------- /mpi/aarch64/mpih-add1.S: -------------------------------------------------------------------------------- 1 | /* ARM64 add_n -- Add two limb vectors of the same length > 0 and store 2 | * sum in a third limb vector. 3 | * 4 | * Copyright (C) 2013 Jussi Kivilinna 5 | * 6 | * This file is part of Libgcrypt. 7 | * 8 | * Libgcrypt is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as 10 | * published by the Free Software Foundation; either version 2.1 of 11 | * the License, or (at your option) any later version. 12 | * 13 | * Libgcrypt is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this program; if not, see . 20 | * 21 | */ 22 | 23 | #include "sysdep.h" 24 | #include "asm-syntax.h" 25 | #include "asm-common-aarch64.h" 26 | 27 | /******************* 28 | * mpi_limb_t 29 | * _gcry_mpih_add_n( mpi_ptr_t res_ptr, x0 30 | * mpi_ptr_t s1_ptr, x1 31 | * mpi_ptr_t s2_ptr, x2 32 | * mpi_size_t size) w3 33 | */ 34 | 35 | .text 36 | 37 | .globl C_SYMBOL_NAME(_gcry_mpih_add_n) 38 | ELF(.type C_SYMBOL_NAME(_gcry_mpih_add_n),%function) 39 | .align 4 40 | C_SYMBOL_NAME(_gcry_mpih_add_n): 41 | CFI_STARTPROC() 42 | and w5, w3, #3; 43 | adds xzr, xzr, xzr; /* clear carry flag */ 44 | 45 | cbz w5, .Large_loop; 46 | 47 | .Loop: 48 | ldr x4, [x1], #8; 49 | sub w3, w3, #1; 50 | ldr x11, [x2], #8; 51 | and w5, w3, #3; 52 | adcs x4, x4, x11; 53 | str x4, [x0], #8; 54 | cbz w3, .Lend; 55 | cbnz w5, .Loop; 56 | 57 | .Large_loop: 58 | ldp x4, x6, [x1], #16; 59 | ldp x5, x7, [x2], #16; 60 | ldp x8, x10, [x1], #16; 61 | ldp x9, x11, [x2], #16; 62 | sub w3, w3, #4; 63 | adcs x4, x4, x5; 64 | adcs x6, x6, x7; 65 | adcs x8, x8, x9; 66 | adcs x10, x10, x11; 67 | stp x4, x6, [x0], #16; 68 | stp x8, x10, [x0], #16; 69 | cbnz w3, .Large_loop; 70 | 71 | .Lend: 72 | adc x0, xzr, xzr; 73 | ret_spec_stop; 74 | CFI_ENDPROC() 75 | ELF(.size C_SYMBOL_NAME(_gcry_mpih_add_n),.-C_SYMBOL_NAME(_gcry_mpih_add_n);) 76 | -------------------------------------------------------------------------------- /mpi/aarch64/mpih-mul1.S: -------------------------------------------------------------------------------- 1 | /* ARM64 mul_1 -- Multiply a limb vector with a limb and store the result in 2 | * a second limb vector. 3 | * 4 | * Copyright (C) 2013 Jussi Kivilinna 5 | * 6 | * This file is part of Libgcrypt. 7 | * 8 | * Libgcrypt is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as 10 | * published by the Free Software Foundation; either version 2.1 of 11 | * the License, or (at your option) any later version. 12 | * 13 | * Libgcrypt is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this program; if not, see . 20 | * 21 | */ 22 | 23 | #include "sysdep.h" 24 | #include "asm-syntax.h" 25 | #include "asm-common-aarch64.h" 26 | 27 | /******************* 28 | * mpi_limb_t 29 | * _gcry_mpih_mul_1( mpi_ptr_t res_ptr, x0 30 | * mpi_ptr_t s1_ptr, x1 31 | * mpi_size_t s1_size, w2 32 | * mpi_limb_t s2_limb) x3 33 | */ 34 | 35 | .text 36 | 37 | .globl C_SYMBOL_NAME(_gcry_mpih_mul_1) 38 | ELF(.type C_SYMBOL_NAME(_gcry_mpih_mul_1),%function) 39 | .align 4 40 | C_SYMBOL_NAME(_gcry_mpih_mul_1): 41 | CFI_STARTPROC() 42 | and w5, w2, #3; 43 | mov x4, xzr; 44 | 45 | cbz w5, .Large_loop; 46 | 47 | .Loop: 48 | ldr x5, [x1], #8; 49 | sub w2, w2, #1; 50 | mul x9, x5, x3; 51 | umulh x10, x5, x3; 52 | and w5, w2, #3; 53 | adds x4, x4, x9; 54 | str x4, [x0], #8; 55 | adc x4, x10, xzr; 56 | 57 | cbz w2, .Lend; 58 | cbnz w5, .Loop; 59 | 60 | .Large_loop: 61 | ldp x5, x6, [x1]; 62 | sub w2, w2, #4; 63 | 64 | mul x9, x5, x3; 65 | ldp x7, x8, [x1, #16]; 66 | umulh x10, x5, x3; 67 | add x1, x1, #32; 68 | 69 | adds x4, x4, x9; 70 | str x4, [x0], #8; 71 | mul x11, x6, x3; 72 | adc x4, x10, xzr; 73 | 74 | umulh x12, x6, x3; 75 | 76 | adds x4, x4, x11; 77 | str x4, [x0], #8; 78 | mul x13, x7, x3; 79 | adc x4, x12, xzr; 80 | 81 | umulh x14, x7, x3; 82 | 83 | adds x4, x4, x13; 84 | str x4, [x0], #8; 85 | mul x15, x8, x3; 86 | adc x4, x14, xzr; 87 | 88 | umulh x16, x8, x3; 89 | 90 | adds x4, x4, x15; 91 | str x4, [x0], #8; 92 | adc x4, x16, xzr; 93 | 94 | cbnz w2, .Large_loop; 95 | 96 | .Lend: 97 | mov x0, x4; 98 | ret_spec_stop; 99 | CFI_ENDPROC() 100 | ELF(.size C_SYMBOL_NAME(_gcry_mpih_mul_1),.-C_SYMBOL_NAME(_gcry_mpih_mul_1);) 101 | -------------------------------------------------------------------------------- /mpi/aarch64/mpih-sub1.S: -------------------------------------------------------------------------------- 1 | /* ARM64 sub_n -- Subtract two limb vectors of the same length > 0 and store 2 | * sum in a third limb vector. 3 | * 4 | * Copyright (C) 2013 Jussi Kivilinna 5 | * 6 | * This file is part of Libgcrypt. 7 | * 8 | * Libgcrypt is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as 10 | * published by the Free Software Foundation; either version 2.1 of 11 | * the License, or (at your option) any later version. 12 | * 13 | * Libgcrypt is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this program; if not, see . 20 | * 21 | */ 22 | 23 | #include "sysdep.h" 24 | #include "asm-syntax.h" 25 | #include "asm-common-aarch64.h" 26 | 27 | /******************* 28 | * mpi_limb_t 29 | * _gcry_mpih_sub_n( mpi_ptr_t res_ptr, x0 30 | * mpi_ptr_t s1_ptr, x1 31 | * mpi_ptr_t s2_ptr, x2 32 | * mpi_size_t size) w3 33 | */ 34 | 35 | .text 36 | 37 | .globl C_SYMBOL_NAME(_gcry_mpih_sub_n) 38 | ELF(.type C_SYMBOL_NAME(_gcry_mpih_sub_n),%function) 39 | .align 4 40 | C_SYMBOL_NAME(_gcry_mpih_sub_n): 41 | CFI_STARTPROC() 42 | and w5, w3, #3; 43 | subs xzr, xzr, xzr; /* prepare carry flag for sub */ 44 | 45 | cbz w5, .Large_loop; 46 | 47 | .Loop: 48 | ldr x4, [x1], #8; 49 | sub w3, w3, #1; 50 | ldr x11, [x2], #8; 51 | and w5, w3, #3; 52 | sbcs x4, x4, x11; 53 | str x4, [x0], #8; 54 | cbz w3, .Lend; 55 | cbnz w5, .Loop; 56 | 57 | .Large_loop: 58 | ldp x4, x6, [x1], #16; 59 | ldp x5, x7, [x2], #16; 60 | ldp x8, x10, [x1], #16; 61 | ldp x9, x11, [x2], #16; 62 | sub w3, w3, #4; 63 | sbcs x4, x4, x5; 64 | sbcs x6, x6, x7; 65 | sbcs x8, x8, x9; 66 | sbcs x10, x10, x11; 67 | stp x4, x6, [x0], #16; 68 | stp x8, x10, [x0], #16; 69 | cbnz w3, .Large_loop; 70 | 71 | .Lend: 72 | cset x0, cc; 73 | ret_spec_stop; 74 | CFI_ENDPROC() 75 | ELF(.size C_SYMBOL_NAME(_gcry_mpih_sub_n),.-C_SYMBOL_NAME(_gcry_mpih_sub_n);) 76 | -------------------------------------------------------------------------------- /mpi/alpha/README: -------------------------------------------------------------------------------- 1 | This directory contains mpn functions optimized for DEC Alpha processors. 2 | 3 | RELEVANT OPTIMIZATION ISSUES 4 | 5 | EV4 6 | 7 | 1. This chip has very limited store bandwidth. The on-chip L1 cache is 8 | write-through, and a cache line is transferred from the store buffer to the 9 | off-chip L2 in as much 15 cycles on most systems. This delay hurts 10 | mpn_add_n, mpn_sub_n, mpn_lshift, and mpn_rshift. 11 | 12 | 2. Pairing is possible between memory instructions and integer arithmetic 13 | instructions. 14 | 15 | 3. mulq and umulh is documented to have a latency of 23 cycles, but 2 of 16 | these cycles are pipelined. Thus, multiply instructions can be issued at a 17 | rate of one each 21nd cycle. 18 | 19 | EV5 20 | 21 | 1. The memory bandwidth of this chip seems excellent, both for loads and 22 | stores. Even when the working set is larger than the on-chip L1 and L2 23 | caches, the performance remain almost unaffected. 24 | 25 | 2. mulq has a measured latency of 13 cycles and an issue rate of 1 each 8th 26 | cycle. umulh has a measured latency of 15 cycles and an issue rate of 1 27 | each 10th cycle. But the exact timing is somewhat confusing. 28 | 29 | 3. mpn_add_n. With 4-fold unrolling, we need 37 instructions, whereof 12 30 | are memory operations. This will take at least 31 | ceil(37/2) [dual issue] + 1 [taken branch] = 20 cycles 32 | We have 12 memory cycles, plus 4 after-store conflict cycles, or 16 data 33 | cache cycles, which should be completely hidden in the 20 issue cycles. 34 | The computation is inherently serial, with these dependencies: 35 | addq 36 | / \ 37 | addq cmpult 38 | | | 39 | cmpult | 40 | \ / 41 | or 42 | I.e., there is a 4 cycle path for each limb, making 16 cycles the absolute 43 | minimum. We could replace the `or' with a cmoveq/cmovne, which would save 44 | a cycle on EV5, but that might waste a cycle on EV4. Also, cmov takes 2 45 | cycles. 46 | addq 47 | / \ 48 | addq cmpult 49 | | \ 50 | cmpult -> cmovne 51 | 52 | STATUS 53 | 54 | -------------------------------------------------------------------------------- /mpi/alpha/distfiles: -------------------------------------------------------------------------------- 1 | README 2 | mpih-add1.S 3 | mpih-sub1.S 4 | mpih-mul1.S 5 | mpih-mul2.S 6 | mpih-mul3.S 7 | mpih-lshift.S 8 | mpih-rshift.S 9 | 10 | udiv-qrnnd.S 11 | 12 | -------------------------------------------------------------------------------- /mpi/amd64/distfiles: -------------------------------------------------------------------------------- 1 | func_abi.h 2 | mpih-add1.S 3 | mpih-lshift.S 4 | mpih-mul1.S 5 | mpih-mul2.S 6 | mpih-mul3.S 7 | mpih-rshift.S 8 | mpih-sub1.S 9 | mpi-asm-defs.h 10 | -------------------------------------------------------------------------------- /mpi/amd64/func_abi.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "asm-common-amd64.h" 4 | 5 | #ifdef USE_MS_ABI 6 | /* Store registers and move four first input arguments from MS ABI to 7 | * SYSV ABI. */ 8 | #define FUNC_ENTRY() \ 9 | CFI_STARTPROC(); \ 10 | pushq %rsi; \ 11 | CFI_PUSH(%rsi); \ 12 | pushq %rdi; \ 13 | CFI_PUSH(%rdi); \ 14 | movq %rdx, %rsi; \ 15 | movq %rcx, %rdi; \ 16 | movq %r8, %rdx; \ 17 | movq %r9, %rcx; 18 | 19 | /* Restore registers. */ 20 | #define FUNC_EXIT() \ 21 | popq %rdi; \ 22 | CFI_POP(%rdi); \ 23 | popq %rsi; \ 24 | CFI_POP(%rsi); \ 25 | ret_spec_stop; \ 26 | CFI_ENDPROC(); 27 | #else 28 | #define FUNC_ENTRY() \ 29 | CFI_STARTPROC(); 30 | 31 | #define FUNC_EXIT() \ 32 | ret_spec_stop; \ 33 | CFI_ENDPROC(); 34 | #endif 35 | -------------------------------------------------------------------------------- /mpi/amd64/mpi-asm-defs.h: -------------------------------------------------------------------------------- 1 | /* This file defines some basic constants for the MPI machinery. We 2 | * need to define the types on a per-CPU basis, so it is done with 3 | * this file here. */ 4 | #define BYTES_PER_MPI_LIMB (SIZEOF_UNSIGNED_LONG_LONG) 5 | -------------------------------------------------------------------------------- /mpi/amd64/mpih-lshift.S: -------------------------------------------------------------------------------- 1 | /* AMD64 (x86_64) lshift -- Left shift a limb vector and store 2 | * result in a second limb vector. 3 | * 4 | * Copyright (C) 1992, 1994, 1995, 1998, 5 | * 2001, 2002, 2006 Free Software Foundation, Inc. 6 | * 7 | * This file is part of Libgcrypt. 8 | * 9 | * Libgcrypt is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as 11 | * published by the Free Software Foundation; either version 2.1 of 12 | * the License, or (at your option) any later version. 13 | * 14 | * Libgcrypt is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with this program; if not, see . 21 | * SPDX-License-Identifier: LGPL-2.1-or-later 22 | * 23 | * Note: This code is heavily based on the GNU MP Library. 24 | * Actually it's the same code with only minor changes in the 25 | * way the data is stored; this is to support the abstraction 26 | * of an optional secure memory allocation which may be used 27 | * to avoid revealing of sensitive data due to paging etc. 28 | */ 29 | 30 | 31 | #include "sysdep.h" 32 | #include "asm-syntax.h" 33 | 34 | /******************* 35 | * mpi_limb_t 36 | * _gcry_mpih_lshift( mpi_ptr_t wp, rdi 37 | * mpi_ptr_t up, rsi 38 | * mpi_size_t usize, rdx 39 | * unsigned cnt) rcx 40 | */ 41 | 42 | TEXT 43 | ALIGN(4) 44 | .globl C_SYMBOL_NAME(_gcry_mpih_lshift) 45 | C_SYMBOL_NAME(_gcry_mpih_lshift:) 46 | FUNC_ENTRY() 47 | /* Note: %xmm6 and %xmm7 not used for WIN64 ABI compatibility. */ 48 | movq -8(%rsi,%rdx,8), %xmm4 49 | movd %ecx, %xmm1 50 | movl $64, %eax 51 | subl %ecx, %eax 52 | movd %eax, %xmm0 53 | movdqa %xmm4, %xmm3 54 | psrlq %xmm0, %xmm4 55 | movq %xmm4, %rax 56 | subq $2, %rdx 57 | jl .Lendo 58 | 59 | ALIGN(4) /* minimal alignment for claimed speed */ 60 | .Loop: movq (%rsi,%rdx,8), %xmm5 61 | movdqa %xmm5, %xmm2 62 | psrlq %xmm0, %xmm5 63 | psllq %xmm1, %xmm3 64 | por %xmm5, %xmm3 65 | movq %xmm3, 8(%rdi,%rdx,8) 66 | je .Lende 67 | movq -8(%rsi,%rdx,8), %xmm4 68 | movdqa %xmm4, %xmm3 69 | psrlq %xmm0, %xmm4 70 | psllq %xmm1, %xmm2 71 | por %xmm4, %xmm2 72 | movq %xmm2, (%rdi,%rdx,8) 73 | subq $2, %rdx 74 | jge .Loop 75 | 76 | .Lendo: movdqa %xmm3, %xmm2 77 | .Lende: psllq %xmm1, %xmm2 78 | movq %xmm2, (%rdi) 79 | FUNC_EXIT() 80 | -------------------------------------------------------------------------------- /mpi/amd64/mpih-mul1.S: -------------------------------------------------------------------------------- 1 | /* AMD64 mul_1 -- Multiply a limb vector with a limb and store 2 | * the result in a second limb vector. 3 | * Copyright (C) 1992, 1994, 1998, 4 | * 2001, 2002, 2006 Free Software Foundation, Inc. 5 | * 6 | * This file is part of Libgcrypt. 7 | * 8 | * Libgcrypt is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as 10 | * published by the Free Software Foundation; either version 2.1 of 11 | * the License, or (at your option) any later version. 12 | * 13 | * Libgcrypt is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this program; if not, see . 20 | * SPDX-License-Identifier: LGPL-2.1-or-later 21 | * 22 | * Note: This code is heavily based on the GNU MP Library. 23 | * Actually it's the same code with only minor changes in the 24 | * way the data is stored; this is to support the abstraction 25 | * of an optional secure memory allocation which may be used 26 | * to avoid revealing of sensitive data due to paging etc. 27 | */ 28 | 29 | 30 | #include "sysdep.h" 31 | #include "asm-syntax.h" 32 | 33 | /******************* 34 | * mpi_limb_t 35 | * _gcry_mpih_mul_1( mpi_ptr_t res_ptr, (rdi) 36 | * mpi_ptr_t s1_ptr, (rsi) 37 | * mpi_size_t s1_size, (rdx) 38 | * mpi_limb_t s2_limb) (rcx) 39 | */ 40 | 41 | 42 | TEXT 43 | ALIGN(4) 44 | 45 | GLOBL C_SYMBOL_NAME(_gcry_mpih_mul_1) 46 | C_SYMBOL_NAME(_gcry_mpih_mul_1:) 47 | 48 | FUNC_ENTRY() 49 | movq %rdx, %r11 50 | leaq (%rsi,%rdx,8), %rsi 51 | leaq (%rdi,%rdx,8), %rdi 52 | negq %r11 53 | xorl %r8d, %r8d 54 | 55 | ALIGN(4) 56 | .Loop: movq (%rsi,%r11,8), %rax 57 | mulq %rcx 58 | addq %r8, %rax 59 | movl $0, %r8d 60 | adcq %rdx, %r8 61 | movq %rax, (%rdi,%r11,8) 62 | incq %r11 63 | jne .Loop 64 | 65 | movq %r8, %rax 66 | FUNC_EXIT() 67 | -------------------------------------------------------------------------------- /mpi/amd64/mpih-mul2.S: -------------------------------------------------------------------------------- 1 | /* AMD64 addmul2 -- Multiply a limb vector with a limb and add 2 | * the result to a second limb vector. 3 | * 4 | * Copyright (C) 1992, 1994, 1998, 5 | * 2001, 2002, 2006 Free Software Foundation, Inc. 6 | * 7 | * This file is part of Libgcrypt. 8 | * 9 | * Libgcrypt is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as 11 | * published by the Free Software Foundation; either version 2.1 of 12 | * the License, or (at your option) any later version. 13 | * 14 | * Libgcrypt is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with this program; if not, see . 21 | * SPDX-License-Identifier: LGPL-2.1-or-later 22 | * 23 | * Note: This code is heavily based on the GNU MP Library. 24 | * Actually it's the same code with only minor changes in the 25 | * way the data is stored; this is to support the abstraction 26 | * of an optional secure memory allocation which may be used 27 | * to avoid revealing of sensitive data due to paging etc. 28 | */ 29 | 30 | 31 | #include "sysdep.h" 32 | #include "asm-syntax.h" 33 | 34 | /******************* 35 | * mpi_limb_t 36 | * _gcry_mpih_addmul_1( mpi_ptr_t res_ptr, (rdi) 37 | * mpi_ptr_t s1_ptr, (rsi) 38 | * mpi_size_t s1_size, (rdx) 39 | * mpi_limb_t s2_limb) (rcx) 40 | */ 41 | TEXT 42 | ALIGN(4) 43 | GLOBL C_SYMBOL_NAME(_gcry_mpih_addmul_1) 44 | C_SYMBOL_NAME(_gcry_mpih_addmul_1:) 45 | FUNC_ENTRY() 46 | movq %rdx, %r11 47 | leaq (%rsi,%rdx,8), %rsi 48 | leaq (%rdi,%rdx,8), %rdi 49 | negq %r11 50 | xorl %r8d, %r8d 51 | xorl %r10d, %r10d 52 | 53 | ALIGN(4) /* minimal alignment for claimed speed */ 54 | .Loop: movq (%rsi,%r11,8), %rax 55 | mulq %rcx 56 | addq (%rdi,%r11,8), %rax 57 | adcq %r10, %rdx 58 | addq %r8, %rax 59 | movq %r10, %r8 60 | movq %rax, (%rdi,%r11,8) 61 | adcq %rdx, %r8 62 | incq %r11 63 | jne .Loop 64 | 65 | movq %r8, %rax 66 | FUNC_EXIT() 67 | -------------------------------------------------------------------------------- /mpi/amd64/mpih-mul3.S: -------------------------------------------------------------------------------- 1 | /* AMD64 submul_1 -- Multiply a limb vector with a limb and add 2 | * the result to a second limb vector. 3 | * 4 | * Copyright (C) 1992, 1994, 1998, 5 | * 2001, 2002, 2006 Free Software Foundation, Inc. 6 | * 7 | * This file is part of Libgcrypt. 8 | * 9 | * Libgcrypt is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as 11 | * published by the Free Software Foundation; either version 2.1 of 12 | * the License, or (at your option) any later version. 13 | * 14 | * Libgcrypt is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with this program; if not, see . 21 | * SPDX-License-Identifier: LGPL-2.1-or-later 22 | * 23 | * Note: This code is heavily based on the GNU MP Library. 24 | * Actually it's the same code with only minor changes in the 25 | * way the data is stored; this is to support the abstraction 26 | * of an optional secure memory allocation which may be used 27 | * to avoid revealing of sensitive data due to paging etc. 28 | */ 29 | 30 | 31 | #include "sysdep.h" 32 | #include "asm-syntax.h" 33 | 34 | 35 | /******************* 36 | * mpi_limb_t 37 | * _gcry_mpih_submul_1( mpi_ptr_t res_ptr, (rdi) 38 | * mpi_ptr_t s1_ptr, (rsi) 39 | * mpi_size_t s1_size, (rdx) 40 | * mpi_limb_t s2_limb) (rcx) 41 | */ 42 | TEXT 43 | ALIGN(4) 44 | GLOBL C_SYMBOL_NAME(_gcry_mpih_submul_1) 45 | C_SYMBOL_NAME(_gcry_mpih_submul_1:) 46 | FUNC_ENTRY() 47 | movq %rdx, %r11 48 | leaq (%rsi,%r11,8), %rsi 49 | leaq (%rdi,%r11,8), %rdi 50 | negq %r11 51 | xorl %r8d, %r8d 52 | 53 | ALIGN(4) /* minimal alignment for claimed speed */ 54 | .Loop: movq (%rsi,%r11,8), %rax 55 | movq (%rdi,%r11,8), %r10 56 | mulq %rcx 57 | subq %r8, %r10 58 | movl $0, %r8d 59 | adcl %r8d, %r8d 60 | subq %rax, %r10 61 | adcq %rdx, %r8 62 | movq %r10, (%rdi,%r11,8) 63 | incq %r11 64 | jne .Loop 65 | 66 | movq %r8, %rax 67 | FUNC_EXIT() 68 | -------------------------------------------------------------------------------- /mpi/amd64/mpih-rshift.S: -------------------------------------------------------------------------------- 1 | /* AMD64 (x86_64) rshift -- Right shift a limb vector and store 2 | * result in a second limb vector. 3 | * 4 | * Copyright (C) 1992, 1994, 1995, 1998, 5 | * 2001, 2002, 2006 Free Software Foundation, Inc. 6 | * 7 | * This file is part of Libgcrypt. 8 | * 9 | * Libgcrypt is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as 11 | * published by the Free Software Foundation; either version 2.1 of 12 | * the License, or (at your option) any later version. 13 | * 14 | * Libgcrypt is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with this program; if not, see . 21 | * SPDX-License-Identifier: LGPL-2.1-or-later 22 | * 23 | * Note: This code is heavily based on the GNU MP Library. 24 | * Actually it's the same code with only minor changes in the 25 | * way the data is stored; this is to support the abstraction 26 | * of an optional secure memory allocation which may be used 27 | * to avoid revealing of sensitive data due to paging etc. 28 | */ 29 | 30 | 31 | #include "sysdep.h" 32 | #include "asm-syntax.h" 33 | 34 | /******************* 35 | * mpi_limb_t 36 | * _gcry_mpih_rshift( mpi_ptr_t wp, rdi 37 | * mpi_ptr_t up, rsi 38 | * mpi_size_t usize, rdx 39 | * unsigned cnt) rcx 40 | */ 41 | 42 | TEXT 43 | ALIGN(4) 44 | .globl C_SYMBOL_NAME(_gcry_mpih_rshift) 45 | C_SYMBOL_NAME(_gcry_mpih_rshift:) 46 | FUNC_ENTRY() 47 | /* Note: %xmm6 and %xmm7 not used for WIN64 ABI compatibility. */ 48 | movq (%rsi), %xmm4 49 | movd %ecx, %xmm1 50 | movl $64, %eax 51 | subl %ecx, %eax 52 | movd %eax, %xmm0 53 | movdqa %xmm4, %xmm3 54 | psllq %xmm0, %xmm4 55 | movq %xmm4, %rax 56 | leaq (%rsi,%rdx,8), %rsi 57 | leaq (%rdi,%rdx,8), %rdi 58 | negq %rdx 59 | addq $2, %rdx 60 | jg .Lendo 61 | 62 | ALIGN(4) /* minimal alignment for claimed speed */ 63 | .Loop: movq -8(%rsi,%rdx,8), %xmm5 64 | movdqa %xmm5, %xmm2 65 | psllq %xmm0, %xmm5 66 | psrlq %xmm1, %xmm3 67 | por %xmm5, %xmm3 68 | movq %xmm3, -16(%rdi,%rdx,8) 69 | je .Lende 70 | movq (%rsi,%rdx,8), %xmm4 71 | movdqa %xmm4, %xmm3 72 | psllq %xmm0, %xmm4 73 | psrlq %xmm1, %xmm2 74 | por %xmm4, %xmm2 75 | movq %xmm2, -8(%rdi,%rdx,8) 76 | addq $2, %rdx 77 | jle .Loop 78 | 79 | .Lendo: movdqa %xmm3, %xmm2 80 | .Lende: psrlq %xmm1, %xmm2 81 | movq %xmm2, -8(%rdi) 82 | FUNC_EXIT() 83 | -------------------------------------------------------------------------------- /mpi/arm/distfiles: -------------------------------------------------------------------------------- 1 | mpi-asm-defs.h 2 | mpih-add1.S 3 | mpih-mul1.S 4 | mpih-mul2.S 5 | mpih-mul3.S 6 | mpih-sub1.S 7 | -------------------------------------------------------------------------------- /mpi/arm/mpi-asm-defs.h: -------------------------------------------------------------------------------- 1 | /* This file defines some basic constants for the MPI machinery. We 2 | * need to define the types on a per-CPU basis, so it is done with 3 | * this file here. */ 4 | #define BYTES_PER_MPI_LIMB (SIZEOF_UNSIGNED_LONG) 5 | -------------------------------------------------------------------------------- /mpi/arm/mpih-add1.S: -------------------------------------------------------------------------------- 1 | /* ARM add_n -- Add two limb vectors of the same length > 0 and store 2 | * sum in a third limb vector. 3 | * 4 | * Copyright (C) 2013 Jussi Kivilinna 5 | * 6 | * This file is part of Libgcrypt. 7 | * 8 | * Libgcrypt is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as 10 | * published by the Free Software Foundation; either version 2.1 of 11 | * the License, or (at your option) any later version. 12 | * 13 | * Libgcrypt is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this program; if not, see . 20 | * 21 | * Note: This code is heavily based on the GNU MP Library (version 4.2.1). 22 | */ 23 | 24 | #include "sysdep.h" 25 | #include "asm-syntax.h" 26 | 27 | .syntax unified 28 | .arm 29 | 30 | /******************* 31 | * mpi_limb_t 32 | * _gcry_mpih_add_n( mpi_ptr_t res_ptr, r0 33 | * mpi_ptr_t s1_ptr, r1 34 | * mpi_ptr_t s2_ptr, r2 35 | * mpi_size_t size) r3 36 | */ 37 | 38 | .text 39 | 40 | .globl _gcry_mpih_add_n 41 | .type _gcry_mpih_add_n,%function 42 | _gcry_mpih_add_n: 43 | push {r4, r5, r6, r7, r8, r9, r10, lr}; 44 | cmn r0, #0; /* clear carry flag */ 45 | 46 | tst r3, #3; 47 | beq .Large_loop; 48 | 49 | .Loop: 50 | ldr r4, [r1], #4; 51 | sub r3, #1; 52 | ldr lr, [r2], #4; 53 | adcs r4, lr; 54 | tst r3, #3; 55 | str r4, [r0], #4; 56 | bne .Loop; 57 | 58 | teq r3, #0; 59 | beq .Lend; 60 | 61 | .Large_loop: 62 | ldm r1!, {r4, r6, r8, r10}; 63 | ldm r2!, {r5, r7, r9, lr}; 64 | sub r3, #4; 65 | adcs r4, r5; 66 | adcs r6, r7; 67 | adcs r8, r9; 68 | adcs r10, lr; 69 | teq r3, #0; 70 | stm r0!, {r4, r6, r8, r10}; 71 | bne .Large_loop; 72 | 73 | .Lend: 74 | adc r0, r3, #0; 75 | pop {r4, r5, r6, r7, r8, r9, r10, pc}; 76 | .size _gcry_mpih_add_n,.-_gcry_mpih_add_n; 77 | -------------------------------------------------------------------------------- /mpi/arm/mpih-mul1.S: -------------------------------------------------------------------------------- 1 | /* ARM mul_1 -- Multiply a limb vector with a limb and store the result in 2 | * a second limb vector. 3 | * 4 | * Copyright (C) 2013 Jussi Kivilinna 5 | * 6 | * This file is part of Libgcrypt. 7 | * 8 | * Libgcrypt is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as 10 | * published by the Free Software Foundation; either version 2.1 of 11 | * the License, or (at your option) any later version. 12 | * 13 | * Libgcrypt is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this program; if not, see . 20 | * 21 | * Note: This code is heavily based on the GNU MP Library (version 4.2.1). 22 | */ 23 | 24 | #include "sysdep.h" 25 | #include "asm-syntax.h" 26 | 27 | .syntax unified 28 | .arm 29 | 30 | /******************* 31 | * mpi_limb_t 32 | * _gcry_mpih_mul_1( mpi_ptr_t res_ptr, r0 33 | * mpi_ptr_t s1_ptr, r1 34 | * mpi_size_t s1_size, r2 35 | * mpi_limb_t s2_limb) r3 36 | */ 37 | 38 | .text 39 | 40 | .globl _gcry_mpih_mul_1 41 | .type _gcry_mpih_mul_1,%function 42 | _gcry_mpih_mul_1: 43 | push {r4, r5, r6, r7, r8, r9, r10, r11, lr}; 44 | mov r4, #0; 45 | 46 | tst r2, #3; 47 | beq .Large_loop; 48 | 49 | .Loop: 50 | ldr r5, [r1], #4; 51 | mov lr, #0; 52 | umlal r4, lr, r5, r3; 53 | sub r2, #1; 54 | str r4, [r0], #4; 55 | tst r2, #3; 56 | mov r4, lr; 57 | bne .Loop; 58 | 59 | teq r2, #0; 60 | beq .Lend; 61 | 62 | .Large_loop: 63 | ldm r1!, {r5, r6, r7, r8}; 64 | mov r9, #0; 65 | mov r10, #0; 66 | umlal r4, r9, r5, r3; 67 | mov r11, #0; 68 | umlal r9, r10, r6, r3; 69 | str r4, [r0], #4; 70 | mov r4, #0; 71 | umlal r10, r11, r7, r3; 72 | subs r2, #4; 73 | umlal r11, r4, r8, r3; 74 | stm r0!, {r9, r10, r11}; 75 | bne .Large_loop; 76 | 77 | .Lend: 78 | mov r0, r4; 79 | pop {r4, r5, r6, r7, r8, r9, r10, r11, pc}; 80 | .size _gcry_mpih_mul_1,.-_gcry_mpih_mul_1; 81 | -------------------------------------------------------------------------------- /mpi/arm/mpih-mul2.S: -------------------------------------------------------------------------------- 1 | /* ARM mul_2 -- Multiply a limb vector with a limb and add the result to 2 | * a second limb vector. 3 | * 4 | * Copyright (C) 2013 Jussi Kivilinna 5 | * 6 | * This file is part of Libgcrypt. 7 | * 8 | * Libgcrypt is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as 10 | * published by the Free Software Foundation; either version 2.1 of 11 | * the License, or (at your option) any later version. 12 | * 13 | * Libgcrypt is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this program; if not, see . 20 | * 21 | * Note: This code is heavily based on the GNU MP Library (version 4.2.1). 22 | */ 23 | 24 | #include "sysdep.h" 25 | #include "asm-syntax.h" 26 | 27 | .syntax unified 28 | .arm 29 | 30 | /******************* 31 | * mpi_limb_t 32 | * _gcry_mpih_addmul_1( mpi_ptr_t res_ptr, r0 33 | * mpi_ptr_t s1_ptr, r1 34 | * mpi_size_t s1_size, r2 35 | * mpi_limb_t s2_limb) r3 36 | */ 37 | 38 | .text 39 | 40 | .globl _gcry_mpih_addmul_1 41 | .type _gcry_mpih_addmul_1,%function 42 | _gcry_mpih_addmul_1: 43 | push {r4, r5, r6, r8, r10, lr}; 44 | mov lr, #0; 45 | cmn r0, #0; /* clear carry flag */ 46 | 47 | tst r2, #3; 48 | beq .Large_loop; 49 | .Loop: 50 | ldr r5, [r1], #4; 51 | ldr r4, [r0]; 52 | sub r2, #1; 53 | adcs r4, lr; 54 | mov lr, #0; 55 | umlal r4, lr, r5, r3; 56 | tst r2, #3; 57 | str r4, [r0], #4; 58 | bne .Loop; 59 | 60 | teq r2, #0; 61 | beq .Lend; 62 | 63 | .Large_loop: 64 | ldr r5, [r1], #4; 65 | ldm r0, {r4, r6, r8, r10}; 66 | 67 | sub r2, #4; 68 | adcs r4, lr; 69 | mov lr, #0; 70 | umlal r4, lr, r5, r3; 71 | 72 | ldr r5, [r1], #4; 73 | adcs r6, lr; 74 | mov lr, #0; 75 | umlal r6, lr, r5, r3; 76 | 77 | ldr r5, [r1], #4; 78 | adcs r8, lr; 79 | mov lr, #0; 80 | umlal r8, lr, r5, r3; 81 | 82 | ldr r5, [r1], #4; 83 | adcs r10, lr; 84 | mov lr, #0; 85 | umlal r10, lr, r5, r3; 86 | 87 | teq r2, #0; 88 | stm r0!, {r4, r6, r8, r10}; 89 | bne .Large_loop; 90 | 91 | .Lend: 92 | adc r0, lr, #0; 93 | pop {r4, r5, r6, r8, r10, pc}; 94 | .size _gcry_mpih_addmul_1,.-_gcry_mpih_addmul_1; 95 | -------------------------------------------------------------------------------- /mpi/arm/mpih-mul3.S: -------------------------------------------------------------------------------- 1 | /* ARM mul_3 -- Multiply a limb vector with a limb and subtract the result 2 | * from a second limb vector. 3 | * 4 | * Copyright (C) 2013 Jussi Kivilinna 5 | * 6 | * This file is part of Libgcrypt. 7 | * 8 | * Libgcrypt is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as 10 | * published by the Free Software Foundation; either version 2.1 of 11 | * the License, or (at your option) any later version. 12 | * 13 | * Libgcrypt is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this program; if not, see . 20 | * 21 | * Note: This code is heavily based on the GNU MP Library (version 4.2.1). 22 | */ 23 | 24 | #include "sysdep.h" 25 | #include "asm-syntax.h" 26 | 27 | .syntax unified 28 | .arm 29 | 30 | /******************* 31 | * mpi_limb_t 32 | * _gcry_mpih_submul_1( mpi_ptr_t res_ptr, r0 33 | * mpi_ptr_t s1_ptr, r1 34 | * mpi_size_t s1_size, r2 35 | * mpi_limb_t s2_limb) r3 36 | */ 37 | 38 | .text 39 | 40 | .globl _gcry_mpih_submul_1 41 | .type _gcry_mpih_submul_1,%function 42 | _gcry_mpih_submul_1: 43 | push {r4, r5, r6, r8, r9, r10, lr}; 44 | mov lr, #0; 45 | cmp r0, #0; /* prepare carry flag for sbc */ 46 | 47 | tst r2, #3; 48 | beq .Large_loop; 49 | .Loop: 50 | ldr r5, [r1], #4; 51 | mov r4, lr; 52 | mov lr, #0; 53 | ldr r6, [r0]; 54 | umlal r4, lr, r5, r3; 55 | sub r2, #1; 56 | sbcs r4, r6, r4; 57 | tst r2, #3; 58 | str r4, [r0], #4; 59 | bne .Loop; 60 | 61 | teq r2, #0; 62 | beq .Lend; 63 | 64 | .Large_loop: 65 | ldr r5, [r1], #4; 66 | mov r9, #0; 67 | ldr r4, [r0, #0]; 68 | 69 | umlal lr, r9, r5, r3; 70 | ldr r6, [r0, #4]; 71 | ldr r5, [r1], #4; 72 | sbcs r4, r4, lr; 73 | 74 | mov lr, #0; 75 | umlal r9, lr, r5, r3; 76 | ldr r8, [r0, #8]; 77 | ldr r5, [r1], #4; 78 | sbcs r6, r6, r9; 79 | 80 | mov r9, #0; 81 | umlal lr, r9, r5, r3; 82 | ldr r10, [r0, #12]; 83 | ldr r5, [r1], #4; 84 | sbcs r8, r8, lr; 85 | 86 | mov lr, #0; 87 | umlal r9, lr, r5, r3; 88 | sub r2, #4; 89 | sbcs r10, r10, r9; 90 | 91 | teq r2, #0; 92 | stm r0!, {r4, r6, r8, r10}; 93 | bne .Large_loop; 94 | 95 | .Lend: 96 | it cc 97 | movcc r2, #1; 98 | add r0, lr, r2; 99 | pop {r4, r5, r6, r8, r9, r10, pc}; 100 | .size _gcry_mpih_submul_1,.-_gcry_mpih_submul_1; 101 | -------------------------------------------------------------------------------- /mpi/arm/mpih-sub1.S: -------------------------------------------------------------------------------- 1 | /* ARM sub_n -- Subtract two limb vectors of the same length > 0 and store 2 | * sum in a third limb vector. 3 | * 4 | * Copyright (C) 2013 Jussi Kivilinna 5 | * 6 | * This file is part of Libgcrypt. 7 | * 8 | * Libgcrypt is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as 10 | * published by the Free Software Foundation; either version 2.1 of 11 | * the License, or (at your option) any later version. 12 | * 13 | * Libgcrypt is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this program; if not, see . 20 | * 21 | * Note: This code is heavily based on the GNU MP Library (version 4.2.1). 22 | */ 23 | 24 | #include "sysdep.h" 25 | #include "asm-syntax.h" 26 | 27 | .syntax unified 28 | .arm 29 | 30 | /******************* 31 | * mpi_limb_t 32 | * _gcry_mpih_sub_n( mpi_ptr_t res_ptr, r0 33 | * mpi_ptr_t s1_ptr, r1 34 | * mpi_ptr_t s2_ptr, r2 35 | * mpi_size_t size) r3 36 | */ 37 | 38 | .text 39 | 40 | .globl _gcry_mpih_sub_n 41 | .type _gcry_mpih_sub_n,%function 42 | _gcry_mpih_sub_n: 43 | push {r4, r5, r6, r7, r8, r9, r10, lr}; 44 | cmp r0, #0; /* prepare carry flag for sub */ 45 | 46 | tst r3, #3; 47 | beq .Large_loop; 48 | 49 | .Loop: 50 | ldr r4, [r1], #4; 51 | sub r3, #1; 52 | ldr lr, [r2], #4; 53 | sbcs r4, lr; 54 | tst r3, #3; 55 | str r4, [r0], #4; 56 | bne .Loop; 57 | 58 | teq r3, #0; 59 | beq .Lend; 60 | 61 | .Large_loop: 62 | ldm r1!, {r4, r6, r8, r10}; 63 | sub r3, #4; 64 | ldm r2!, {r5, r7, r9, lr}; 65 | sbcs r4, r5; 66 | sbcs r6, r7; 67 | sbcs r8, r9; 68 | sbcs r10, lr; 69 | teq r3, #0; 70 | stm r0!, {r4, r6, r8, r10}; 71 | bne .Large_loop; 72 | 73 | .Lend: 74 | sbc r0, r3, #0; 75 | neg r0, r0; 76 | pop {r4, r5, r6, r7, r8, r9, r10, pc}; 77 | .size _gcry_mpih_sub_n,.-_gcry_mpih_sub_n; 78 | -------------------------------------------------------------------------------- /mpi/asm-common-aarch64.h: -------------------------------------------------------------------------------- 1 | /* asm-common-aarch64.h - Common macros for AArch64 assembly 2 | * 3 | * Copyright (C) 2018 Martin Storsjö 4 | * 5 | * This file is part of Libgcrypt. 6 | * 7 | * Libgcrypt is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation; either version 2.1 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * Libgcrypt is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this program; if not, see . 19 | */ 20 | 21 | #ifndef MPI_ASM_COMMON_AARCH64_H 22 | #define MPI_ASM_COMMON_AARCH64_H 23 | 24 | #include "../cipher/asm-common-aarch64.h" 25 | 26 | #endif /* MPI_ASM_COMMON_AARCH64_H */ 27 | -------------------------------------------------------------------------------- /mpi/asm-common-amd64.h: -------------------------------------------------------------------------------- 1 | /* asm-common-amd64.h - Common macros for AMD64 assembly 2 | * 3 | * Copyright (C) 2022 Jussi Kivilinna 4 | * 5 | * This file is part of Libgcrypt. 6 | * 7 | * Libgcrypt is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation; either version 2.1 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * Libgcrypt is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this program; if not, see . 19 | */ 20 | 21 | #ifndef MPI_ASM_COMMON_AMD64_H 22 | #define MPI_ASM_COMMON_AMD64_H 23 | 24 | #include "../cipher/asm-common-amd64.h" 25 | 26 | #endif /* MPI_ASM_COMMON_AMD64_H */ 27 | -------------------------------------------------------------------------------- /mpi/asm-common-i386.h: -------------------------------------------------------------------------------- 1 | /* asm-common-i386.h - Common macros for AMD64 assembly 2 | * 3 | * Copyright (C) 2023 Jussi Kivilinna 4 | * 5 | * This file is part of Libgcrypt. 6 | * 7 | * Libgcrypt is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation; either version 2.1 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * Libgcrypt is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this program; if not, see . 19 | */ 20 | 21 | #ifndef MPI_ASM_COMMON_I386_H 22 | #define MPI_ASM_COMMON_I386_H 23 | 24 | #include "../cipher/asm-common-i386.h" 25 | 26 | #endif /* MPI_ASM_COMMON_I386_H */ 27 | -------------------------------------------------------------------------------- /mpi/ec-ed25519.c: -------------------------------------------------------------------------------- 1 | /* ec-ed25519.c - Ed25519 optimized elliptic curve functions 2 | * Copyright (C) 2013 g10 Code GmbH 3 | * 4 | * This file is part of Libgcrypt. 5 | * 6 | * Libgcrypt is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Libgcrypt is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include "mpi-internal.h" 26 | #include "longlong.h" 27 | #include "g10lib.h" 28 | #include "context.h" 29 | #include "ec-context.h" 30 | #include "ec-internal.h" 31 | 32 | void 33 | _gcry_mpi_ec_ed25519_mod (gcry_mpi_t a) 34 | { 35 | (void)a; 36 | 37 | } 38 | -------------------------------------------------------------------------------- /mpi/ec-internal.h: -------------------------------------------------------------------------------- 1 | /* ec-internal.h - Internal declarations of ec*.c 2 | * Copyright (C) 2013 g10 Code GmbH 3 | * 4 | * This file is part of Libgcrypt. 5 | * 6 | * Libgcrypt is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Libgcrypt is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | */ 19 | 20 | #ifndef GCRY_EC_INTERNAL_H 21 | #define GCRY_EC_INTERNAL_H 22 | 23 | #include 24 | 25 | void _gcry_mpi_ec_ed25519_mod (gcry_mpi_t a); 26 | 27 | #ifndef ASM_DISABLED 28 | void _gcry_mpi_ec_nist192_mod (gcry_mpi_t w, mpi_ec_t ctx); 29 | void _gcry_mpi_ec_nist224_mod (gcry_mpi_t w, mpi_ec_t ctx); 30 | void _gcry_mpi_ec_nist256_mod (gcry_mpi_t w, mpi_ec_t ctx); 31 | void _gcry_mpi_ec_nist384_mod (gcry_mpi_t w, mpi_ec_t ctx); 32 | void _gcry_mpi_ec_nist521_mod (gcry_mpi_t w, mpi_ec_t ctx); 33 | #else 34 | # define _gcry_mpi_ec_nist192_mod NULL 35 | # define _gcry_mpi_ec_nist224_mod NULL 36 | # define _gcry_mpi_ec_nist256_mod NULL 37 | # define _gcry_mpi_ec_nist384_mod NULL 38 | # define _gcry_mpi_ec_nist521_mod NULL 39 | #endif 40 | 41 | #ifdef HAVE_GCC_INLINE_ASM_S390X 42 | int _gcry_s390x_ec_hw_mul_point (mpi_point_t result, gcry_mpi_t scalar, 43 | mpi_point_t point, mpi_ec_t ctx); 44 | # define mpi_ec_hw_mul_point _gcry_s390x_ec_hw_mul_point 45 | #else 46 | # define mpi_ec_hw_mul_point(r,s,p,c) (-1) 47 | #endif 48 | 49 | #endif /*GCRY_EC_INTERNAL_H*/ 50 | -------------------------------------------------------------------------------- /mpi/generic/distfiles: -------------------------------------------------------------------------------- 1 | mpih-add1.c 2 | mpih-mul1.c 3 | mpih-mul2.c 4 | mpih-mul3.c 5 | mpih-lshift.c 6 | mpih-rshift.c 7 | mpih-sub1.c 8 | udiv-w-sdiv.c 9 | mpi-asm-defs.h 10 | 11 | -------------------------------------------------------------------------------- /mpi/generic/mpi-asm-defs.h: -------------------------------------------------------------------------------- 1 | /* This file defines some basic constants for the MPI machinery. 2 | * AMD64 compiled for the x32 ABI is special and thus we can't use the 3 | * standard values for this ABI. */ 4 | #if (__GNUC__ >= 3 && defined(__x86_64__) && defined(__ILP32__)) || (defined(_WIN64) || defined(_MSC_VER) && (defined(__x86_64__) || defined(__x86_64) || defined(_M_X64))) 5 | #define BYTES_PER_MPI_LIMB 8 6 | #else 7 | #define BYTES_PER_MPI_LIMB (SIZEOF_UNSIGNED_LONG) 8 | #endif 9 | -------------------------------------------------------------------------------- /mpi/generic/mpih-add1.c: -------------------------------------------------------------------------------- 1 | /* mpihelp-add_1.c - MPI helper functions 2 | * Copyright (C) 1994, 1996, 1997, 1998, 3 | * 2000, 2002 Free Software Foundation, Inc. 4 | * 5 | * This file is part of Libgcrypt. 6 | * 7 | * Libgcrypt is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation; either version 2.1 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * Libgcrypt is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this program; if not, see . 19 | * SPDX-License-Identifier: LGPL-2.1-or-later 20 | * 21 | * Note: This code is heavily based on the GNU MP Library. 22 | * Actually it's the same code with only minor changes in the 23 | * way the data is stored; this is to support the abstraction 24 | * of an optional secure memory allocation which may be used 25 | * to avoid revealing of sensitive data due to paging etc. 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include "mpi-internal.h" 32 | #include "longlong.h" 33 | 34 | mpi_limb_t 35 | _gcry_mpih_add_n (mpi_ptr_t res_ptr, mpi_ptr_t s1_ptr, 36 | mpi_ptr_t s2_ptr, mpi_size_t size) 37 | { 38 | mpi_limb_t x, y, cy; 39 | mpi_size_t j; 40 | 41 | /* The loop counter and index J goes from -SIZE to -1. This way 42 | the loop becomes faster. */ 43 | j = -size; 44 | 45 | /* Offset the base pointers to compensate for the negative indices. */ 46 | s1_ptr -= j; 47 | s2_ptr -= j; 48 | res_ptr -= j; 49 | 50 | cy = 0; 51 | do 52 | { 53 | y = s2_ptr[j]; 54 | x = s1_ptr[j]; 55 | y += cy; /* add previous carry to one addend */ 56 | cy = y < cy; /* get out carry from that addition */ 57 | y += x; /* add other addend */ 58 | cy += y < x; /* get out carry from that add, combine */ 59 | res_ptr[j] = y; 60 | } 61 | while ( ++j ); 62 | 63 | return cy; 64 | } 65 | 66 | -------------------------------------------------------------------------------- /mpi/generic/mpih-lshift.c: -------------------------------------------------------------------------------- 1 | /* mpi-lshift.c - MPI helper functions 2 | * Copyright (C) 1994, 1996, 1998, 2001, 2002 Free Software Foundation, Inc. 3 | * 4 | * This file is part of Libgcrypt. 5 | * 6 | * Libgcrypt is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Libgcrypt is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | * 20 | * Note: This code is heavily based on the GNU MP Library. 21 | * Actually it's the same code with only minor changes in the 22 | * way the data is stored; this is to support the abstraction 23 | * of an optional secure memory allocation which may be used 24 | * to avoid revealing of sensitive data due to paging etc. 25 | */ 26 | 27 | #include 28 | #include 29 | #include 30 | #include "mpi-internal.h" 31 | 32 | /* Shift U (pointed to by UP and USIZE digits long) CNT bits to the left 33 | * and store the USIZE least significant digits of the result at WP. 34 | * Return the bits shifted out from the most significant digit. 35 | * 36 | * Argument constraints: 37 | * 1. 0 < CNT < BITS_PER_MP_LIMB 38 | * 2. If the result is to be written over the input, WP must be >= UP. 39 | */ 40 | 41 | mpi_limb_t 42 | _gcry_mpih_lshift( mpi_ptr_t wp, mpi_ptr_t up, mpi_size_t usize, 43 | unsigned int cnt) 44 | { 45 | mpi_limb_t high_limb, low_limb; 46 | unsigned sh_1, sh_2; 47 | mpi_size_t i; 48 | mpi_limb_t retval; 49 | 50 | sh_1 = cnt; 51 | wp += 1; 52 | sh_2 = BITS_PER_MPI_LIMB - sh_1; 53 | i = usize - 1; 54 | low_limb = up[i]; 55 | retval = low_limb >> sh_2; 56 | high_limb = low_limb; 57 | while ( --i >= 0 ) 58 | { 59 | low_limb = up[i]; 60 | wp[i] = (high_limb << sh_1) | (low_limb >> sh_2); 61 | high_limb = low_limb; 62 | } 63 | wp[i] = high_limb << sh_1; 64 | 65 | return retval; 66 | } 67 | 68 | 69 | -------------------------------------------------------------------------------- /mpi/generic/mpih-mul1.c: -------------------------------------------------------------------------------- 1 | /* mpihelp-mul_1.c - MPI helper functions 2 | * Copyright (C) 1994, 1996, 1997, 1998, 2001, 3 | * 2002 Free Software Foundation, Inc. 4 | * 5 | * This file is part of Libgcrypt. 6 | * 7 | * Libgcrypt is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation; either version 2.1 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * Libgcrypt is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this program; if not, see . 19 | * SPDX-License-Identifier: LGPL-2.1-or-later 20 | * 21 | * Note: This code is heavily based on the GNU MP Library. 22 | * Actually it's the same code with only minor changes in the 23 | * way the data is stored; this is to support the abstraction 24 | * of an optional secure memory allocation which may be used 25 | * to avoid revealing of sensitive data due to paging etc. 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include "mpi-internal.h" 32 | #include "longlong.h" 33 | 34 | mpi_limb_t 35 | _gcry_mpih_mul_1( mpi_ptr_t res_ptr, mpi_ptr_t s1_ptr, mpi_size_t s1_size, 36 | mpi_limb_t s2_limb) 37 | { 38 | mpi_limb_t cy_limb; 39 | mpi_size_t j; 40 | mpi_limb_t prod_high, prod_low; 41 | 42 | /* The loop counter and index J goes from -S1_SIZE to -1. This way 43 | * the loop becomes faster. */ 44 | j = -s1_size; 45 | 46 | /* Offset the base pointers to compensate for the negative indices. */ 47 | s1_ptr -= j; 48 | res_ptr -= j; 49 | 50 | cy_limb = 0; 51 | do 52 | { 53 | umul_ppmm( prod_high, prod_low, s1_ptr[j], s2_limb ); 54 | prod_low += cy_limb; 55 | cy_limb = (prod_low < cy_limb?1:0) + prod_high; 56 | res_ptr[j] = prod_low; 57 | } 58 | while( ++j ); 59 | 60 | return cy_limb; 61 | } 62 | 63 | -------------------------------------------------------------------------------- /mpi/generic/mpih-mul2.c: -------------------------------------------------------------------------------- 1 | /* mpih-mul2.c - MPI helper functions 2 | * Copyright (C) 1994, 1996, 1997, 1998, 2001, 3 | * 2002 Free Software Foundation, Inc. 4 | * 5 | * This file is part of Libgcrypt. 6 | * 7 | * Libgcrypt is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation; either version 2.1 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * Libgcrypt is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this program; if not, see . 19 | * SPDX-License-Identifier: LGPL-2.1-or-later 20 | * 21 | * Note: This code is heavily based on the GNU MP Library. 22 | * Actually it's the same code with only minor changes in the 23 | * way the data is stored; this is to support the abstraction 24 | * of an optional secure memory allocation which may be used 25 | * to avoid revealing of sensitive data due to paging etc. 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include "mpi-internal.h" 32 | #include "longlong.h" 33 | 34 | 35 | mpi_limb_t 36 | _gcry_mpih_addmul_1( mpi_ptr_t res_ptr, mpi_ptr_t s1_ptr, 37 | mpi_size_t s1_size, mpi_limb_t s2_limb) 38 | { 39 | mpi_limb_t cy_limb; 40 | mpi_size_t j; 41 | mpi_limb_t prod_high, prod_low; 42 | mpi_limb_t x; 43 | 44 | /* The loop counter and index J goes from -SIZE to -1. This way 45 | * the loop becomes faster. */ 46 | j = -s1_size; 47 | res_ptr -= j; 48 | s1_ptr -= j; 49 | 50 | cy_limb = 0; 51 | do 52 | { 53 | umul_ppmm( prod_high, prod_low, s1_ptr[j], s2_limb ); 54 | 55 | prod_low += cy_limb; 56 | cy_limb = (prod_low < cy_limb?1:0) + prod_high; 57 | 58 | x = res_ptr[j]; 59 | prod_low = x + prod_low; 60 | cy_limb += prod_low < x?1:0; 61 | res_ptr[j] = prod_low; 62 | } 63 | while ( ++j ); 64 | 65 | return cy_limb; 66 | } 67 | 68 | 69 | -------------------------------------------------------------------------------- /mpi/generic/mpih-mul3.c: -------------------------------------------------------------------------------- 1 | /* mpih-mul3.c - MPI helper functions 2 | * Copyright (C) 1994, 1996, 1997, 1998, 2001, 3 | * 2002 Free Software Foundation, Inc. 4 | * 5 | * This file is part of Libgcrypt. 6 | * 7 | * Libgcrypt is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation; either version 2.1 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * Libgcrypt is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this program; if not, see . 19 | * SPDX-License-Identifier: LGPL-2.1-or-later 20 | * 21 | * Note: This code is heavily based on the GNU MP Library. 22 | * Actually it's the same code with only minor changes in the 23 | * way the data is stored; this is to support the abstraction 24 | * of an optional secure memory allocation which may be used 25 | * to avoid revealing of sensitive data due to paging etc. 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include "mpi-internal.h" 32 | #include "longlong.h" 33 | 34 | 35 | mpi_limb_t 36 | _gcry_mpih_submul_1( mpi_ptr_t res_ptr, mpi_ptr_t s1_ptr, 37 | mpi_size_t s1_size, mpi_limb_t s2_limb) 38 | { 39 | mpi_limb_t cy_limb; 40 | mpi_size_t j; 41 | mpi_limb_t prod_high, prod_low; 42 | mpi_limb_t x; 43 | 44 | /* The loop counter and index J goes from -SIZE to -1. This way 45 | * the loop becomes faster. */ 46 | j = -s1_size; 47 | res_ptr -= j; 48 | s1_ptr -= j; 49 | 50 | cy_limb = 0; 51 | do 52 | { 53 | umul_ppmm( prod_high, prod_low, s1_ptr[j], s2_limb); 54 | 55 | prod_low += cy_limb; 56 | cy_limb = (prod_low < cy_limb?1:0) + prod_high; 57 | 58 | x = res_ptr[j]; 59 | prod_low = x - prod_low; 60 | cy_limb += prod_low > x?1:0; 61 | res_ptr[j] = prod_low; 62 | } 63 | while( ++j ); 64 | 65 | return cy_limb; 66 | } 67 | 68 | 69 | -------------------------------------------------------------------------------- /mpi/generic/mpih-rshift.c: -------------------------------------------------------------------------------- 1 | /* mpih-rshift.c - MPI helper functions 2 | * Copyright (C) 1994, 1996, 1998, 1999, 3 | * 2000, 2001, 2002 Free Software Foundation, Inc. 4 | * 5 | * This file is part of Libgcrypt. 6 | * 7 | * Libgcrypt is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation; either version 2.1 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * Libgcrypt is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this program; if not, see . 19 | * SPDX-License-Identifier: LGPL-2.1-or-later 20 | * 21 | * Note: This code is heavily based on the GNU MP Library. 22 | * Actually it's the same code with only minor changes in the 23 | * way the data is stored; this is to support the abstraction 24 | * of an optional secure memory allocation which may be used 25 | * to avoid revealing of sensitive data due to paging etc. 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include "mpi-internal.h" 32 | 33 | 34 | /* Shift U (pointed to by UP and USIZE limbs long) CNT bits to the right 35 | * and store the USIZE least significant limbs of the result at WP. 36 | * The bits shifted out to the right are returned. 37 | * 38 | * Argument constraints: 39 | * 1. 0 < CNT < BITS_PER_MP_LIMB 40 | * 2. If the result is to be written over the input, WP must be <= UP. 41 | */ 42 | 43 | mpi_limb_t 44 | _gcry_mpih_rshift( mpi_ptr_t wp, mpi_ptr_t up, mpi_size_t usize, unsigned cnt) 45 | { 46 | mpi_limb_t high_limb, low_limb; 47 | unsigned sh_1, sh_2; 48 | mpi_size_t i; 49 | mpi_limb_t retval; 50 | 51 | sh_1 = cnt; 52 | wp -= 1; 53 | sh_2 = BITS_PER_MPI_LIMB - sh_1; 54 | high_limb = up[0]; 55 | retval = high_limb << sh_2; 56 | low_limb = high_limb; 57 | for (i=1; i < usize; i++) 58 | { 59 | high_limb = up[i]; 60 | wp[i] = (low_limb >> sh_1) | (high_limb << sh_2); 61 | low_limb = high_limb; 62 | } 63 | wp[i] = low_limb >> sh_1; 64 | 65 | return retval; 66 | } 67 | 68 | -------------------------------------------------------------------------------- /mpi/generic/mpih-sub1.c: -------------------------------------------------------------------------------- 1 | /* mpihelp-add_2.c - MPI helper functions 2 | * Copyright (C) 1994, 1996, 1997, 1998, 2001, 3 | * 2002 Free Software Foundation, Inc. 4 | * 5 | * This file is part of Libgcrypt. 6 | * 7 | * Libgcrypt is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation; either version 2.1 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * Libgcrypt is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this program; if not, see . 19 | * SPDX-License-Identifier: LGPL-2.1-or-later 20 | * 21 | * Note: This code is heavily based on the GNU MP Library. 22 | * Actually it's the same code with only minor changes in the 23 | * way the data is stored; this is to support the abstraction 24 | * of an optional secure memory allocation which may be used 25 | * to avoid revealing of sensitive data due to paging etc. 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include "mpi-internal.h" 32 | #include "longlong.h" 33 | 34 | mpi_limb_t 35 | _gcry_mpih_sub_n( mpi_ptr_t res_ptr, mpi_ptr_t s1_ptr, 36 | mpi_ptr_t s2_ptr, mpi_size_t size) 37 | { 38 | mpi_limb_t x, y, cy; 39 | mpi_size_t j; 40 | 41 | /* The loop counter and index J goes from -SIZE to -1. This way 42 | the loop becomes faster. */ 43 | j = -size; 44 | 45 | /* Offset the base pointers to compensate for the negative indices. */ 46 | s1_ptr -= j; 47 | s2_ptr -= j; 48 | res_ptr -= j; 49 | 50 | cy = 0; 51 | do 52 | { 53 | y = s2_ptr[j]; 54 | x = s1_ptr[j]; 55 | y += cy; /* add previous carry to subtrahend */ 56 | cy = y < cy; /* get out carry from that addition */ 57 | y = x - y; /* main subtract */ 58 | cy += y > x; /* get out carry from the subtract, combine */ 59 | res_ptr[j] = y; 60 | } 61 | while( ++j ); 62 | 63 | return cy; 64 | } 65 | 66 | 67 | -------------------------------------------------------------------------------- /mpi/hppa/README: -------------------------------------------------------------------------------- 1 | This directory contains mpn functions for various HP PA-RISC chips. Code 2 | that runs faster on the PA7100 and later implementations, is in the pa7100 3 | directory. 4 | 5 | RELEVANT OPTIMIZATION ISSUES 6 | 7 | Load and Store timing 8 | 9 | On the PA7000 no memory instructions can issue the two cycles after a store. 10 | For the PA7100, this is reduced to one cycle. 11 | 12 | The PA7100 has a lookup-free cache, so it helps to schedule loads and the 13 | dependent instruction really far from each other. 14 | 15 | STATUS 16 | 17 | 1. mpn_mul_1 could be improved to 6.5 cycles/limb on the PA7100, using the 18 | instructions bwlow (but some sw pipelining is needed to avoid the 19 | xmpyu-fstds delay): 20 | 21 | fldds s1_ptr 22 | 23 | xmpyu 24 | fstds N(%r30) 25 | xmpyu 26 | fstds N(%r30) 27 | 28 | ldws N(%r30) 29 | ldws N(%r30) 30 | ldws N(%r30) 31 | ldws N(%r30) 32 | 33 | addc 34 | stws res_ptr 35 | addc 36 | stws res_ptr 37 | 38 | addib Loop 39 | 40 | 2. mpn_addmul_1 could be improved from the current 10 to 7.5 cycles/limb 41 | (asymptotically) on the PA7100, using the instructions below. With proper 42 | sw pipelining and the unrolling level below, the speed becomes 8 43 | cycles/limb. 44 | 45 | fldds s1_ptr 46 | fldds s1_ptr 47 | 48 | xmpyu 49 | fstds N(%r30) 50 | xmpyu 51 | fstds N(%r30) 52 | xmpyu 53 | fstds N(%r30) 54 | xmpyu 55 | fstds N(%r30) 56 | 57 | ldws N(%r30) 58 | ldws N(%r30) 59 | ldws N(%r30) 60 | ldws N(%r30) 61 | ldws N(%r30) 62 | ldws N(%r30) 63 | ldws N(%r30) 64 | ldws N(%r30) 65 | addc 66 | addc 67 | addc 68 | addc 69 | addc %r0,%r0,cy-limb 70 | 71 | ldws res_ptr 72 | ldws res_ptr 73 | ldws res_ptr 74 | ldws res_ptr 75 | add 76 | stws res_ptr 77 | addc 78 | stws res_ptr 79 | addc 80 | stws res_ptr 81 | addc 82 | stws res_ptr 83 | 84 | addib 85 | -------------------------------------------------------------------------------- /mpi/hppa/distfiles: -------------------------------------------------------------------------------- 1 | README 2 | udiv-qrnnd.S 3 | mpih-add1.S 4 | mpih-sub1.S 5 | mpih-lshift.S 6 | mpih-rshift.S 7 | 8 | -------------------------------------------------------------------------------- /mpi/hppa/mpih-add1.S: -------------------------------------------------------------------------------- 1 | /* hppa add_n -- Add two limb vectors of the same length > 0 and store 2 | * sum in a third limb vector. 3 | * 4 | * Copyright (C) 1992, 1994, 1998, 5 | * 2001, 2002 Fee Software Foundation, Inc. 6 | * 7 | * This file is part of Libgcrypt. 8 | * 9 | * Libgcrypt is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as 11 | * published by the Free Software Foundation; either version 2.1 of 12 | * the License, or (at your option) any later version. 13 | * 14 | * Libgcrypt is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with this program; if not, see . 21 | * SPDX-License-Identifier: LGPL-2.1-or-later 22 | * 23 | * Note: This code is heavily based on the GNU MP Library. 24 | * Actually it's the same code with only minor changes in the 25 | * way the data is stored; this is to support the abstraction 26 | * of an optional secure memory allocation which may be used 27 | * to avoid revealing of sensitive data due to paging etc. 28 | */ 29 | 30 | 31 | 32 | /******************* 33 | * mpi_limb_t 34 | * _gcry_mpih_add_n( mpi_ptr_t res_ptr, (gr26) 35 | * mpi_ptr_t s1_ptr, (gr25) 36 | * mpi_ptr_t s2_ptr, (gr24) 37 | * mpi_size_t size) (gr23) 38 | * 39 | * One might want to unroll this as for other processors, but it turns 40 | * out that the data cache contention after a store makes such 41 | * unrolling useless. We can't come under 5 cycles/limb anyway. 42 | */ 43 | 44 | .code 45 | .export _gcry_mpih_add_n 46 | .label _gcry_mpih_add_n 47 | .proc 48 | .callinfo frame=0,no_calls 49 | .entry 50 | 51 | ldws,ma 4(0,%r25),%r20 52 | ldws,ma 4(0,%r24),%r19 53 | 54 | addib,= -1,%r23,L$end ; check for (SIZE == 1) 55 | add %r20,%r19,%r28 ; add first limbs ignoring cy 56 | 57 | .label L$loop 58 | ldws,ma 4(0,%r25),%r20 59 | ldws,ma 4(0,%r24),%r19 60 | stws,ma %r28,4(0,%r26) 61 | addib,<> -1,%r23,L$loop 62 | addc %r20,%r19,%r28 63 | 64 | .label L$end 65 | stws %r28,0(0,%r26) 66 | bv 0(%r2) 67 | addc %r0,%r0,%r28 68 | 69 | .exit 70 | .procend 71 | -------------------------------------------------------------------------------- /mpi/hppa/mpih-lshift.S: -------------------------------------------------------------------------------- 1 | /* hppa lshift 2 | * 3 | * Copyright (C) 1992, 1994, 1998 4 | * 2001, 2002 Free Software Foundation, Inc. 5 | * 6 | * This file is part of Libgcrypt. 7 | * 8 | * Libgcrypt is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as 10 | * published by the Free Software Foundation; either version 2.1 of 11 | * the License, or (at your option) any later version. 12 | * 13 | * Libgcrypt is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this program; if not, see . 20 | * SPDX-License-Identifier: LGPL-2.1-or-later 21 | */ 22 | 23 | 24 | 25 | /******************* 26 | * mpi_limb_t 27 | * _gcry_mpih_lshift( mpi_ptr_t wp, (gr26) 28 | * mpi_ptr_t up, (gr25) 29 | * mpi_size_t usize, (gr24) 30 | * unsigned cnt) (gr23) 31 | */ 32 | 33 | .code 34 | .export _gcry_mpih_lshift 35 | .label _gcry_mpih_lshift 36 | .proc 37 | .callinfo frame=64,no_calls 38 | .entry 39 | 40 | sh2add %r24,%r25,%r25 41 | sh2add %r24,%r26,%r26 42 | ldws,mb -4(0,%r25),%r22 43 | subi 32,%r23,%r1 44 | mtsar %r1 45 | addib,= -1,%r24,L$0004 46 | vshd %r0,%r22,%r28 ; compute carry out limb 47 | ldws,mb -4(0,%r25),%r29 48 | addib,= -1,%r24,L$0002 49 | vshd %r22,%r29,%r20 50 | 51 | .label L$loop 52 | ldws,mb -4(0,%r25),%r22 53 | stws,mb %r20,-4(0,%r26) 54 | addib,= -1,%r24,L$0003 55 | vshd %r29,%r22,%r20 56 | ldws,mb -4(0,%r25),%r29 57 | stws,mb %r20,-4(0,%r26) 58 | addib,<> -1,%r24,L$loop 59 | vshd %r22,%r29,%r20 60 | 61 | .label L$0002 62 | stws,mb %r20,-4(0,%r26) 63 | vshd %r29,%r0,%r20 64 | bv 0(%r2) 65 | stw %r20,-4(0,%r26) 66 | .label L$0003 67 | stws,mb %r20,-4(0,%r26) 68 | .label L$0004 69 | vshd %r22,%r0,%r20 70 | bv 0(%r2) 71 | stw %r20,-4(0,%r26) 72 | 73 | .exit 74 | .procend 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /mpi/hppa/mpih-rshift.S: -------------------------------------------------------------------------------- 1 | /* hppa rshift 2 | * 3 | * Copyright (C) 1992, 1994, 1998, 4 | * 2001, 2002 Free Software Foundation, Inc. 5 | * 6 | * This file is part of Libgcrypt. 7 | * 8 | * Libgcrypt is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as 10 | * published by the Free Software Foundation; either version 2.1 of 11 | * the License, or (at your option) any later version. 12 | * 13 | * Libgcrypt is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this program; if not, see . 20 | * SPDX-License-Identifier: LGPL-2.1-or-later 21 | */ 22 | 23 | 24 | 25 | 26 | /******************* 27 | * mpi_limb_t 28 | * _gcry_mpih_rshift( mpi_ptr_t wp, (gr26) 29 | * mpi_ptr_t up, (gr25) 30 | * mpi_size_t usize, (gr24) 31 | * unsigned cnt) (gr23) 32 | */ 33 | 34 | .code 35 | .export _gcry_mpih_rshift 36 | .label _gcry_mpih_rshift 37 | .proc 38 | .callinfo frame=64,no_calls 39 | .entry 40 | 41 | ldws,ma 4(0,%r25),%r22 42 | mtsar %r23 43 | addib,= -1,%r24,L$r004 44 | vshd %r22,%r0,%r28 ; compute carry out limb 45 | ldws,ma 4(0,%r25),%r29 46 | addib,= -1,%r24,L$r002 47 | vshd %r29,%r22,%r20 48 | 49 | .label L$roop 50 | ldws,ma 4(0,%r25),%r22 51 | stws,ma %r20,4(0,%r26) 52 | addib,= -1,%r24,L$r003 53 | vshd %r22,%r29,%r20 54 | ldws,ma 4(0,%r25),%r29 55 | stws,ma %r20,4(0,%r26) 56 | addib,<> -1,%r24,L$roop 57 | vshd %r29,%r22,%r20 58 | 59 | .label L$r002 60 | stws,ma %r20,4(0,%r26) 61 | vshd %r0,%r29,%r20 62 | bv 0(%r2) 63 | stw %r20,0(0,%r26) 64 | .label L$r003 65 | stws,ma %r20,4(0,%r26) 66 | .label L$r004 67 | vshd %r0,%r22,%r20 68 | bv 0(%r2) 69 | stw %r20,0(0,%r26) 70 | 71 | .exit 72 | .procend 73 | 74 | -------------------------------------------------------------------------------- /mpi/hppa/mpih-sub1.S: -------------------------------------------------------------------------------- 1 | /* hppa sub_n -- Sub two limb vectors of the same length > 0 and store 2 | * sum in a third limb vector. 3 | * 4 | * Copyright (C) 1992, 1994, 1998, 5 | * 2001, 2002 Free Software Foundation, Inc. 6 | * 7 | * This file is part of Libgcrypt. 8 | * 9 | * Libgcrypt is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as 11 | * published by the Free Software Foundation; either version 2.1 of 12 | * the License, or (at your option) any later version. 13 | * 14 | * Libgcrypt is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with this program; if not, see . 21 | * SPDX-License-Identifier: LGPL-2.1-or-later 22 | * 23 | * Note: This code is heavily based on the GNU MP Library. 24 | * Actually it's the same code with only minor changes in the 25 | * way the data is stored; this is to support the abstraction 26 | * of an optional secure memory allocation which may be used 27 | * to avoid revealing of sensitive data due to paging etc. 28 | */ 29 | 30 | 31 | #include "sysdep.h" 32 | #include "asm-syntax.h" 33 | 34 | 35 | /******************* 36 | * mpi_limb_t 37 | * _gcry_mpih_sub_n( mpi_ptr_t res_ptr, (gr26) 38 | * mpi_ptr_t s1_ptr, (gr25) 39 | * mpi_ptr_t s2_ptr, (gr24) 40 | * mpi_size_t size) (gr23) 41 | * 42 | * One might want to unroll this as for other processors, but it turns 43 | * out that the data cache contention after a store makes such 44 | * unrolling useless. We can't come under 5 cycles/limb anyway. 45 | */ 46 | 47 | 48 | .code 49 | .export _gcry_mpih_sub_n 50 | .label _gcry_mpih_sub_n 51 | .proc 52 | .callinfo frame=0,no_calls 53 | .entry 54 | 55 | ldws,ma 4(0,%r25),%r20 56 | ldws,ma 4(0,%r24),%r19 57 | 58 | addib,= -1,%r23,L$end ; check for (SIZE == 1) 59 | sub %r20,%r19,%r28 ; subtract first limbs ignoring cy 60 | 61 | .label L$loop 62 | ldws,ma 4(0,%r25),%r20 63 | ldws,ma 4(0,%r24),%r19 64 | stws,ma %r28,4(0,%r26) 65 | addib,<> -1,%r23,L$loop 66 | subb %r20,%r19,%r28 67 | 68 | .label L$end 69 | stws %r28,0(0,%r26) 70 | addc %r0,%r0,%r28 71 | bv 0(%r2) 72 | subi 1,%r28,%r28 73 | 74 | .exit 75 | .procend 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /mpi/hppa1.1/distfiles: -------------------------------------------------------------------------------- 1 | udiv-qrnnd.S 2 | mpih-mul1.S 3 | mpih-mul2.S 4 | mpih-mul3.S 5 | 6 | -------------------------------------------------------------------------------- /mpi/hppa1.1/udiv-qrnnd.S: -------------------------------------------------------------------------------- 1 | /* HP-PA __udiv_qrnnd division support, used from longlong.h. 2 | * This version runs fast on PA 7000 and later. 3 | * 4 | * Copyright (C) 1993, 1994, 1998, 5 | * 2001, 2002, 2004 Free Software Foundation, Inc. 6 | * 7 | * This file is part of Libgcrypt. 8 | * 9 | * Libgcrypt is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as 11 | * published by the Free Software Foundation; either version 2.1 of 12 | * the License, or (at your option) any later version. 13 | * 14 | * Libgcrypt is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with this program; if not, see . 21 | * SPDX-License-Identifier: LGPL-2.1-or-later 22 | * 23 | * Note: This code is heavily based on the GNU MP Library. 24 | * Actually it's the same code with only minor changes in the 25 | * way the data is stored; this is to support the abstraction 26 | * of an optional secure memory allocation which may be used 27 | * to avoid revealing of sensitive data due to paging etc. 28 | */ 29 | 30 | 31 | 32 | /* INPUT PARAMETERS 33 | * rem_ptr gr26 34 | * n1 gr25 35 | * n0 gr24 36 | * d gr23 37 | */ 38 | 39 | .level 1.1 40 | 41 | .data 42 | .align 8 43 | .label L$0000 44 | .word 0x43f00000 45 | .word 0x0 46 | .code 47 | .export __udiv_qrnnd 48 | .label __udiv_qrnnd 49 | .proc 50 | .callinfo frame=64,no_calls 51 | .entry 52 | ldo 64(%r30),%r30 53 | 54 | stws %r25,-16(0,%r30) ; n_hi 55 | stws %r24,-12(0,%r30) ; n_lo 56 | stw %r19,-32(%r30) 57 | addil LT%L$0000,%r19 58 | ldw RT%L$0000(%r1),%r1 59 | fldds -16(0,%r30),%fr5 60 | stws %r23,-12(0,%r30) 61 | comib,<= 0,%r25,L$1 62 | fcnvxf,dbl,dbl %fr5,%fr5 63 | fldds 0(0,%r1),%fr4 64 | fadd,dbl %fr4,%fr5,%fr5 65 | .label L$1 66 | fcpy,sgl %fr0,%fr6L 67 | fldws -12(0,%r30),%fr6R 68 | fcnvxf,dbl,dbl %fr6,%fr4 69 | 70 | fdiv,dbl %fr5,%fr4,%fr5 71 | 72 | fcnvfx,dbl,dbl %fr5,%fr4 73 | fstws %fr4R,-16(%r30) 74 | xmpyu %fr4R,%fr6R,%fr6 75 | ldws -16(%r30),%r28 76 | fstds %fr6,-16(0,%r30) 77 | ldws -12(0,%r30),%r21 78 | ldws -16(0,%r30),%r20 79 | sub %r24,%r21,%r22 80 | subb %r25,%r20,%r1 81 | comib,= 0,%r1,L$2 82 | ldo -64(%r30),%r30 83 | 84 | add %r22,%r23,%r22 85 | ldo -1(%r28),%r28 86 | .label L$2 87 | bv 0(%r2) 88 | stws %r22,0(0,%r26) 89 | 90 | .exit 91 | .procend 92 | 93 | -------------------------------------------------------------------------------- /mpi/i386/distfiles: -------------------------------------------------------------------------------- 1 | mpih-add1.S 2 | mpih-mul1.S 3 | mpih-mul2.S 4 | mpih-mul3.S 5 | mpih-lshift.S 6 | mpih-rshift.S 7 | mpih-sub1.S 8 | syntax.h 9 | 10 | -------------------------------------------------------------------------------- /mpi/i386/syntax.h: -------------------------------------------------------------------------------- 1 | /* syntax.h -- Definitions for x86 syntax variations. 2 | * 3 | * Copyright (C) 1992, 1994, 1995, 1998, 4 | * 2001, 2002 Free Software Foundation, Inc. 5 | * 6 | * This file is part of Libgcrypt. 7 | * 8 | * Libgcrypt is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as 10 | * published by the Free Software Foundation; either version 2.1 of 11 | * the License, or (at your option) any later version. 12 | * 13 | * Libgcrypt is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this program; if not, see . 20 | * SPDX-License-Identifier: LGPL-2.1-or-later 21 | * 22 | * Note: This code is heavily based on the GNU MP Library. 23 | * Actually it's the same code with only minor changes in the 24 | * way the data is stored; this is to support the abstraction 25 | * of an optional secure memory allocation which may be used 26 | * to avoid revealing of sensitive data due to paging etc. 27 | */ 28 | 29 | #include 30 | 31 | #ifdef __i386__ 32 | #include "asm-common-i386.h" 33 | #endif 34 | 35 | #undef ALIGN 36 | 37 | #if defined (BSD_SYNTAX) || defined (ELF_SYNTAX) 38 | #define R(r) %r 39 | #define MEM(base)(base) 40 | #define MEM_DISP(base,displacement)displacement(R(base)) 41 | #define MEM_INDEX(base,index,size)(R(base),R(index),size) 42 | #ifdef __STDC__ 43 | #define INSN1(mnemonic,size_suffix,dst)mnemonic##size_suffix dst 44 | #define INSN2(mnemonic,size_suffix,dst,src)mnemonic##size_suffix src,dst 45 | #else 46 | #define INSN1(mnemonic,size_suffix,dst)mnemonic/**/size_suffix dst 47 | #define INSN2(mnemonic,size_suffix,dst,src)mnemonic/**/size_suffix src,dst 48 | #endif 49 | #define TEXT .text 50 | #if defined (BSD_SYNTAX) 51 | #define ALIGN(log) .align log 52 | #endif 53 | #if defined (ELF_SYNTAX) 54 | #define ALIGN(log) .align 1<<(log) 55 | #endif 56 | #define GLOBL .globl 57 | #endif 58 | 59 | #ifdef INTEL_SYNTAX 60 | #define R(r) r 61 | #define MEM(base)[base] 62 | #define MEM_DISP(base,displacement)[base+(displacement)] 63 | #define MEM_INDEX(base,index,size)[base+index*size] 64 | #define INSN1(mnemonic,size_suffix,dst)mnemonic dst 65 | #define INSN2(mnemonic,size_suffix,dst,src)mnemonic dst,src 66 | #define TEXT .text 67 | #define ALIGN(log) .align log 68 | #define GLOBL .globl 69 | #endif 70 | 71 | #ifdef X86_BROKEN_ALIGN 72 | #undef ALIGN 73 | #define ALIGN(log) .align log,0x90 74 | #endif 75 | 76 | /* 'ret' instruction replacement for straight-line speculation mitigation */ 77 | #define ret_spec_stop \ 78 | ret; int3; 79 | -------------------------------------------------------------------------------- /mpi/m68k/distfiles: -------------------------------------------------------------------------------- 1 | syntax.h 2 | mpih-lshift.S 3 | mpih-rshift.S 4 | mpih-add1.S 5 | mpih-sub1.S 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /mpi/m68k/mc68020/distfiles: -------------------------------------------------------------------------------- 1 | mpih-mul1.S 2 | mpih-mul2.S 3 | mpih-mul3.S 4 | -------------------------------------------------------------------------------- /mpi/m68k/mpih-add1.S: -------------------------------------------------------------------------------- 1 | /* mc68020 __mpn_add_n -- Add two limb vectors of the same length > 0 and store 2 | * sum in a third limb vector. 3 | * 4 | * Copyright (C) 1992, 1994,1996, 1998, 5 | * 2001, 2002 Free Software Foundation, Inc. 6 | * 7 | * This file is part of Libgcrypt. 8 | * 9 | * Libgcrypt is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as 11 | * published by the Free Software Foundation; either version 2.1 of 12 | * the License, or (at your option) any later version. 13 | * 14 | * Libgcrypt is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with this program; if not, see . 21 | * SPDX-License-Identifier: LGPL-2.1-or-later 22 | * 23 | * Note: This code is heavily based on the GNU MP Library. 24 | * Actually it's the same code with only minor changes in the 25 | * way the data is stored; this is to support the abstraction 26 | * of an optional secure memory allocation which may be used 27 | * to avoid revealing of sensitive data due to paging etc. 28 | */ 29 | 30 | 31 | #include "sysdep.h" 32 | #include "asm-syntax.h" 33 | 34 | 35 | /******************* 36 | * mpi_limb_t 37 | * _gcry_mpih_add_n( mpi_ptr_t res_ptr, (sp + 4) 38 | * mpi_ptr_t s1_ptr, (sp + 8) 39 | * mpi_ptr_t s2_ptr, (sp + 16) 40 | * mpi_size_t size) (sp + 12) 41 | */ 42 | 43 | 44 | TEXT 45 | ALIGN 46 | GLOBL C_SYMBOL_NAME(_gcry_mpih_add_n) 47 | 48 | C_SYMBOL_NAME(_gcry_mpih_add_n:) 49 | PROLOG(_gcry_mpih_add_n) 50 | /* Save used registers on the stack. */ 51 | movel R(d2),MEM_PREDEC(sp) 52 | movel R(a2),MEM_PREDEC(sp) 53 | 54 | /* Copy the arguments to registers. Better use movem? */ 55 | movel MEM_DISP(sp,12),R(a2) 56 | movel MEM_DISP(sp,16),R(a0) 57 | movel MEM_DISP(sp,20),R(a1) 58 | movel MEM_DISP(sp,24),R(d2) 59 | 60 | eorw #1,R(d2) 61 | lsrl #1,R(d2) 62 | bcc L(L1) 63 | subql #1,R(d2) /* clears cy as side effect */ 64 | 65 | L(Loop:) 66 | movel MEM_POSTINC(a0),R(d0) 67 | movel MEM_POSTINC(a1),R(d1) 68 | addxl R(d1),R(d0) 69 | movel R(d0),MEM_POSTINC(a2) 70 | L(L1:) movel MEM_POSTINC(a0),R(d0) 71 | movel MEM_POSTINC(a1),R(d1) 72 | addxl R(d1),R(d0) 73 | movel R(d0),MEM_POSTINC(a2) 74 | 75 | dbf R(d2),L(Loop) /* loop until 16 lsb of %4 == -1 */ 76 | subxl R(d0),R(d0) /* d0 <= -cy; save cy as 0 or -1 in d0 */ 77 | subl #0x10000,R(d2) 78 | bcs L(L2) 79 | addl R(d0),R(d0) /* restore cy */ 80 | bra L(Loop) 81 | 82 | L(L2:) 83 | negl R(d0) 84 | 85 | /* Restore used registers from stack frame. */ 86 | movel MEM_POSTINC(sp),R(a2) 87 | movel MEM_POSTINC(sp),R(d2) 88 | 89 | rts 90 | EPILOG(_gcry_mpih_add_n) 91 | 92 | 93 | -------------------------------------------------------------------------------- /mpi/m68k/mpih-sub1.S: -------------------------------------------------------------------------------- 1 | /* mc68020 __mpn_sub_n -- Subtract two limb vectors of the same length > 0 and 2 | * store difference in a third limb vector. 3 | * 4 | * Copyright (C) 1992, 1994, 1996, 1998, 5 | * 2001, 2002 Free Software Foundation, Inc. 6 | * 7 | * This file is part of Libgcrypt. 8 | * 9 | * Libgcrypt is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as 11 | * published by the Free Software Foundation; either version 2.1 of 12 | * the License, or (at your option) any later version. 13 | * 14 | * Libgcrypt is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with this program; if not, see . 21 | * SPDX-License-Identifier: LGPL-2.1-or-later 22 | * 23 | * Note: This code is heavily based on the GNU MP Library. 24 | * Actually it's the same code with only minor changes in the 25 | * way the data is stored; this is to support the abstraction 26 | * of an optional secure memory allocation which may be used 27 | * to avoid revealing of sensitive data due to paging etc. 28 | */ 29 | 30 | #include "sysdep.h" 31 | #include "asm-syntax.h" 32 | 33 | 34 | /******************* 35 | * mpi_limb_t 36 | * _gcry_mpih_sub_n( mpi_ptr_t res_ptr, (sp + 4) 37 | * mpi_ptr_t s1_ptr, (sp + 8) 38 | * mpi_ptr_t s2_ptr, (sp + 16) 39 | * mpi_size_t size) (sp + 12) 40 | */ 41 | 42 | 43 | TEXT 44 | ALIGN 45 | GLOBL C_SYMBOL_NAME(_gcry_mpih_sub_n) 46 | 47 | C_SYMBOL_NAME(_gcry_mpih_sub_n:) 48 | PROLOG(_gcry_mpih_sub_n) 49 | /* Save used registers on the stack. */ 50 | movel R(d2),MEM_PREDEC(sp) 51 | movel R(a2),MEM_PREDEC(sp) 52 | 53 | /* Copy the arguments to registers. Better use movem? */ 54 | movel MEM_DISP(sp,12),R(a2) 55 | movel MEM_DISP(sp,16),R(a0) 56 | movel MEM_DISP(sp,20),R(a1) 57 | movel MEM_DISP(sp,24),R(d2) 58 | 59 | eorw #1,R(d2) 60 | lsrl #1,R(d2) 61 | bcc L(L1) 62 | subql #1,R(d2) /* clears cy as side effect */ 63 | 64 | L(Loop:) 65 | movel MEM_POSTINC(a0),R(d0) 66 | movel MEM_POSTINC(a1),R(d1) 67 | subxl R(d1),R(d0) 68 | movel R(d0),MEM_POSTINC(a2) 69 | L(L1:) movel MEM_POSTINC(a0),R(d0) 70 | movel MEM_POSTINC(a1),R(d1) 71 | subxl R(d1),R(d0) 72 | movel R(d0),MEM_POSTINC(a2) 73 | 74 | dbf R(d2),L(Loop) /* loop until 16 lsb of %4 == -1 */ 75 | subxl R(d0),R(d0) /* d0 <= -cy; save cy as 0 or -1 in d0 */ 76 | subl #0x10000,R(d2) 77 | bcs L(L2) 78 | addl R(d0),R(d0) /* restore cy */ 79 | bra L(Loop) 80 | 81 | L(L2:) 82 | negl R(d0) 83 | 84 | /* Restore used registers from stack frame. */ 85 | movel MEM_POSTINC(sp),R(a2) 86 | movel MEM_POSTINC(sp),R(d2) 87 | 88 | rts 89 | EPILOG(_gcry_mpih_sub_n) 90 | 91 | 92 | -------------------------------------------------------------------------------- /mpi/mips3/README: -------------------------------------------------------------------------------- 1 | This directory contains mpn functions optimized for MIPS3. Example of 2 | processors that implement MIPS3 are R4000, R4400, R4600, R4700, and R8000. 3 | 4 | RELEVANT OPTIMIZATION ISSUES 5 | 6 | 1. On the R4000 and R4400, branches, both the plain and the "likely" ones, 7 | take 3 cycles to execute. (The fastest possible loop will take 4 cycles, 8 | because of the delay insn.) 9 | 10 | On the R4600, branches takes a single cycle 11 | 12 | On the R8000, branches often take no noticeable cycles, as they are 13 | executed in a separate function unit.. 14 | 15 | 2. The R4000 and R4400 have a load latency of 4 cycles. 16 | 17 | 3. On the R4000 and R4400, multiplies take a data-dependent number of 18 | cycles, contrary to the SGI documentation. There seem to be 3 or 4 19 | possible latencies. 20 | 21 | STATUS 22 | 23 | Good... 24 | -------------------------------------------------------------------------------- /mpi/mips3/distfiles: -------------------------------------------------------------------------------- 1 | README 2 | mpih-add1.S 3 | mpih-sub1.S 4 | mpih-mul1.S 5 | mpih-mul2.S 6 | mpih-mul3.S 7 | mpih-lshift.S 8 | mpih-rshift.S 9 | mpi-asm-defs.h 10 | 11 | -------------------------------------------------------------------------------- /mpi/mips3/mpi-asm-defs.h: -------------------------------------------------------------------------------- 1 | /* This file defines some basic constants for the MPI machinery. We 2 | * need to define the types on a per-CPU basis, so it is done with 3 | * this file here. */ 4 | #define BYTES_PER_MPI_LIMB 8 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /mpi/mips3/mpih-lshift.S: -------------------------------------------------------------------------------- 1 | /* mips3 lshift 2 | * 3 | * Copyright (C) 1995, 1998, 2000, 4 | * 2001, 2002 Free Software Foundation, Inc. 5 | * 6 | * This file is part of Libgcrypt. 7 | * 8 | * Libgcrypt is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as 10 | * published by the Free Software Foundation; either version 2.1 of 11 | * the License, or (at your option) any later version. 12 | * 13 | * Libgcrypt is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this program; if not, see . 20 | * SPDX-License-Identifier: LGPL-2.1-or-later 21 | */ 22 | 23 | /******************* 24 | * mpi_limb_t 25 | * _gcry_mpih_lshift( mpi_ptr_t wp, ($4) 26 | * mpi_ptr_t up, ($5) 27 | * mpi_size_t usize, ($6) 28 | * unsigned cnt) ($7) 29 | */ 30 | 31 | .text 32 | .align 2 33 | .globl _gcry_mpih_lshift 34 | .ent _gcry_mpih_lshift 35 | _gcry_mpih_lshift: 36 | .set noreorder 37 | .set nomacro 38 | 39 | dsll $2,$6,3 40 | daddu $5,$5,$2 # make r5 point at end of src 41 | ld $10,-8($5) # load first limb 42 | dsubu $13,$0,$7 43 | daddu $4,$4,$2 # make r4 point at end of res 44 | daddiu $6,$6,-1 45 | and $9,$6,4-1 # number of limbs in first loop 46 | beq $9,$0,.L0 # if multiple of 4 limbs, skip first loop 47 | dsrl $2,$10,$13 # compute function result 48 | 49 | dsubu $6,$6,$9 50 | 51 | .Loop0: ld $3,-16($5) 52 | daddiu $4,$4,-8 53 | daddiu $5,$5,-8 54 | daddiu $9,$9,-1 55 | dsll $11,$10,$7 56 | dsrl $12,$3,$13 57 | move $10,$3 58 | or $8,$11,$12 59 | bne $9,$0,.Loop0 60 | sd $8,0($4) 61 | 62 | .L0: beq $6,$0,.Lend 63 | nop 64 | 65 | .Loop: ld $3,-16($5) 66 | daddiu $4,$4,-32 67 | daddiu $6,$6,-4 68 | dsll $11,$10,$7 69 | dsrl $12,$3,$13 70 | 71 | ld $10,-24($5) 72 | dsll $14,$3,$7 73 | or $8,$11,$12 74 | sd $8,24($4) 75 | dsrl $9,$10,$13 76 | 77 | ld $3,-32($5) 78 | dsll $11,$10,$7 79 | or $8,$14,$9 80 | sd $8,16($4) 81 | dsrl $12,$3,$13 82 | 83 | ld $10,-40($5) 84 | dsll $14,$3,$7 85 | or $8,$11,$12 86 | sd $8,8($4) 87 | dsrl $9,$10,$13 88 | 89 | daddiu $5,$5,-32 90 | or $8,$14,$9 91 | bgtz $6,.Loop 92 | sd $8,0($4) 93 | 94 | .Lend: dsll $8,$10,$7 95 | j $31 96 | sd $8,-8($4) 97 | .end _gcry_mpih_lshift 98 | -------------------------------------------------------------------------------- /mpi/mips3/mpih-mul1.S: -------------------------------------------------------------------------------- 1 | /* mips3 mpih-mul1.S -- Multiply a limb vector with a limb and store 2 | * the result in a second limb vector. 3 | * 4 | * Copyright (C) 1992, 1994, 1995, 1998, 2000 5 | * 2001, 2002 Free Software Foundation, Inc. 6 | * 7 | * This file is part of Libgcrypt. 8 | * 9 | * Libgcrypt is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as 11 | * published by the Free Software Foundation; either version 2.1 of 12 | * the License, or (at your option) any later version. 13 | * 14 | * Libgcrypt is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with this program; if not, see . 21 | * SPDX-License-Identifier: LGPL-2.1-or-later 22 | */ 23 | 24 | 25 | /******************* 26 | * mpi_limb_t 27 | * _gcry_mpih_mul_1( mpi_ptr_t res_ptr, (r4) 28 | * mpi_ptr_t s1_ptr, (r5) 29 | * mpi_size_t s1_size, (r6) 30 | * mpi_limb_t s2_limb) (r7) 31 | */ 32 | 33 | .text 34 | .align 4 35 | .globl _gcry_mpih_mul_1 36 | .ent _gcry_mpih_mul_1 37 | _gcry_mpih_mul_1: 38 | .set noreorder 39 | .set nomacro 40 | 41 | /* # warm up phase 0 */ 42 | ld $8,0($5) 43 | 44 | /* # warm up phase 1 */ 45 | daddiu $5,$5,8 46 | dmultu $8,$7 47 | 48 | daddiu $6,$6,-1 49 | beq $6,$0,$LC0 50 | move $2,$0 # zero cy2 51 | 52 | daddiu $6,$6,-1 53 | beq $6,$0,$LC1 54 | ld $8,0($5) # load new s1 limb as early as possible 55 | 56 | Loop: mflo $10 57 | mfhi $9 58 | daddiu $5,$5,8 59 | daddu $10,$10,$2 # add old carry limb to low product limb 60 | dmultu $8,$7 61 | ld $8,0($5) # load new s1 limb as early as possible 62 | daddiu $6,$6,-1 # decrement loop counter 63 | sltu $2,$10,$2 # carry from previous addition -> $2 64 | sd $10,0($4) 65 | daddiu $4,$4,8 66 | bne $6,$0,Loop 67 | daddu $2,$9,$2 # add high product limb and carry from addition 68 | 69 | /* # cool down phase 1 */ 70 | $LC1: mflo $10 71 | mfhi $9 72 | daddu $10,$10,$2 73 | sltu $2,$10,$2 74 | dmultu $8,$7 75 | sd $10,0($4) 76 | daddiu $4,$4,8 77 | daddu $2,$9,$2 # add high product limb and carry from addition 78 | 79 | /* # cool down phase 0 */ 80 | $LC0: mflo $10 81 | mfhi $9 82 | daddu $10,$10,$2 83 | sltu $2,$10,$2 84 | sd $10,0($4) 85 | j $31 86 | daddu $2,$9,$2 # add high product limb and carry from addition 87 | 88 | .end _gcry_mpih_mul_1 89 | 90 | -------------------------------------------------------------------------------- /mpi/mips3/mpih-mul2.S: -------------------------------------------------------------------------------- 1 | /* MIPS3 addmul_1 -- Multiply a limb vector with a single limb and 2 | * add the product to a second limb vector. 3 | * 4 | * Copyright (C) 1992, 1994, 1995, 1998, 2000 5 | * 2001, 2002 Free Software Foundation, Inc. 6 | * 7 | * This file is part of Libgcrypt. 8 | * 9 | * Libgcrypt is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as 11 | * published by the Free Software Foundation; either version 2.1 of 12 | * the License, or (at your option) any later version. 13 | * 14 | * Libgcrypt is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with this program; if not, see . 21 | * SPDX-License-Identifier: LGPL-2.1-or-later 22 | */ 23 | 24 | 25 | /******************* 26 | * mpi_limb_t 27 | * _gcry_mpih_addmul_1( mpi_ptr_t res_ptr, (r4) 28 | * mpi_ptr_t s1_ptr, (r5) 29 | * mpi_size_t s1_size, (r6) 30 | * mpi_limb_t s2_limb) (r7) 31 | */ 32 | 33 | .text 34 | .align 4 35 | .globl _gcry_mpih_addmul_1 36 | .ent _gcry_mpih_addmul_1 37 | _gcry_mpih_addmul_1: 38 | .set noreorder 39 | .set nomacro 40 | 41 | /* # warm up phase 0 */ 42 | ld $8,0($5) 43 | 44 | /* # warm up phase 1 */ 45 | daddiu $5,$5,8 46 | dmultu $8,$7 47 | 48 | daddiu $6,$6,-1 49 | beq $6,$0,$LC0 50 | move $2,$0 # zero cy2 51 | 52 | daddiu $6,$6,-1 53 | beq $6,$0,$LC1 54 | ld $8,0($5) # load new s1 limb as early as possible 55 | 56 | Loop: ld $10,0($4) 57 | mflo $3 58 | mfhi $9 59 | daddiu $5,$5,8 60 | daddu $3,$3,$2 # add old carry limb to low product limb 61 | dmultu $8,$7 62 | ld $8,0($5) # load new s1 limb as early as possible 63 | daddiu $6,$6,-1 # decrement loop counter 64 | sltu $2,$3,$2 # carry from previous addition -> $2 65 | daddu $3,$10,$3 66 | sltu $10,$3,$10 67 | daddu $2,$2,$10 68 | sd $3,0($4) 69 | daddiu $4,$4,8 70 | bne $6,$0,Loop 71 | daddu $2,$9,$2 # add high product limb and carry from addition 72 | 73 | /* # cool down phase 1 */ 74 | $LC1: ld $10,0($4) 75 | mflo $3 76 | mfhi $9 77 | daddu $3,$3,$2 78 | sltu $2,$3,$2 79 | dmultu $8,$7 80 | daddu $3,$10,$3 81 | sltu $10,$3,$10 82 | daddu $2,$2,$10 83 | sd $3,0($4) 84 | daddiu $4,$4,8 85 | daddu $2,$9,$2 # add high product limb and carry from addition 86 | 87 | /* # cool down phase 0 */ 88 | $LC0: ld $10,0($4) 89 | mflo $3 90 | mfhi $9 91 | daddu $3,$3,$2 92 | sltu $2,$3,$2 93 | daddu $3,$10,$3 94 | sltu $10,$3,$10 95 | daddu $2,$2,$10 96 | sd $3,0($4) 97 | j $31 98 | daddu $2,$9,$2 # add high product limb and carry from addition 99 | 100 | .end _gcry_mpih_addmul_1 101 | 102 | -------------------------------------------------------------------------------- /mpi/mips3/mpih-mul3.S: -------------------------------------------------------------------------------- 1 | /* MIPS3 submul_1 -- Multiply a limb vector with a single limb and 2 | * subtract the product from a second limb vector. 3 | * 4 | * Copyright (C) 1992, 1994, 1995, 1998, 2000 5 | * 2001, 2002 Free Software Foundation, Inc. 6 | * 7 | * This file is part of Libgcrypt. 8 | * 9 | * Libgcrypt is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as 11 | * published by the Free Software Foundation; either version 2.1 of 12 | * the License, or (at your option) any later version. 13 | * 14 | * Libgcrypt is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with this program; if not, see . 21 | * SPDX-License-Identifier: LGPL-2.1-or-later 22 | */ 23 | 24 | 25 | /******************* 26 | * mpi_limb_t 27 | * _gcry_mpih_submul_1( mpi_ptr_t res_ptr, (r4) 28 | * mpi_ptr_t s1_ptr, (r5) 29 | * mpi_size_t s1_size, (r6) 30 | * mpi_limb_t s2_limb) (r7) 31 | */ 32 | 33 | .text 34 | .align 4 35 | .globl _gcry_mpih_submul_1 36 | .ent _gcry_mpih_submul_1 37 | _gcry_mpih_submul_1: 38 | .set noreorder 39 | .set nomacro 40 | 41 | /* # warm up phase 0 */ 42 | ld $8,0($5) 43 | 44 | /* # warm up phase 1 */ 45 | daddiu $5,$5,8 46 | dmultu $8,$7 47 | 48 | daddiu $6,$6,-1 49 | beq $6,$0,$LC0 50 | move $2,$0 # zero cy2 51 | 52 | daddiu $6,$6,-1 53 | beq $6,$0,$LC1 54 | ld $8,0($5) # load new s1 limb as early as possible 55 | 56 | Loop: ld $10,0($4) 57 | mflo $3 58 | mfhi $9 59 | daddiu $5,$5,8 60 | daddu $3,$3,$2 # add old carry limb to low product limb 61 | dmultu $8,$7 62 | ld $8,0($5) # load new s1 limb as early as possible 63 | daddiu $6,$6,-1 # decrement loop counter 64 | sltu $2,$3,$2 # carry from previous addition -> $2 65 | dsubu $3,$10,$3 66 | sgtu $10,$3,$10 67 | daddu $2,$2,$10 68 | sd $3,0($4) 69 | daddiu $4,$4,8 70 | bne $6,$0,Loop 71 | daddu $2,$9,$2 # add high product limb and carry from addition 72 | 73 | /* # cool down phase 1 */ 74 | $LC1: ld $10,0($4) 75 | mflo $3 76 | mfhi $9 77 | daddu $3,$3,$2 78 | sltu $2,$3,$2 79 | dmultu $8,$7 80 | dsubu $3,$10,$3 81 | sgtu $10,$3,$10 82 | daddu $2,$2,$10 83 | sd $3,0($4) 84 | daddiu $4,$4,8 85 | daddu $2,$9,$2 # add high product limb and carry from addition 86 | 87 | /* # cool down phase 0 */ 88 | $LC0: ld $10,0($4) 89 | mflo $3 90 | mfhi $9 91 | daddu $3,$3,$2 92 | sltu $2,$3,$2 93 | dsubu $3,$10,$3 94 | sgtu $10,$3,$10 95 | daddu $2,$2,$10 96 | sd $3,0($4) 97 | j $31 98 | daddu $2,$9,$2 # add high product limb and carry from addition 99 | 100 | .end _gcry_mpih_submul_1 101 | 102 | -------------------------------------------------------------------------------- /mpi/mips3/mpih-rshift.S: -------------------------------------------------------------------------------- 1 | /* mips3 rshift 2 | * 3 | * Copyright (C) 1995, 1998, 2000 4 | * 2001, 2002 Free Software Foundation, Inc. 5 | * 6 | * This file is part of Libgcrypt. 7 | * 8 | * Libgcrypt is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as 10 | * published by the Free Software Foundation; either version 2.1 of 11 | * the License, or (at your option) any later version. 12 | * 13 | * Libgcrypt is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this program; if not, see . 20 | * SPDX-License-Identifier: LGPL-2.1-or-later 21 | */ 22 | 23 | /******************* 24 | * mpi_limb_t 25 | * _gcry_mpih_rshift( mpi_ptr_t wp, ($4) 26 | * mpi_ptr_t up, ($5) 27 | * mpi_size_t usize, ($6) 28 | * unsigned cnt) ($7) 29 | */ 30 | 31 | .text 32 | .align 2 33 | .globl _gcry_mpih_rshift 34 | .ent _gcry_mpih_rshift 35 | _gcry_mpih_rshift: 36 | .set noreorder 37 | .set nomacro 38 | 39 | ld $10,0($5) # load first limb 40 | dsubu $13,$0,$7 41 | daddiu $6,$6,-1 42 | and $9,$6,4-1 # number of limbs in first loop 43 | beq $9,$0,.L0 # if multiple of 4 limbs, skip first loop 44 | dsll $2,$10,$13 # compute function result 45 | 46 | dsubu $6,$6,$9 47 | 48 | .Loop0: ld $3,8($5) 49 | daddiu $4,$4,8 50 | daddiu $5,$5,8 51 | daddiu $9,$9,-1 52 | dsrl $11,$10,$7 53 | dsll $12,$3,$13 54 | move $10,$3 55 | or $8,$11,$12 56 | bne $9,$0,.Loop0 57 | sd $8,-8($4) 58 | 59 | .L0: beq $6,$0,.Lend 60 | nop 61 | 62 | .Loop: ld $3,8($5) 63 | daddiu $4,$4,32 64 | daddiu $6,$6,-4 65 | dsrl $11,$10,$7 66 | dsll $12,$3,$13 67 | 68 | ld $10,16($5) 69 | dsrl $14,$3,$7 70 | or $8,$11,$12 71 | sd $8,-32($4) 72 | dsll $9,$10,$13 73 | 74 | ld $3,24($5) 75 | dsrl $11,$10,$7 76 | or $8,$14,$9 77 | sd $8,-24($4) 78 | dsll $12,$3,$13 79 | 80 | ld $10,32($5) 81 | dsrl $14,$3,$7 82 | or $8,$11,$12 83 | sd $8,-16($4) 84 | dsll $9,$10,$13 85 | 86 | daddiu $5,$5,32 87 | or $8,$14,$9 88 | bgtz $6,.Loop 89 | sd $8,-8($4) 90 | 91 | .Lend: dsrl $8,$10,$7 92 | j $31 93 | sd $8,0($4) 94 | .end _gcry_mpih_rshift 95 | 96 | -------------------------------------------------------------------------------- /mpi/mpi-gcd.c: -------------------------------------------------------------------------------- 1 | /* mpi-gcd.c - MPI functions 2 | * Copyright (C) 1998, 2001, 2002, 2003 Free Software Foundation, Inc. 3 | * 4 | * This file is part of Libgcrypt. 5 | * 6 | * Libgcrypt is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Libgcrypt is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include "mpi-internal.h" 25 | 26 | /**************** 27 | * Find the greatest common divisor G of A and B. 28 | * Return: true if this 1, false in all other cases 29 | */ 30 | int 31 | _gcry_mpi_gcd (gcry_mpi_t g, gcry_mpi_t xa, gcry_mpi_t xb) 32 | { 33 | gcry_mpi_t a, b; 34 | 35 | a = mpi_copy(xa); 36 | b = mpi_copy(xb); 37 | 38 | /* TAOCP Vol II, 4.5.2, Algorithm A */ 39 | a->sign = 0; 40 | b->sign = 0; 41 | while (mpi_cmp_ui (b, 0)) 42 | { 43 | _gcry_mpi_fdiv_r( g, a, b ); /* G is used as temporary variable. */ 44 | mpi_set(a,b); 45 | mpi_set(b,g); 46 | } 47 | mpi_set(g, a); 48 | 49 | mpi_free(a); 50 | mpi_free(b); 51 | return !mpi_cmp_ui( g, 1); 52 | } 53 | -------------------------------------------------------------------------------- /mpi/mpi-inline.c: -------------------------------------------------------------------------------- 1 | /* mpi-inline.c 2 | * Copyright (C) 1999, 2002 Free Software Foundation, Inc. 3 | * 4 | * This file is part of Libgcrypt. 5 | * 6 | * Libgcrypt is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Libgcrypt is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | /* put the inline functions as real functions into the lib */ 26 | #define G10_MPI_INLINE_DECL 27 | 28 | #include "mpi-internal.h" 29 | 30 | /* always include the header because it is only 31 | * included by mpi-internal if __GCC__ is defined but we 32 | * need it here in all cases and the above definition of 33 | * of the macro allows us to do so 34 | */ 35 | #include "mpi-inline.h" 36 | -------------------------------------------------------------------------------- /mpi/pa7100/distfiles: -------------------------------------------------------------------------------- 1 | mpih-lshift.S 2 | mpih-rshift.S 3 | 4 | -------------------------------------------------------------------------------- /mpi/pa7100/mpih-lshift.S: -------------------------------------------------------------------------------- 1 | /* hppa lshift 2 | * optimized for the PA7100, where it runs at 3.25 cycles/limb 3 | * 4 | * Copyright (C) 1992, 1994, 1998, 5 | * 2001, 2002 Free Software Foundation, Inc. 6 | * 7 | * This file is part of Libgcrypt. 8 | * 9 | * Libgcrypt is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as 11 | * published by the Free Software Foundation; either version 2.1 of 12 | * the License, or (at your option) any later version. 13 | * 14 | * Libgcrypt is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with this program; if not, see . 21 | * SPDX-License-Identifier: LGPL-2.1-or-later 22 | */ 23 | 24 | 25 | 26 | /******************* 27 | * mpi_limb_t 28 | * _gcry_mpih_lshift( mpi_ptr_t wp, (gr26) 29 | * mpi_ptr_t up, (gr25) 30 | * mpi_size_t usize, (gr24) 31 | * unsigned cnt) (gr23) 32 | */ 33 | 34 | .code 35 | .export _gcry_mpih_lshift 36 | .label _gcry_mpih_lshift 37 | .proc 38 | .callinfo frame=64,no_calls 39 | .entry 40 | 41 | sh2add %r24,%r25,%r25 42 | sh2add %r24,%r26,%r26 43 | ldws,mb -4(0,%r25),%r22 44 | subi 32,%r23,%r1 45 | mtsar %r1 46 | addib,= -1,%r24,L$0004 47 | vshd %r0,%r22,%r28 ; compute carry out limb 48 | ldws,mb -4(0,%r25),%r29 49 | addib,<= -5,%r24,L$rest 50 | vshd %r22,%r29,%r20 51 | 52 | .label L$loop 53 | ldws,mb -4(0,%r25),%r22 54 | stws,mb %r20,-4(0,%r26) 55 | vshd %r29,%r22,%r20 56 | ldws,mb -4(0,%r25),%r29 57 | stws,mb %r20,-4(0,%r26) 58 | vshd %r22,%r29,%r20 59 | ldws,mb -4(0,%r25),%r22 60 | stws,mb %r20,-4(0,%r26) 61 | vshd %r29,%r22,%r20 62 | ldws,mb -4(0,%r25),%r29 63 | stws,mb %r20,-4(0,%r26) 64 | addib,> -4,%r24,L$loop 65 | vshd %r22,%r29,%r20 66 | 67 | .label L$rest 68 | addib,= 4,%r24,L$end1 69 | nop 70 | .label L$eloop 71 | ldws,mb -4(0,%r25),%r22 72 | stws,mb %r20,-4(0,%r26) 73 | addib,<= -1,%r24,L$end2 74 | vshd %r29,%r22,%r20 75 | ldws,mb -4(0,%r25),%r29 76 | stws,mb %r20,-4(0,%r26) 77 | addib,> -1,%r24,L$eloop 78 | vshd %r22,%r29,%r20 79 | 80 | .label L$end1 81 | stws,mb %r20,-4(0,%r26) 82 | vshd %r29,%r0,%r20 83 | bv 0(%r2) 84 | stw %r20,-4(0,%r26) 85 | .label L$end2 86 | stws,mb %r20,-4(0,%r26) 87 | .label L$0004 88 | vshd %r22,%r0,%r20 89 | bv 0(%r2) 90 | stw %r20,-4(0,%r26) 91 | 92 | .exit 93 | .procend 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /mpi/pa7100/mpih-rshift.S: -------------------------------------------------------------------------------- 1 | /* hppa rshift 2 | * optimized for the PA7100, where it runs at 3.25 cycles/limb 3 | * 4 | * Copyright (C) 1992, 1994, 1998, 5 | * 2001, 2002 Free Software Foundation, Inc. 6 | * 7 | * This file is part of Libgcrypt. 8 | * 9 | * Libgcrypt is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as 11 | * published by the Free Software Foundation; either version 2.1 of 12 | * the License, or (at your option) any later version. 13 | * 14 | * Libgcrypt is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with this program; if not, see . 21 | * SPDX-License-Identifier: LGPL-2.1-or-later 22 | */ 23 | 24 | 25 | 26 | /******************* 27 | * mpi_limb_t 28 | * _gcry_mpih_rshift( mpi_ptr_t wp, (gr26) 29 | * mpi_ptr_t up, (gr25) 30 | * mpi_size_t usize, (gr24) 31 | * unsigned cnt) (gr23) 32 | */ 33 | 34 | .code 35 | .export _gcry_mpih_rshift 36 | .label _gcry_mpih_rshift 37 | .proc 38 | .callinfo frame=64,no_calls 39 | .entry 40 | 41 | ldws,ma 4(0,%r25),%r22 42 | mtsar %r23 43 | addib,= -1,%r24,L$r004 44 | vshd %r22,%r0,%r28 ; compute carry out limb 45 | ldws,ma 4(0,%r25),%r29 46 | addib,<= -5,%r24,L$rrest 47 | vshd %r29,%r22,%r20 48 | 49 | .label L$roop 50 | ldws,ma 4(0,%r25),%r22 51 | stws,ma %r20,4(0,%r26) 52 | vshd %r22,%r29,%r20 53 | ldws,ma 4(0,%r25),%r29 54 | stws,ma %r20,4(0,%r26) 55 | vshd %r29,%r22,%r20 56 | ldws,ma 4(0,%r25),%r22 57 | stws,ma %r20,4(0,%r26) 58 | vshd %r22,%r29,%r20 59 | ldws,ma 4(0,%r25),%r29 60 | stws,ma %r20,4(0,%r26) 61 | addib,> -4,%r24,L$roop 62 | vshd %r29,%r22,%r20 63 | 64 | .label L$rrest 65 | addib,= 4,%r24,L$rend1 66 | nop 67 | .label L$eroop 68 | ldws,ma 4(0,%r25),%r22 69 | stws,ma %r20,4(0,%r26) 70 | addib,<= -1,%r24,L$rend2 71 | vshd %r22,%r29,%r20 72 | ldws,ma 4(0,%r25),%r29 73 | stws,ma %r20,4(0,%r26) 74 | addib,> -1,%r24,L$eroop 75 | vshd %r29,%r22,%r20 76 | 77 | .label L$rend1 78 | stws,ma %r20,4(0,%r26) 79 | vshd %r0,%r29,%r20 80 | bv 0(%r2) 81 | stw %r20,0(0,%r26) 82 | .label L$rend2 83 | stws,ma %r20,4(0,%r26) 84 | .label L$r004 85 | vshd %r0,%r22,%r20 86 | bv 0(%r2) 87 | stw %r20,0(0,%r26) 88 | 89 | .exit 90 | .procend 91 | 92 | 93 | -------------------------------------------------------------------------------- /mpi/power/distfiles: -------------------------------------------------------------------------------- 1 | mpih-add1.S 2 | mpih-lshift.S 3 | mpih-mul1.S 4 | mpih-mul2.S 5 | mpih-mul3.S 6 | mpih-rshift.S 7 | mpih-sub1.S 8 | -------------------------------------------------------------------------------- /mpi/power/mpih-lshift.S: -------------------------------------------------------------------------------- 1 | /* IBM POWER lshift 2 | * 3 | * Copyright (C) 1992, 1994, 1999, 2002 Free Software Foundation, Inc. 4 | * 5 | * This file is part of Libgcrypt. 6 | * 7 | * Libgcrypt is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation; either version 2.1 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * Libgcrypt is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this program; if not, see . 19 | * SPDX-License-Identifier: LGPL-2.1-or-later 20 | */ 21 | 22 | #include "sysdep.h" 23 | #include "asm-syntax.h" 24 | 25 | /* 26 | # INPUT PARAMETERS 27 | # res_ptr r3 28 | # s_ptr r4 29 | # size r5 30 | # cnt r6 31 | */ 32 | 33 | .toc 34 | .extern _gcry_mpih_lshift[DS] 35 | .extern ._gcry_mpih_lshift 36 | .csect [PR] 37 | .align 2 38 | .globl _gcry_mpih_lshift 39 | .globl ._gcry_mpih_lshift 40 | .csect _gcry_mpih_lshift[DS] 41 | _gcry_mpih_lshift: 42 | .long ._gcry_mpih_lshift, TOC[tc0], 0 43 | .csect [PR] 44 | ._gcry_mpih_lshift: 45 | sli 0,5,2 46 | cax 9,3,0 47 | cax 4,4,0 48 | sfi 8,6,32 49 | mtctr 5 # put limb count in CTR loop register 50 | lu 0,-4(4) # read most significant limb 51 | sre 3,0,8 # compute carry out limb, and init MQ register 52 | bdz Lend2 # if just one limb, skip loop 53 | lu 0,-4(4) # read 2:nd most significant limb 54 | sreq 7,0,8 # compute most significant limb of result 55 | bdz Lend # if just two limb, skip loop 56 | Loop: lu 0,-4(4) # load next lower limb 57 | stu 7,-4(9) # store previous result during read latency 58 | sreq 7,0,8 # compute result limb 59 | bdn Loop # loop back until CTR is zero 60 | Lend: stu 7,-4(9) # store 2:nd least significant limb 61 | Lend2: sle 7,0,6 # compute least significant limb 62 | st 7,-4(9) # store it 63 | br 64 | 65 | -------------------------------------------------------------------------------- /mpi/power/mpih-rshift.S: -------------------------------------------------------------------------------- 1 | /* IBM POWER rshift 2 | * 3 | * Copyright (C) 1992, 1994, 1999, 2002 Free Software Foundation, Inc. 4 | * 5 | * This file is part of Libgcrypt. 6 | * 7 | * Libgcrypt is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation; either version 2.1 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * Libgcrypt is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this program; if not, see . 19 | * SPDX-License-Identifier: LGPL-2.1-or-later 20 | */ 21 | 22 | #include "sysdep.h" 23 | #include "asm-syntax.h" 24 | 25 | 26 | /* 27 | # INPUT PARAMETERS 28 | # res_ptr r3 29 | # s_ptr r4 30 | # size r5 31 | # cnt r6 32 | */ 33 | 34 | .toc 35 | .extern _gcry_mpih_rshift[DS] 36 | .extern ._gcry_mpih_rshift 37 | .csect [PR] 38 | .align 2 39 | .globl _gcry_mpih_rshift 40 | .globl ._gcry_mpih_rshift 41 | .csect _gcry_mpih_rshift[DS] 42 | _gcry_mpih_rshift: 43 | .long ._gcry_mpih_rshift, TOC[tc0], 0 44 | .csect [PR] 45 | ._gcry_mpih_rshift: 46 | sfi 8,6,32 47 | mtctr 5 # put limb count in CTR loop register 48 | l 0,0(4) # read least significant limb 49 | ai 9,3,-4 # adjust res_ptr since it's offset in the stu:s 50 | sle 3,0,8 # compute carry limb, and init MQ register 51 | bdz Lend2 # if just one limb, skip loop 52 | lu 0,4(4) # read 2:nd least significant limb 53 | sleq 7,0,8 # compute least significant limb of result 54 | bdz Lend # if just two limb, skip loop 55 | Loop: lu 0,4(4) # load next higher limb 56 | stu 7,4(9) # store previous result during read latency 57 | sleq 7,0,8 # compute result limb 58 | bdn Loop # loop back until CTR is zero 59 | Lend: stu 7,4(9) # store 2:nd most significant limb 60 | Lend2: sre 7,0,6 # compute most significant limb 61 | st 7,4(9) # store it 62 | br 63 | 64 | 65 | -------------------------------------------------------------------------------- /mpi/powerpc32/distfiles: -------------------------------------------------------------------------------- 1 | mpih-add1.S 2 | mpih-sub1.S 3 | mpih-mul1.S 4 | mpih-mul2.S 5 | mpih-mul3.S 6 | mpih-lshift.S 7 | mpih-rshift.S 8 | syntax.h 9 | 10 | -------------------------------------------------------------------------------- /mpi/powerpc32/syntax.h: -------------------------------------------------------------------------------- 1 | /* gmp2-2.0.2-ppc/mpn/powerpc-linux/syntax.h Tue Oct 6 19:27:01 1998 */ 2 | /* From glibc's sysdeps/unix/sysv/linux/powerpc/sysdep.h */ 3 | 4 | /* Copyright (C) 1992, 1997, 1998 Free Software Foundation, Inc. 5 | This file is part of the GNU C Library. 6 | 7 | The GNU C Library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Library General Public License as 9 | published by the Free Software Foundation; either version 2 of the 10 | License, or (at your option) any later version. 11 | 12 | The GNU C Library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Library General Public License for more details. 16 | 17 | You should have received a copy of the GNU Library General Public 18 | License along with the GNU C Library; see the file COPYING.LIB. If not, 19 | see . 20 | SPDX-License-Identifier: LGPL-2-or-later 21 | */ 22 | 23 | 24 | #define USE_PPC_PATCHES 1 25 | 26 | /* This seems to always be the case on PPC. */ 27 | #define ALIGNARG(log2) log2 28 | /* For ELF we need the `.type' directive to make shared libs work right. */ 29 | #define ASM_TYPE_DIRECTIVE(name,typearg) .type name,typearg; 30 | #define ASM_SIZE_DIRECTIVE(name) .size name,.-name 31 | #define ASM_GLOBAL_DIRECTIVE .globl 32 | 33 | #ifdef __STDC__ 34 | #define C_LABEL(name) C_SYMBOL_NAME(name)##: 35 | #else 36 | #define C_LABEL(name) C_SYMBOL_NAME(name)/**/: 37 | #endif 38 | 39 | #ifdef __STDC__ 40 | #define L(body) .L##body 41 | #else 42 | #define L(body) .L/**/body 43 | #endif 44 | 45 | /* No profiling of gmp's assembly for now... */ 46 | #define CALL_MCOUNT /* no profiling */ 47 | 48 | #define ENTRY(name) \ 49 | ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME(name); \ 50 | ASM_TYPE_DIRECTIVE (C_SYMBOL_NAME(name),@function) \ 51 | .align ALIGNARG(2); \ 52 | C_LABEL(name) \ 53 | CALL_MCOUNT 54 | 55 | #define EALIGN_W_0 /* No words to insert. */ 56 | #define EALIGN_W_1 nop 57 | #define EALIGN_W_2 nop;nop 58 | #define EALIGN_W_3 nop;nop;nop 59 | #define EALIGN_W_4 EALIGN_W_3;nop 60 | #define EALIGN_W_5 EALIGN_W_4;nop 61 | #define EALIGN_W_6 EALIGN_W_5;nop 62 | #define EALIGN_W_7 EALIGN_W_6;nop 63 | 64 | /* EALIGN is like ENTRY, but does alignment to 'words'*4 bytes 65 | past a 2^align boundary. */ 66 | #define EALIGN(name, alignt, words) \ 67 | ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME(name); \ 68 | ASM_TYPE_DIRECTIVE (C_SYMBOL_NAME(name),@function) \ 69 | .align ALIGNARG(alignt); \ 70 | EALIGN_W_##words; \ 71 | C_LABEL(name) 72 | 73 | #undef END 74 | #define END(name) \ 75 | ASM_SIZE_DIRECTIVE(name) 76 | 77 | -------------------------------------------------------------------------------- /mpi/powerpc64/distfiles: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/libgcrypt/4a997384e4bf0bb04e0fb6c61976c67c27bc8612/mpi/powerpc64/distfiles -------------------------------------------------------------------------------- /mpi/sparc32/distfiles: -------------------------------------------------------------------------------- 1 | mpih-lshift.S 2 | mpih-rshift.S 3 | mpih-add1.S 4 | udiv.S 5 | 6 | -------------------------------------------------------------------------------- /mpi/sparc32/mpih-lshift.S: -------------------------------------------------------------------------------- 1 | /* sparc lshift 2 | * 3 | * Copyright (C) 1995, 1996, 1998, 4 | * 2001, 2002 Free Software Foundation, Inc. 5 | * 6 | * This file is part of Libgcrypt. 7 | * 8 | * Libgcrypt is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as 10 | * published by the Free Software Foundation; either version 2.1 of 11 | * the License, or (at your option) any later version. 12 | * 13 | * Libgcrypt is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this program; if not, see . 20 | * SPDX-License-Identifier: LGPL-2.1-or-later 21 | */ 22 | 23 | 24 | ! INPUT PARAMETERS 25 | ! res_ptr %o0 26 | ! src_ptr %o1 27 | ! size %o2 28 | ! cnt %o3 29 | 30 | #include "sysdep.h" 31 | 32 | .text 33 | .align 4 34 | .global C_SYMBOL_NAME(_gcry_mpih_lshift) 35 | C_SYMBOL_NAME(_gcry_mpih_lshift): 36 | sll %o2,2,%g1 37 | add %o1,%g1,%o1 ! make %o1 point at end of src 38 | ld [%o1-4],%g2 ! load first limb 39 | sub %g0,%o3,%o5 ! negate shift count 40 | add %o0,%g1,%o0 ! make %o0 point at end of res 41 | add %o2,-1,%o2 42 | andcc %o2,4-1,%g4 ! number of limbs in first loop 43 | srl %g2,%o5,%g1 ! compute function result 44 | be L0 ! if multiple of 4 limbs, skip first loop 45 | st %g1,[%sp+80] 46 | 47 | sub %o2,%g4,%o2 ! adjust count for main loop 48 | 49 | Loop0: ld [%o1-8],%g3 50 | add %o0,-4,%o0 51 | add %o1,-4,%o1 52 | addcc %g4,-1,%g4 53 | sll %g2,%o3,%o4 54 | srl %g3,%o5,%g1 55 | mov %g3,%g2 56 | or %o4,%g1,%o4 57 | bne Loop0 58 | st %o4,[%o0+0] 59 | 60 | L0: tst %o2 61 | be Lend 62 | nop 63 | 64 | Loop: ld [%o1-8],%g3 65 | add %o0,-16,%o0 66 | addcc %o2,-4,%o2 67 | sll %g2,%o3,%o4 68 | srl %g3,%o5,%g1 69 | 70 | ld [%o1-12],%g2 71 | sll %g3,%o3,%g4 72 | or %o4,%g1,%o4 73 | st %o4,[%o0+12] 74 | srl %g2,%o5,%g1 75 | 76 | ld [%o1-16],%g3 77 | sll %g2,%o3,%o4 78 | or %g4,%g1,%g4 79 | st %g4,[%o0+8] 80 | srl %g3,%o5,%g1 81 | 82 | ld [%o1-20],%g2 83 | sll %g3,%o3,%g4 84 | or %o4,%g1,%o4 85 | st %o4,[%o0+4] 86 | srl %g2,%o5,%g1 87 | 88 | add %o1,-16,%o1 89 | or %g4,%g1,%g4 90 | bne Loop 91 | st %g4,[%o0+0] 92 | 93 | Lend: sll %g2,%o3,%g2 94 | st %g2,[%o0-4] 95 | retl 96 | ld [%sp+80],%o0 97 | 98 | -------------------------------------------------------------------------------- /mpi/sparc32/mpih-rshift.S: -------------------------------------------------------------------------------- 1 | /* sparc rshift 2 | * 3 | * Copyright (C) 1995, 1996, 1998, 4 | * 2001, 2002 Free Software Foundation, Inc. 5 | * 6 | * This file is part of Libgcrypt. 7 | * 8 | * Libgcrypt is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as 10 | * published by the Free Software Foundation; either version 2.1 of 11 | * the License, or (at your option) any later version. 12 | * 13 | * Libgcrypt is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this program; if not, see . 20 | * SPDX-License-Identifier: LGPL-2.1-or-later 21 | */ 22 | 23 | ! INPUT PARAMETERS 24 | ! res_ptr %o0 25 | ! src_ptr %o1 26 | ! size %o2 27 | ! cnt %o3 28 | 29 | #include "sysdep.h" 30 | 31 | .text 32 | .align 4 33 | .global C_SYMBOL_NAME(_gcry_mpih_rshift) 34 | C_SYMBOL_NAME(_gcry_mpih_rshift): 35 | ld [%o1],%g2 ! load first limb 36 | sub %g0,%o3,%o5 ! negate shift count 37 | add %o2,-1,%o2 38 | andcc %o2,4-1,%g4 ! number of limbs in first loop 39 | sll %g2,%o5,%g1 ! compute function result 40 | be L0 ! if multiple of 4 limbs, skip first loop 41 | st %g1,[%sp+80] 42 | 43 | sub %o2,%g4,%o2 ! adjust count for main loop 44 | 45 | Loop0: ld [%o1+4],%g3 46 | add %o0,4,%o0 47 | add %o1,4,%o1 48 | addcc %g4,-1,%g4 49 | srl %g2,%o3,%o4 50 | sll %g3,%o5,%g1 51 | mov %g3,%g2 52 | or %o4,%g1,%o4 53 | bne Loop0 54 | st %o4,[%o0-4] 55 | 56 | L0: tst %o2 57 | be Lend 58 | nop 59 | 60 | Loop: ld [%o1+4],%g3 61 | add %o0,16,%o0 62 | addcc %o2,-4,%o2 63 | srl %g2,%o3,%o4 64 | sll %g3,%o5,%g1 65 | 66 | ld [%o1+8],%g2 67 | srl %g3,%o3,%g4 68 | or %o4,%g1,%o4 69 | st %o4,[%o0-16] 70 | sll %g2,%o5,%g1 71 | 72 | ld [%o1+12],%g3 73 | srl %g2,%o3,%o4 74 | or %g4,%g1,%g4 75 | st %g4,[%o0-12] 76 | sll %g3,%o5,%g1 77 | 78 | ld [%o1+16],%g2 79 | srl %g3,%o3,%g4 80 | or %o4,%g1,%o4 81 | st %o4,[%o0-8] 82 | sll %g2,%o5,%g1 83 | 84 | add %o1,16,%o1 85 | or %g4,%g1,%g4 86 | bne Loop 87 | st %g4,[%o0-4] 88 | 89 | Lend: srl %g2,%o3,%g2 90 | st %g2,[%o0-0] 91 | retl 92 | ld [%sp+80],%o0 93 | 94 | -------------------------------------------------------------------------------- /mpi/sparc32v8/distfiles: -------------------------------------------------------------------------------- 1 | mpih-mul1.S 2 | mpih-mul2.S 3 | mpih-mul3.S 4 | 5 | -------------------------------------------------------------------------------- /mpi/sparc32v8/mpih-mul3.S: -------------------------------------------------------------------------------- 1 | /* SPARC v8 __mpn_submul_1 -- Multiply a limb vector with a limb and 2 | * subtract the result from a second limb vector. 3 | * 4 | * Copyright (C) 1992, 1993, 1994, 1998, 5 | * 2001, 2002 Free Software Foundation, Inc. 6 | * 7 | * This file is part of Libgcrypt. 8 | * 9 | * Libgcrypt is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as 11 | * published by the Free Software Foundation; either version 2.1 of 12 | * the License, or (at your option) any later version. 13 | * 14 | * Libgcrypt is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with this program; if not, see . 21 | * SPDX-License-Identifier: LGPL-2.1-or-later 22 | * 23 | * Note: This code is heavily based on the GNU MP Library. 24 | * Actually it's the same code with only minor changes in the 25 | * way the data is stored; this is to support the abstraction 26 | * of an optional secure memory allocation which may be used 27 | * to avoid revealing of sensitive data due to paging etc. 28 | */ 29 | 30 | 31 | ! INPUT PARAMETERS 32 | ! res_ptr o0 33 | ! s1_ptr o1 34 | ! size o2 35 | ! s2_limb o3 36 | 37 | #include "sysdep.h" 38 | 39 | .text 40 | .align 4 41 | .global C_SYMBOL_NAME(_gcry_mpih_submul_1) 42 | C_SYMBOL_NAME(_gcry_mpih_submul_1): 43 | sub %g0,%o2,%o2 ! negate ... 44 | sll %o2,2,%o2 ! ... and scale size 45 | sub %o1,%o2,%o1 ! o1 is offset s1_ptr 46 | sub %o0,%o2,%g1 ! g1 is offset res_ptr 47 | 48 | mov 0,%o0 ! clear cy_limb 49 | 50 | Loop: ld [%o1+%o2],%o4 51 | ld [%g1+%o2],%g2 52 | umul %o4,%o3,%o5 53 | rd %y,%g3 54 | addcc %o5,%o0,%o5 55 | addx %g3,0,%o0 56 | subcc %g2,%o5,%g2 57 | addx %o0,0,%o0 58 | st %g2,[%g1+%o2] 59 | 60 | addcc %o2,4,%o2 61 | bne Loop 62 | nop 63 | 64 | retl 65 | nop 66 | 67 | 68 | -------------------------------------------------------------------------------- /mpi/supersparc/distfiles: -------------------------------------------------------------------------------- 1 | udiv.S 2 | 3 | -------------------------------------------------------------------------------- /random/jitterentropy-base.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021, Stephan Mueller 3 | * 4 | * License: see LICENSE file in root directory 5 | * 6 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 7 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 8 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF 9 | * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 10 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 11 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 12 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 13 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 14 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 15 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 16 | * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH 17 | * DAMAGE. 18 | */ 19 | 20 | #ifndef JITTERENTROPY_BASE_H 21 | #define JITTERENTROPY_BASE_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" 25 | { 26 | #endif 27 | 28 | int jent_time_entropy_init(unsigned int osr, unsigned int flags); 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif /* JITTERENTROPY_BASE_H */ 35 | -------------------------------------------------------------------------------- /random/jitterentropy-gcd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021, Stephan Mueller 3 | * 4 | * License: see LICENSE file in root directory 5 | * 6 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 7 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 8 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF 9 | * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 10 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 11 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 12 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 13 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 14 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 15 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 16 | * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH 17 | * DAMAGE. 18 | */ 19 | 20 | #ifndef JITTERENTROPY_GCD_H 21 | #define JITTERENTROPY_GCD_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" 25 | { 26 | #endif 27 | 28 | int jent_gcd_analyze(uint64_t *delta_history, size_t nelem); 29 | uint64_t *jent_gcd_init(size_t nelem); 30 | void jent_gcd_fini(uint64_t *delta_history, size_t nelem); 31 | int jent_gcd_get(uint64_t *value); 32 | int jent_gcd_selftest(void); 33 | 34 | /* Watch for common adjacent GCD values */ 35 | #define jent_gcd_add_value(delta_history, delta, idx) \ 36 | delta_history[idx] = delta; 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | 42 | #endif /* JITTERENTROPY_GCD_H */ 43 | -------------------------------------------------------------------------------- /random/jitterentropy-health.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021, Stephan Mueller 3 | * 4 | * License: see LICENSE file in root directory 5 | * 6 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 7 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 8 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF 9 | * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 10 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 11 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 12 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 13 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 14 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 15 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 16 | * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH 17 | * DAMAGE. 18 | */ 19 | 20 | #ifndef JITTERENTROPY_HEALTH_H 21 | #define JITTERENTROPY_HEALTH_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" 25 | { 26 | #endif 27 | 28 | static inline uint64_t jent_delta(uint64_t prev, uint64_t next) 29 | { 30 | return (next - prev); 31 | } 32 | 33 | #ifdef JENT_HEALTH_LAG_PREDICTOR 34 | void jent_lag_init(struct rand_data *ec, unsigned int osr); 35 | #else /* JENT_HEALTH_LAG_PREDICTOR */ 36 | static inline void jent_lag_init(struct rand_data *ec, unsigned int osr) 37 | { 38 | (void)ec; 39 | (void)osr; 40 | } 41 | #endif /* JENT_HEALTH_LAG_PREDICTOR */ 42 | 43 | void jent_apt_init(struct rand_data *ec, unsigned int osr); 44 | unsigned int jent_stuck(struct rand_data *ec, uint64_t current_delta); 45 | unsigned int jent_health_failure(struct rand_data *ec); 46 | 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | 51 | #endif /* JITTERENTROPY_HEALTH_H */ 52 | -------------------------------------------------------------------------------- /random/jitterentropy-noise.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021, Stephan Mueller 3 | * 4 | * License: see LICENSE file in root directory 5 | * 6 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 7 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 8 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF 9 | * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 10 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 11 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 12 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 13 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 14 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 15 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 16 | * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH 17 | * DAMAGE. 18 | */ 19 | 20 | #ifndef JITTERENTROPY_NOISE_H 21 | #define JITTERENTROPY_NOISE_H 22 | 23 | #include "jitterentropy.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" 27 | { 28 | #endif 29 | 30 | unsigned int jent_measure_jitter(struct rand_data *ec, 31 | uint64_t loop_cnt, 32 | uint64_t *ret_current_delta); 33 | void jent_random_data(struct rand_data *ec); 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | 39 | #endif /* JITTERENTROPY_NOISE_H */ 40 | -------------------------------------------------------------------------------- /random/jitterentropy-sha3.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021, Stephan Mueller 3 | * 4 | * License: see LICENSE file in root directory 5 | * 6 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 7 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 8 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF 9 | * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 10 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 11 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 12 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 13 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 14 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 15 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 16 | * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH 17 | * DAMAGE. 18 | */ 19 | 20 | #ifndef JITTERENTROPY_SHA3_H 21 | #define JITTERENTROPY_SHA3_H 22 | 23 | #include "jitterentropy.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" 27 | { 28 | #endif 29 | 30 | #define SHA3_SIZE_BLOCK(bits) ((1600 - 2 * bits) >> 3) 31 | #define SHA3_256_SIZE_BLOCK SHA3_SIZE_BLOCK(SHA3_256_SIZE_DIGEST_BITS) 32 | #define SHA3_MAX_SIZE_BLOCK SHA3_256_SIZE_BLOCK 33 | 34 | struct sha_ctx { 35 | uint64_t state[25]; 36 | size_t msg_len; 37 | unsigned int r; 38 | unsigned int rword; 39 | unsigned int digestsize; 40 | uint8_t partial[SHA3_MAX_SIZE_BLOCK]; 41 | }; 42 | 43 | #define SHA_MAX_CTX_SIZE (sizeof(struct sha_ctx)) 44 | #define HASH_CTX_ON_STACK(name) \ 45 | struct sha_ctx name 46 | 47 | void sha3_256_init(struct sha_ctx *ctx); 48 | void sha3_update(struct sha_ctx *ctx, const uint8_t *in, size_t inlen); 49 | void sha3_final(struct sha_ctx *ctx, uint8_t *digest); 50 | int sha3_tester(void); 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | 56 | #endif /* JITTERENTROPY_SHA3_H */ 57 | -------------------------------------------------------------------------------- /random/jitterentropy-timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021, Stephan Mueller 3 | * 4 | * License: see LICENSE file in root directory 5 | * 6 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 7 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 8 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF 9 | * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 10 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 11 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 12 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 13 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 14 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 15 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 16 | * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH 17 | * DAMAGE. 18 | */ 19 | 20 | #ifndef JITTERENTROPY_TIMER_H 21 | #define JITTERENTROPY_TIMER_H 22 | 23 | #include "jitterentropy.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" 27 | { 28 | #endif 29 | 30 | #ifdef JENT_CONF_ENABLE_INTERNAL_TIMER 31 | 32 | void jent_notime_block_switch(void); 33 | int jent_notime_settick(struct rand_data *ec); 34 | void jent_notime_unsettick(struct rand_data *ec); 35 | void jent_get_nstime_internal(struct rand_data *ec, uint64_t *out); 36 | int jent_notime_enable(struct rand_data *ec, unsigned int flags); 37 | void jent_notime_disable(struct rand_data *ec); 38 | int jent_notime_switch(struct jent_notime_thread *new_thread); 39 | void jent_notime_force(void); 40 | int jent_notime_forced(void); 41 | 42 | #else /* JENT_CONF_ENABLE_INTERNAL_TIMER */ 43 | 44 | static inline void jent_notime_block_switch(void) { } 45 | 46 | static inline int jent_notime_settick(struct rand_data *ec) 47 | { 48 | (void)ec; 49 | return 0; 50 | } 51 | 52 | static inline void jent_notime_unsettick(struct rand_data *ec) { (void)ec; } 53 | 54 | static inline void jent_get_nstime_internal(struct rand_data *ec, uint64_t *out) 55 | { 56 | (void)ec; 57 | jent_get_nstime(out); 58 | } 59 | 60 | static inline int jent_notime_enable(struct rand_data *ec, unsigned int flags) 61 | { 62 | (void)ec; 63 | 64 | /* If we force the timer-less noise source, we return an error */ 65 | if (flags & JENT_FORCE_INTERNAL_TIMER) 66 | return EHEALTH; 67 | 68 | return 0; 69 | } 70 | 71 | static inline void jent_notime_disable(struct rand_data *ec) 72 | { 73 | (void)ec; 74 | } 75 | 76 | static inline int jent_notime_switch(struct jent_notime_thread *new_thread) 77 | { 78 | (void)new_thread; 79 | return -EOPNOTSUPP; 80 | } 81 | 82 | static inline void jent_notime_force(void) { } 83 | 84 | static inline int jent_notime_forced(void) { return 0; } 85 | 86 | #endif /* JENT_CONF_ENABLE_INTERNAL_TIMER */ 87 | 88 | #ifdef __cplusplus 89 | } 90 | #endif 91 | 92 | #endif /* JITTERENTROPY-TIMER_H */ 93 | -------------------------------------------------------------------------------- /random/rndw32uwp.cpp: -------------------------------------------------------------------------------- 1 | /* rndw32uwp - W32 entropy gatherer (UWP) 2 | * 3 | * This file is part of Libgcrypt. 4 | * 5 | * Libgcrypt is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as 7 | * published by the Free Software Foundation; either version 2.1 of 8 | * the License, or (at your option) any later version. 9 | * 10 | * Libgcrypt is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this program; if not, see . 17 | */ 18 | 19 | #include "config.h" 20 | #include "types.h" 21 | #include "g10lib.h" 22 | #include "windows.h" 23 | 24 | using namespace Platform; 25 | using namespace Windows::Security::Cryptography; 26 | using namespace Windows::Security::Cryptography::Certificates; 27 | using namespace Windows::Storage::Streams; 28 | 29 | extern "C" { 30 | int 31 | _gcry_rnduwp_gather_random(void(*add)(const void*, size_t, 32 | enum random_origins), 33 | enum random_origins origin, 34 | size_t length, int level) 35 | { 36 | if (!level) 37 | return 0; 38 | 39 | IBuffer^ data = CryptographicBuffer::GenerateRandom(length); 40 | Array^ data2; 41 | CryptographicBuffer::CopyToByteArray(data, &data2); 42 | (*add)(data2->Data, length, origin); 43 | 44 | return 0; 45 | } 46 | 47 | void 48 | _gcry_rnduwp_gather_random_fast(void(*add)(const void*, size_t, 49 | enum random_origins), 50 | enum random_origins origin) 51 | { 52 | size_t size = 20 * sizeof(intptr_t) + 2 * sizeof(POINT) + sizeof(MEMORYSTATUS) 53 | + 8 * sizeof(FILETIME) + sizeof(LARGE_INTEGER); 54 | 55 | _gcry_rnduwp_gather_random(add, origin, size, 1); 56 | } 57 | } -------------------------------------------------------------------------------- /src/context.h: -------------------------------------------------------------------------------- 1 | /* context.h - Declarations for the context management 2 | * Copyright (C) 2013 g10 Code GmbH 3 | * 4 | * This file is part of Libgcrypt. 5 | * 6 | * Libgcrypt is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Libgcrypt is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | */ 19 | 20 | #ifndef GCRY_CONTEXT_H 21 | #define GCRY_CONTEXT_H 22 | 23 | /* Context types as used in struct gcry_context. */ 24 | #define CONTEXT_TYPE_EC 1 /* The context is used with EC functions. */ 25 | #define CONTEXT_TYPE_SINGLE_DATA 2 /* Used with pubkey functions. */ 26 | 27 | gcry_ctx_t _gcry_ctx_alloc (int type, size_t length, void (*deinit)(void*), 28 | gcry_ctx_t next); 29 | void *_gcry_ctx_get_pointer (gcry_ctx_t ctx, int type); 30 | void *_gcry_ctx_find_pointer (gcry_ctx_t ctx, int type); 31 | 32 | 33 | #endif /*GCRY_CONTEXT_H*/ 34 | -------------------------------------------------------------------------------- /src/gcrypt-testapi.h: -------------------------------------------------------------------------------- 1 | /* gcrypt-testapi.h - Definitiona for the Regression test API 2 | * Copyright (C) 2016 g10 Code GmbH 3 | * 4 | * This file is part of Libgcrypt. 5 | * 6 | * Libgcrypt is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Libgcrypt is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | */ 19 | 20 | /* 21 | * WARNING: This is a private API to be used by regression tests. In 22 | * particular this API does not constitute a well defined ABI. The 23 | * header may only be used with its matching Libgcrypt version. 24 | */ 25 | 26 | #ifndef GCRY_GCRYPT_TESTAPI_H 27 | #define GCRY_GCRYPT_TESTAPI_H 28 | 29 | /* For use with gcry_control: */ 30 | #define PRIV_CTL_INIT_EXTRNG_TEST 58 31 | #define PRIV_CTL_RUN_EXTRNG_TEST 59 32 | #define PRIV_CTL_DEINIT_EXTRNG_TEST 60 33 | #define PRIV_CTL_EXTERNAL_LOCK_TEST 61 34 | #define PRIV_CTL_DUMP_SECMEM_STATS 62 35 | 36 | #define EXTERNAL_LOCK_TEST_INIT 30111 37 | #define EXTERNAL_LOCK_TEST_LOCK 30112 38 | #define EXTERNAL_LOCK_TEST_UNLOCK 30113 39 | #define EXTERNAL_LOCK_TEST_DESTROY 30114 40 | 41 | /* For use with gcry_cipher_ctl: */ 42 | #define PRIV_CIPHERCTL_DISABLE_WEAK_KEY 61 43 | #define PRIV_CIPHERCTL_GET_INPUT_VECTOR 62 44 | #define PRIV_CIPHERCTL_GET_COUNTER 63 45 | 46 | 47 | /* Private interfaces for testing of random-drbg.c. */ 48 | struct gcry_drbg_test_vector 49 | { 50 | const char *flagstr; 51 | unsigned char *entropy; 52 | size_t entropylen; 53 | unsigned char *entpra; 54 | unsigned char *entprb; 55 | size_t entprlen; 56 | unsigned char *addtla; 57 | unsigned char *addtlb; 58 | size_t addtllen; 59 | unsigned char *pers; 60 | size_t perslen; 61 | unsigned char *expected; 62 | size_t expectedlen; 63 | unsigned char *entropyreseed; 64 | size_t entropyreseed_len; 65 | unsigned char *addtl_reseed; 66 | size_t addtl_reseed_len; 67 | }; 68 | 69 | 70 | #endif /*GCRY_GCRYPT_TESTAPI_H*/ 71 | -------------------------------------------------------------------------------- /src/hmac256.h: -------------------------------------------------------------------------------- 1 | /* hmac256.h - Declarations for _gcry_hmac256 2 | * Copyright (C) 2008 Free Software Foundation, Inc. 3 | * 4 | * This file is part of Libgcrypt. 5 | * 6 | * Libgcrypt is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Libgcrypt is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | */ 19 | 20 | #ifndef HMAC256_H 21 | #define HMAC256_H 22 | 23 | 24 | struct hmac256_context; 25 | typedef struct hmac256_context *hmac256_context_t; 26 | 27 | hmac256_context_t _gcry_hmac256_new (const void *key, size_t keylen); 28 | void _gcry_hmac256_update (hmac256_context_t hd, const void *buf, size_t len); 29 | const void *_gcry_hmac256_finalize (hmac256_context_t hd, size_t *r_dlen); 30 | void _gcry_hmac256_release (hmac256_context_t hd); 31 | 32 | int _gcry_hmac256_file (void *result, size_t resultsize, const char *filename, 33 | const void *key, size_t keylen); 34 | 35 | 36 | #endif /*HMAC256_H*/ 37 | -------------------------------------------------------------------------------- /src/hwf-common.h: -------------------------------------------------------------------------------- 1 | /* hwf-common.h - Declarations for hwf-CPU.c modules 2 | * Copyright (C) 2012 g10 Code GmbH 3 | * 4 | * This file is part of Libgcrypt. 5 | * 6 | * Libgcrypt is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Libgcrypt is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | */ 19 | 20 | #ifndef HWF_COMMON_H 21 | #define HWF_COMMON_H 22 | 23 | unsigned int _gcry_hwf_detect_x86 (void); 24 | unsigned int _gcry_hwf_detect_arm (void); 25 | unsigned int _gcry_hwf_detect_ppc (void); 26 | unsigned int _gcry_hwf_detect_s390x (void); 27 | 28 | #endif /*HWF_COMMON_H*/ 29 | -------------------------------------------------------------------------------- /src/libgcrypt.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | includedir=@includedir@ 4 | libdir=@libdir@ 5 | host=@LIBGCRYPT_CONFIG_HOST@ 6 | api_version=@LIBGCRYPT_CONFIG_API_VERSION@ 7 | symmetric_ciphers="@LIBGCRYPT_CIPHERS@" 8 | asymmetric_ciphers="@LIBGCRYPT_PUBKEY_CIPHERS@" 9 | digests="@LIBGCRYPT_DIGESTS@" 10 | 11 | Name: libgcrypt 12 | Description: General purpose cryptographic library 13 | Requires.private: gpg-error 14 | Version: @PACKAGE_VERSION@ 15 | Cflags: -I${includedir} @LIBGCRYPT_CONFIG_CFLAGS@ 16 | Libs: -L${libdir} @LIBGCRYPT_CONFIG_LIBS@ 17 | Libs.private: @DL_LIBS@ 18 | URL: https://www.gnupg.org/software/libgcrypt/index.html 19 | -------------------------------------------------------------------------------- /src/missing-string.c: -------------------------------------------------------------------------------- 1 | /* missing-string.c - missing string utilities 2 | * Copyright (C) 1994, 1998, 1999, 2000, 2001, 3 | * 2003 Free Software Foundation, Inc. 4 | * 5 | * This file is part of Libgcrypt. 6 | * 7 | * Libgcrypt is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation; either version 2.1 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * Libgcrypt is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this program; if not, see . 19 | * SPDX-License-Identifier: LGPL-2.1-or-later 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include "g10lib.h" 29 | 30 | 31 | #ifndef HAVE_STPCPY 32 | char * 33 | stpcpy(char *a,const char *b) 34 | { 35 | while( *b ) 36 | *a++ = *b++; 37 | *a = 0; 38 | 39 | return (char*)a; 40 | } 41 | #endif 42 | 43 | 44 | #ifndef HAVE_STRCASECMP 45 | int 46 | strcasecmp( const char *a, const char *b ) 47 | { 48 | for( ; *a && *b; a++, b++ ) { 49 | if( *a != *b && toupper(*a) != toupper(*b) ) 50 | break; 51 | } 52 | return *(const byte*)a - *(const byte*)b; 53 | } 54 | #endif 55 | -------------------------------------------------------------------------------- /src/secmem.h: -------------------------------------------------------------------------------- 1 | /* secmem.h - internal definitions for secmem 2 | * Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation, Inc. 3 | * 4 | * This file is part of Libgcrypt. 5 | * 6 | * Libgcrypt is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Libgcrypt is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #ifndef G10_SECMEM_H 22 | #define G10_SECMEM_H 1 23 | 24 | void _gcry_secmem_init (size_t npool); 25 | void _gcry_secmem_term (void); 26 | void *_gcry_secmem_malloc (size_t size, int xhint) _GCRY_GCC_ATTR_MALLOC; 27 | void *_gcry_secmem_realloc (void *a, size_t newsize, int xhint); 28 | int _gcry_secmem_free (void *a); 29 | void _gcry_secmem_dump_stats (int extended); 30 | void _gcry_secmem_set_auto_expand (unsigned int chunksize); 31 | void _gcry_secmem_set_flags (unsigned flags); 32 | unsigned _gcry_secmem_get_flags(void); 33 | int _gcry_private_is_secure (const void *p); 34 | 35 | /* Flags for _gcry_secmem_{set,get}_flags. */ 36 | #define GCRY_SECMEM_FLAG_NO_WARNING (1 << 0) 37 | #define GCRY_SECMEM_FLAG_SUSPEND_WARNING (1 << 1) 38 | #define GCRY_SECMEM_FLAG_NOT_LOCKED (1 << 2) 39 | #define GCRY_SECMEM_FLAG_NO_MLOCK (1 << 3) 40 | #define GCRY_SECMEM_FLAG_NO_PRIV_DROP (1 << 4) 41 | 42 | #endif /* G10_SECMEM_H */ 43 | -------------------------------------------------------------------------------- /src/stdmem.h: -------------------------------------------------------------------------------- 1 | /* stdmem.h - internal definitions for stdmem 2 | * Copyright (C) 2000, 2002, 2005 Free Software Foundation, Inc. 3 | * 4 | * This file is part of Libgcrypt. 5 | * 6 | * Libgcrypt is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Libgcrypt is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #ifndef G10_STDMEM_H 22 | #define G10_STDMEM_H 1 23 | 24 | void *_gcry_private_malloc (size_t n) _GCRY_GCC_ATTR_MALLOC; 25 | void *_gcry_private_malloc_secure (size_t n, int xhint) _GCRY_GCC_ATTR_MALLOC; 26 | void *_gcry_private_realloc (void *a, size_t n, int xhint); 27 | void _gcry_private_free (void *a); 28 | 29 | #endif /* G10_STDMEM_H */ 30 | -------------------------------------------------------------------------------- /src/versioninfo.rc.in: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiftMediaProject/libgcrypt/4a997384e4bf0bb04e0fb6c61976c67c27bc8612/src/versioninfo.rc.in -------------------------------------------------------------------------------- /stamp-h.in: -------------------------------------------------------------------------------- 1 | timestamp 2 | -------------------------------------------------------------------------------- /tests/README: -------------------------------------------------------------------------------- 1 | Some notes about the tests. 2 | 3 | rsa-16k.key - A 16384 bit RSA key (public and privat), created 2008-08-28. 4 | It took 91 minutes to create it on a 1500Mhz Pentium M. 5 | pkpench showed these results: 6 | encrypt: 80 ms 7 | decrypt: 14370 ms 8 | sign: 14110 ms 9 | verify: 30 ms 10 | -------------------------------------------------------------------------------- /tests/basic-disable-all-hwf.in: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo " now running 'basic' test with all hardware features disabled." 4 | exec ./basic@EXEEXT@ --disable-hwf all 5 | -------------------------------------------------------------------------------- /tests/hashtest-256g.in: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | algos="SHA1 SHA256 SHA512 SHA3-512 SM3" 4 | 5 | test "@RUN_LARGE_DATA_TESTS@" = yes || exit 77 6 | echo " now running 256 GiB tests for $algos - this takes looong" 7 | exec ./hashtest@EXEEXT@ --gigs 256 $algos 8 | -------------------------------------------------------------------------------- /tests/hashtest-6g.in: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | algos="SHA1 SHA256 SHA512 SHA3-512 SM3 BLAKE2S_256 BLAKE2B_512 CRC32 CRC24RFC2440" 4 | 5 | test "@RUN_LARGE_DATA_TESTS@" = yes || exit 77 6 | echo " now running 6 GiB tests for $algos - this can take long" 7 | exec ./hashtest@EXEEXT@ --hugeblock --gigs 6 $algos 8 | -------------------------------------------------------------------------------- /tests/pkcstv2c.awk: -------------------------------------------------------------------------------- 1 | #! /usr/bin/awk -f 2 | # pkcstv2c.awk - Convert pkcs1 test vectors into a C table. 3 | # Copyright 2011 Free Software Foundation, Inc. 4 | # 5 | # This file is free software; as a special exception the author gives 6 | # unlimited permission to copy and/or distribute it, with or without 7 | # modifications, as long as this notice is preserved. 8 | # 9 | # This file is distributed in the hope that it will be useful, but 10 | # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the 11 | # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | # 13 | 14 | BEGIN { 15 | in_key = 0; 16 | in_item = 0; 17 | in_number = 0; 18 | no_comma = 0; 19 | 20 | printf " static struct {\n"; 21 | printf " const char *desc;\n"; 22 | printf " const char *n, *e, *d;\n"; 23 | printf " struct {\n"; 24 | printf " const char *desc;\n"; 25 | printf " const char *mesg;\n"; 26 | printf " const char *seed;\n"; 27 | printf " const char *encr;\n"; 28 | printf " } m[20];\n"; 29 | printf " } tbl[] =\n"; 30 | printf " {\n"; 31 | } 32 | 33 | { sub (/\r/,""); } 34 | 35 | /^# Public key/ { skip_pub = 1; } 36 | /^# Private key/ { skip_pub = 0; } 37 | skip_pub { next } 38 | 39 | in_number && ! /^[0-9a-f]/ { 40 | if (in_number == 2) 41 | printf "\""; 42 | if (no_comma) 43 | no_comma = 0; 44 | else 45 | printf "," 46 | printf "\n"; 47 | in_number = 0; 48 | } 49 | 50 | in_number == 3 { 51 | printf "\n"; 52 | in_number = 1; 53 | } 54 | 55 | in_number == 1 { 56 | gsub (/ /,"") 57 | printf "%*s\"%s", indent, "", $0; 58 | in_number = 2; 59 | next; 60 | } 61 | 62 | in_number == 2 { 63 | gsub (/ /,"") 64 | printf "%s\"", $0; 65 | in_number = 3; 66 | next; 67 | } 68 | 69 | /^#.*Example.*key pair/ { 70 | if (in_item) { 71 | printf " }\n }\n },\n"; 72 | in_item = 0; 73 | } 74 | in_key = 1; 75 | indent = 6; 76 | printf " {\n \"%s\",\n", gensub(/.*: (A .*)/, "\\1", "g"); 77 | next 78 | } 79 | 80 | /^# PKCS#1 .*Example/ { 81 | if (in_key) { 82 | printf " {\n"; 83 | in_key = 0; 84 | } 85 | if (in_item) 86 | printf " },{\n"; 87 | else 88 | printf " {\n"; 89 | in_item = 1; 90 | indent = 10; 91 | printf " \"%s\",\n", gensub(/^# (.*)/, "\\1", "g"); 92 | next 93 | } 94 | 95 | (in_key || in_item) && /^# (Modulus|Public|Exponent|Message|Seed)/ { 96 | # printf "/* %s */\n", $0; 97 | in_number = 1; 98 | next 99 | } 100 | (in_key || in_item) && /^# (Signature|Encryption)/ { 101 | # printf "/* %s */\n", $0; 102 | in_number = 1; 103 | no_comma = 1; 104 | next 105 | } 106 | 107 | END { 108 | if (in_item) { 109 | printf " }\n }\n }\n };\n"; 110 | in_item = 0; 111 | } 112 | } --------------------------------------------------------------------------------