Changelog
Source:NEWS.md
zucrypt 0.1.1
Additions only, for zujwt: randomness, AES-GCM, PBKDF2, RSA and key I/O, EC keys, ECDSA, ECDH and X25519, in an openssl-shaped layer. Each C function is appended to the archive and the registered table: ABI 1 is unchanged, so a package linking libzucrypt.a, such as zuxlsx, needs no change. The bundled TF-PSA-Crypto is updated to 1.1.2, a security release.
R interface
crypt_rand_bytes(n = 1)returnsnbytes from the operating system’s cryptographic random source, mirroringopenssl::rand_bytes()(#9). R’s random number generator is never used or disturbed, soset.seed()has no effect on it. A failure of the source raises the newzucrypt_entropy_errorclass and never returns bytes.crypt_aes_gcm_encrypt()andcrypt_aes_gcm_decrypt()provide AES-GCM authenticated encryption (#10), with a 12-byte nonce, a 16-byte tag and optional associated data. The nonce is random unless supplied, and the nonce and tag travel as attributes of the ciphertext. Decryption checks the tag first: any alteration, a truncated tag or a wrong key raises the newzucrypt_auth_errorclass and returns no plaintext. The names and argument order followopenssl, and the ciphertext bytes match, butopensslreturns no tag and does not authenticate, so this is a documented difference rather than a mirror.crypt_pbkdf2()derives a key from a raw password with PBKDF2-HMAC over SHA-1, SHA-256, SHA-384 or SHA-512 (#12).RSA, in the openssl-style layer (#80):
crypt_read_key(),crypt_read_pubkey(),crypt_write_pem(),crypt_write_der(),crypt_write_pkcs1(),crypt_rsa_keygen(),crypt_signature_create(),crypt_signature_verify(),crypt_rsa_encrypt()andcrypt_rsa_decrypt()keepopenssl’s names and arguments. Keys are read and written as PKCS#1, PKCS#8 and SubjectPublicKeyInfo, PEM or DER, byte for byte asopensslwrites them. Additions:pss = TRUEfor RSASSA-PSS,oaep_hashfor OAEP over SHA-256 and longer digests, andcrypt_rsa_key()andas.list()to build a key from its integers and take it apart. Moduli of 1024 to 4096 bits. A signature that does not verify, or a ciphertext that does not decrypt, iszucrypt_auth_error.-
Elliptic curves (#81):
crypt_ec_keygen(),crypt_ec_dh(),crypt_x25519_keygen(),crypt_x25519_diffie_hellman(),crypt_read_x25519_key(),crypt_read_x25519_pubkey(),crypt_ecdsa_parse()andcrypt_ecdsa_write()keepopenssl’s names and arguments, andcrypt_signature_create()and_verify()sign with ECDSA on P-256, P-384 and P-521, in DER, withdeterministic = TRUEfor RFC-
crypt_ec_key()andas.list()build an EC key from its coordinates and take it apart. EC and X25519 keys are read and written in every encodingopenssluses, byte for byte, an X25519 private key with the bytes it was read from. Points off the curve, peers on another curve and all-zero X25519 secrets are refused. There is no Ed25519.
-
crypt_sha1(),crypt_sha256(),crypt_sha384()andcrypt_sha512()mirroropenssl’s digest and HMAC functions on raw input, so thathash = crypt_sha256works asopenssl’shash = sha256does.
C interface
-
zuc_random_bytes()is added to the archive, andrandom_bytesis appended to the registered table; test for it withZUCRYPT_API_HAS(api, random_bytes). Both are additions, as ABI 1 allows. -
ZUC_ERR_ENTROPY = 10is appended tozuc_status. -
zuc_aead_encrypt(),zuc_aead_decrypt()andzuc_pbkdf2_hmac()are added to the archive, andaead_encrypt,aead_decryptandpbkdf2_hmacare appended to the table.ZUC_ALG_AES_GCM = 96is the first identifier in the cipher range, andZUC_ERR_AUTH = 11is appended tozuc_status. The digest and HMAC functions refuseZUC_ALG_AES_GCM. - RSA: an opaque
zuc_pkeyhandle withzuc_pkey_parse(),zuc_pkey_generate(),zuc_pkey_public(),zuc_pkey_free(),zuc_pkey_type(),zuc_pkey_bits(),zuc_pkey_is_private(),zuc_pkey_write(),zuc_pkey_sign_hash(),zuc_pkey_verify_hash(),zuc_pkey_encrypt()andzuc_pkey_decrypt(), appended to the archive and the table. Newzuc_algvalues:ZUC_ALG_RSA_OAEP = 97,ZUC_ALG_RSA_PKCS1V15_CRYPT = 98,ZUC_ALG_RSA = 192,ZUC_ALG_RSA_PKCS1V15_SIGN = 224andZUC_ALG_RSA_PSS = 225. - Elliptic curves:
zuc_pkey_import(),zuc_pkey_export()(the backend’s raw key forms) andzuc_pkey_agree()(ECDH and X25519), appended to the archive and the table; thezuc_pkey_*functions take EC keys too. Newzuc_algvalues:ZUC_ALG_EC_P256to_P521(193-195),ZUC_ALG_X25519 = 196,ZUC_ALG_ECDH = 197,ZUC_ALG_ECDSA = 226andZUC_ALG_ECDSA_DETERMINISTIC = 227. -
?zucrypt_c_apiand the C-API article now say that no other PSA Crypto or Mbed TLS may be linked into the same shared object aslibzucrypt.a: the archive’s backend symbols are hidden from other shared objects, not inside your own, so the link fails with a duplicate symbol (#112).
Bug fixes
C interface:
zucrypt-r.hresolved the function table through a union, which is defined in C and undefined in ISO C++ (#113). A C++ consumer now converts withreinterpret_cast; C consumers are unchanged.The archive-consumer
configurerecipe in “Using zucrypt from C” put the library path intosedunescaped, so a path containing&or|linked the wrong file, and one containing'broke the quoting ofPKG_LIBS(#110). The recipe now escapes the first and refuses the second with a message, aszuxlsx’s configure does.Unloading zucrypt –
unloadNamespace(), and sopkgload::unload()anddevtools::load_all()– while keys or contexts were still alive crashed R at the next garbage collection, which called their finalizers in the unloaded library (#144)..onUnload()now finalizes every live object first; one that outlives the unload is refused as no longer valid.On 64-bit Arm under systems other than Linux and macOS (FreeBSD, Windows), AES is built with the software implementation (#144). The hardware path is detected at run time only on Linux upstream, and assumed elsewhere, so a CPU without the Cryptography Extension would have failed on its first AES operation.
crypt_equal()and the AES-CBC functions read past the end of a buffer when given a classed raw vector whoselength()method misreports its length:crypt_equal()could answerTRUEwrongly or crash R, and a 1-byte IV was read as 16 (#106). The native code now checks every length, number, name and flag it relies on, rather than trusting R’s checks; a logicalNAreaching it is an error rather thanFALSE(#107).crypt_signature_create()andcrypt_signature_verify()given a non-blocking connection whose data had not all arrived signed or verified the part received so far, as if it were the whole (#145). Every function that reads a connection (crypt_hash(),crypt_hmac(),crypt_read_key(),crypt_read_pubkey(), and the signature functions’dataandsig) now goes through one reader, which refuses such a connection withzucrypt_connection_error, refuses a text-mode one withzucrypt_invalid_argument, and reports a connection or file that cannot be opened, or a directory given as a key path, as a zucrypt condition rather than R’s own error. A key file is read to its end rather than to the size it had when the read began.C interface: a
zuc_hash,zuc_hmacorzuc_aeshandle kept across the lastzuc_shutdown()returnsZUC_ERR_NOT_READYafter a laterzuc_init(), and its free leaves the key store alone (#92). Before, the new backend could give its key id to a new handle, and the old handle then encrypted under the new handle’s key, returningZUC_OK, and its free destroyed that key.C interface:
zuc_aes_cbc_set_state()andzuc_aes_cbc_get_state()on a handle kept across the lastzuc_shutdown()returnedZUC_OKrather thanZUC_ERR_NOT_READY(#142).C interface: a digest or HMAC update that fails in the backend ends the operation until reset, as a finish does (#108). The handle had stayed “active”, and an empty update on it reported success.
Fixed before release, in the functions new here
Found by the reviews, fuzzing and tests of the additions above, before any of them was on CRAN.
crypt_rand_bytes(), key generation and randomised signing failed withzucrypt_entropy_erroron Linux when the kernel refusesgetrandom(): a kernel before 3.17 under a recent glibc, as in a current container on an old host, or a seccomp filter (#144). They now read/dev/urandominstead, andcrypt_info()$build_flags$random_backendsays so.A condition about a key now carries that key’s type in its
algorithmfield ("rsa","p256","p384","p521"or"x25519"), andNAwhen the input is not a key (#143); every key condition said"rsa". A public key object given where a private key is needed, as incrypt_signature_create(data, key = k$pubkey), is refused naming that argument and the function called, rather than as a badfiletocrypt_read_key().C interface: two places where the adapter broke a promise of
zucrypt.h(#142).zuc_pkey_write()refused a PEM encoding written into a buffer of exactly its length, and wrote a NUL past it into a larger one; it now needs exactly the length it reports and writes nothing more.zuc_pkey_decrypt()andzuc_pkey_agree()left the output buffer as it was when they refused an argument (a public key, an unsupported scheme, a peer on another curve), rather than zeroing it. The R functions were not affected.RSA keys follow one size rule everywhere: a modulus of 1024 to 4096 bits, a whole number of bytes (#141).
crypt_read_key(),crypt_read_pubkey()andcrypt_rsa_key()now refuse a key under 1024 bits, which they read and used before, aszucrypt_unsupported_algorithm;opensslstill reads such keys. A key of 1028 or 2047 bits, which the bundled library cannot use, is refused with a message naming the rule rather than “up to 4096 bits”.crypt_rsa_keygen()refuses a size that is not a multiple of 8 aszucrypt_invalid_argumentup front; 1025 used to pass the check and fail in the backend as an unsupported algorithm.A failing operating-system random source is reported as
zucrypt_entropy_error(ZUC_ERR_ENTROPYin C) by every key operation (#140).crypt_rsa_decrypt()reported it aszucrypt_auth_error, as if the ciphertext had been forged,crypt_ec_dh()andcrypt_x25519_diffie_hellman()aszucrypt_invalid_argument, as if the peer key were bad, and in C, writing the public half of a private EC or X25519 key as SubjectPublicKeyInfo returnedZUC_ERR_BACKEND. Decryption still reports every padding failure as the one status.Writing a private key as PEM (
crypt_write_pem(), and the PEM forms of the C API’szuc_pkey_write()) left the key’s base64 in freed memory: the vendored PEM writer released its buffer without wiping it (#137). A fourth local patch to TF-PSA-Crypto wipes it. A new test searches every block the backend frees during a key write or read, for RSA, P-256, P-384, P-521 and X25519 in every encoding, for a piece of the private key.In the C API,
zuc_aead_encrypt()andzuc_aead_decrypt()now refuse, withZUC_ERR_OVERLAP, a tag or output buffer that overlaps any other buffer of the call, aszucrypt.hpromised (#138). Before, a tag inside the ciphertext silently overwrote it, an output over the tag failed a valid message, and a short tag with partially overlapping input and output zeroed part of the caller’s ciphertext. The R functions were not affected: they never share buffers.crypt_ecdsa_parse()reads strict DER (#91). It accepted a SEQUENCE or INTEGER whose length ran past the input, padding a truncated INTEGER with invented zero bytes, and negative and non-minimal INTEGERs. It now refuses them, and bytes after the signature too, whichopenssl::ecdsa_parse()ignores. Signature verification was not affected.An RSA key over 4096 bits, the bundled library’s limit, is
zucrypt_unsupported_algorithmfrom bothcrypt_read_key()andcrypt_read_pubkey(), in every encoding, and the message names the limit (#93). A public key was reported as “not a key”, and a private key in DER depended on its encoding.C interface:
zuc_aead_decrypt()zeroes the output on everyZUC_ERR_AUTH, including a tag of the wrong length, which is refused before the backend runs and used to leave the buffer as it was. Found by the new GCM fuzz target’s oracle.PEM input gives its first key block, as
opensslreads it (#180). A file holding several keys gave whichever block the bundled library’s search ranked first – a laterRSA PRIVATE KEYorEC PRIVATE KEYblock over a firstPRIVATE KEY– so a signature could be checked against a key other than the oneopensslwould use. Text before the block, asopenssl pkcs12 -nodeswrites (“Bag Attributes”), was refused; it is now passed over, as are blocks with other labels (EC PARAMETERS).An X25519 private key is written with the 32 bytes it was read from (#175). They were written clamped (RFC 7748 section 5), so a key did not round-trip,
as.list(key)$data$dand the encodings differed fromopenssl’s for any key not already clamped, though every shared secret was right. Keys fromcrypt_x25519_keygen()were not affected.?crypt_rsa_cryptostated the PSS salt rule loosely (#181): the salt is the digest’s length, or the most that fits in a key too small for that, and verification requires exactly that length.
Backend
-
The vendored TF-PSA-Crypto is updated from 1.1.1 to 1.1.2 (#173), a security release on the 1.1 LTS line. It fixes, in code zucrypt compiles:
- Spectre v1 side channels in hardware AES and GCM, which a powerful local attacker could use to recover part of a key or plaintext through the software fallback executed speculatively (CVE-2026-115493);
- in the cipher module (CVE-2026-93833), in ECDSA signing, which may leak the private key (CVE-2026-93835), and in PSA ECC operations (CVE-2026-93842);
- a shared secret left unwiped on the stack by
psa_key_agreement(); - the public half of an RSA key not being set when it was read from PKCS#8;
- wrong SHA-1 and SHA-256 digests for a single update of 4 GiB or more on 64-bit platforms. The R functions feed the backend 1 MiB at a time, but a C caller of
zuc_hash_compute()with that much data was affected.
The release’s other advisories do not apply to this build: the p256-m driver (CVE-2026-93845) and PKCS#5 and PKCS#12 decryption (CVE-2026-50582) are not compiled, and the ROM-table timing issue (CVE-2026-115492) needs
MBEDTLS_AES_ROM_TABLES, which is not set. The trim is unchanged at 153 files. The four local patches are all still needed, and0002was refreshed for moved context. Enabled for the new functions: GCM, PBKDF2-HMAC, RSA, the PK, PEM, ASN.1 and Base64 modules, the NIST curves P-256, P-384 and P-521, Curve25519, ECDSA (with RFC 6979) and ECDH. The trim grew from 113 vendored files to 153, 43 of them compiled. Measured on macOS x86-64 from the 0.1.1 tarball, the tarball is 1.1 MB, and the installed
zucrypt.so448 KB andlibzucrypt.a1.5 MB.The backend allocates through
zuc_int_calloc(), which records a failed allocation. The RSA functions report any failure that followed one asZUC_ERR_MEMORY: inside bignum and ASN.1 code an allocation failure otherwise surfaced as an invalid key, a bad argument or an RNG failure.tools/make-rsa-kat.pyextracts the RFC 7515 A.2 and RFC 7516 A.1 and A.2 vectors and generates PSS and OAEP ones, and checks them all against Python’scryptography; the tests cross-verify withopenssl2.4.2.The AEAD and KDF vectors are checked outside the package by
tools/check-kat.py, against Python’scryptographyandhashlib, andtools/make-kat.R --checkcompares the GCM ciphertexts withopenssl.On glibc, a
getrandom()call interrupted by a signal is retried instead of being reported as an entropy failure.
zucrypt 0.1.0
CRAN release: 2026-10-23
First release, and the first on CRAN. A focused set of cryptographic primitives over raw vectors, backed by a vendored, pinned crypto library, published to R and to C. The seven R functions are stable, and the static archive is frozen as ABI 1, after its first consumer – zuxlsx’s decryption of password-protected workbooks – was built and tested against it. The registered table is experimental (see “C interface” below).
R interface
Seven functions, and deliberately no more:
-
crypt_hash()andcrypt_hmac()— SHA-1, SHA-256, SHA-384 and SHA-512 digests and keyed digests, of a raw vector or of everything a connection yields:crypt_hash(file(path))hashes a file in 1 MiB chunks without reading it into memory (#11). Raw vectors in, raw vectors out; a character value is never given a guessed encoding and never treated as a file name. Algorithm names match exactly, with no partial matching and no fallback. -
crypt_hex()— lower-case hex of a raw vector, converted in C, for printing or storing a digest. Hex stays an explicit step at the call site (#59). -
crypt_equal()— constant-time comparison. Unequal lengths returnFALSErather than pretending the length is secret. -
crypt_aes_cbc_encrypt_nopad()andcrypt_aes_cbc_decrypt_nopad()— AES-128/192/256 in CBC mode, with no padding and no authentication. Interoperability tools for formats that specify unauthenticated CBC, not a way to encrypt something of your own. -
crypt_info()— what this build contains, read from the compiled library.
Failures are R conditions classed c(<specific>, "zucrypt_error", "error", "condition"), mapped from the C status by enumerator name rather than by number. Every condition carries algorithm and native_status fields; for AES, algorithm names the cipher ("aes-256-cbc"), or "aes-cbc" when the key is what is wrong. No message ever contains a key, an IV or plaintext.
Fixed before the tag, from the package review in #51:
- A condition no longer carries the call that raised it, only the function’s name. Before,
print()on an error andconditionCall()showed the caller’s expression – literal keys and plaintext included – although the message itself was clean. -
crypt_hmac()(andzuc_hmac_*()) accept keys of any length, as documented. Keys of 8,192 bytes or more used to fail withzucrypt_unsupported_algorithm, because the backend caps an imported key there; a key longer than the hash’s block is now hashed first, as RFC 2104 specifies, which gives the same MAC. -
?crypt_aes_cbc_nopadnow authenticates the IV as well as the ciphertext in its encrypt-then-MAC advice and example. A MAC over the ciphertext alone let the IV, and so the first plaintext block, be changed undetected.
Renamed before release (#56): the CBC pair was crypt_aes_cbc_encrypt() and crypt_aes_cbc_decrypt() during development. The _nopad suffix names the difference from openssl::aes_cbc_encrypt(), which pads, so that code moved from openssl by changing a prefix can never silently get the padding back as plaintext. The unsuffixed names are reserved for an openssl-compatible padded pair. The C interface (zuc_aes_*()) is unchanged.
C interface
Both shapes the zu* family consumes siblings by, at ZUCRYPT_ABI_VERSION 1, with different stability (?zucrypt_c_api):
- A static archive,
libzucrypt.a, installed tolib/plus the R sub-architecture (lib/x64/on Windows), for a package that cannot carry anImports:—LinkingTo:only, no runtime dependency, and the consumer owns the backend’s lifetime throughzuc_init()/zuc_shutdown(). This is the primary shape, and it is frozen as ABI 1: within major version 1, functions may be added, nothing is removed or given a new meaning, and enumerator values are permanent. - A registered function table,
inst/include/zucrypt-r.h, for a package that can carry anImports:. Resolved lazily throughzucrypt_api(); test an appended field withZUCRYPT_API_HAS(). Experimental until a package uses it.
Settled before the freeze, from the first consumer’s report (#43):
-
zuc_algvalues are grouped into reserved ranges, published asZUC_ALG_*_FIRST/_LAST(digests, other MACs, ciphers and AEAD, key derivation, key families, signatures), so later families never renumber. - A buffer pointer may be
NULLexactly when its length is 0, for the incremental digest and HMAC calls as for CBC – now stated, and tested. - The lifecycle note in
zucrypt.hsays what an R package needs forzuc_shutdown()to run at all: an.onUnload()that callslibrary.dynam.unload(). The archive fixture now does, and its checks prove the DLL is released.
inst/include/zucrypt.h compiles standalone as C99 against <stddef.h> and <stdint.h>, and names no backend type: a consumer never has to reproduce this package’s build configuration.
Both shapes are exercised on Linux, macOS and Windows by consumer fixture packages, as a real consumer would use them: - the table through an Imports: + LinkingTo: package that calls every entry; - the archive through a LinkingTo-only package whose configure resolves libzucrypt.a.
The archive fixture’s checks cover: - linking through a library path that contains a space; - exporting no backend symbol from its own shared object; - running beside zucrypt in the same R session, in either load order; - running with zucrypt not installed at all.
Settled before any consumer linked the ABI (design revision 3):
- AES-ECB is not provided. Its one use was Office Standard encryption, which
zuxlsxdoes not implement. - The backend’s key store grows on demand, so the number of live AES and HMAC handles is bounded only by memory. The static store it replaces allowed 16 live AES handles per process and reported the 17th as an allocation failure.
-
ZUC_ERR_NOT_READY(9) is returned by a call made beforezuc_init()or after the lastzuc_shutdown(). -
zuc_infogainshardware_acceleration, appended after the required prefix, andcrypt_info()$build_flags$hardware_accelerationnow reads it from the compiled library. - TF-PSA-Crypto’s licence is installed as
licenses/tf-psa-crypto-LICENSE, since the archive carries its object code into every consumer.
Backend
Vendored TF-PSA-Crypto 1.1.1, an LTS release, trimmed to 113 files — the dependency closure of the sources that carry a symbol under this package’s configuration. Installation needs a C99 compiler and nothing else: no system cryptographic library, no CMake, no Python or Perl, and no network access.
AES runs on the CPU’s AES instructions — AES-NI on x86, the Cryptography Extension on 64-bit Arm — chosen at run time, and on a software fallback where the CPU has neither. The backend’s own security policy warns that the software fallback leaks key material through cache timing; crypt_info()$build_flags$aes_implementation reports which path a machine uses, and ?crypt_aes_cbc_nopad explains when that matters. Every path produces the same bytes. (Until the review in #51 hardware AES was off everywhere.)
Upstream symbols are hidden. The installed shared object exports exactly one symbol, R_init_zucrypt, so an independently vendored copy of the same library in another package cannot bind to this one, and no OpenSSL-ABI name is exported beside the libcrypto other packages link.
Supported platforms
Checked on every push: Linux, macOS (ARM64) and Windows; R release, oldrel-1 and 4.1; CRAN’s clang-23 and GCC-16 containers; the no-Suggests flavour; LTO; rchk and gctorture; ASan, UBSan, valgrind and GCC’s -fanalyzer. Weekly: i386, musl and aarch64 builds that run the test suite and fail on a WARNING, and a sweep that fails each allocation the crypt_*() calls make, one run per allocation — about 250 of them, of which some 77 land in zucrypt’s own code — checking that each surfaces as an error rather than a crash or a wrong answer.
Correctness is checked against published vectors — FIPS 180-2, RFC 2202, RFC 4231, RFC 6234 and NIST SP 800-38A, including the one-million-byte messages and HMAC keys longer than the block — every one of which is also recomputed with OpenSSL, an implementation sharing no code with the vendored backend. Inputs up to 4 MiB are compared with OpenSSL directly, and the iterated hash Office agile encryption uses is checked against msoffcrypto-tool.
Not in this release
Deliberate omissions, each waiting on a concrete consumer rather than on effort: authenticated encryption, password-based key derivation (PBKDF2, HKDF, Argon2), random byte generation, signatures, key serialization, file hashing and connection wrappers. There is no encrypt_file(password = ), and there will not be one without a specified authenticated format, a nonce policy and a key derivation step.
Office/Excel decryption is not here either. It belongs to zuxlsx, which consumes this package.