Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: CI

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
build-and-test:
name: Build and Test
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install dependencies (Ubuntu)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y \
libssl-dev \
libsecp256k1-dev \
autoconf \
automake \
libtool \
pkg-config \
autoconf-archive \
cmake

- name: Build and install libaes_siv
run: |
git clone https://github.com/dfoxfranke/libaes_siv.git
cd libaes_siv
mkdir build && cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local
make
sudo make install
sudo ldconfig

- name: Generate build system
run: ./autogen.sh

- name: Configure (Ubuntu)
if: runner.os == 'Linux'
run: ./configure

- name: Build
run: make

- name: Run tests
run: make check
23 changes: 20 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ autom4te.cache
/aclocal.m4
build-aux/compile
/config.cache
build-aux/config.guess
build-aux/config.guess*
/config.h.in
/config.h.in~
build-aux/config.log
build-aux/config.status
build-aux/config.sub
build-aux/config.sub*
/configure
/configure~
/configure.scan
build-aux/depcomp
build-aux/install-sh
build-aux/install-sh*
build-aux/missing
/stamp-h1

Expand All @@ -57,3 +57,20 @@ build-aux/m4/lt~obsolete.m4
# (which is called by configure script))
Makefile

# clangd
compile_commands.json
**/*.cache
**/*.libs
config.log

# build artifacts
**/*.o
**/*.la
**/*.lo

# tests
build-aux/test-driver
test_runner
test_runner.log
test_runner.trs
test-suite.log
45 changes: 44 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
ACLOCAL_AMFLAGS = -I build-aux/m4

# Use serial test harness to show test output in real-time
AUTOMAKE_OPTIONS = color-tests serial-tests

AM_CFLAGS = -Wall -g -O3

lib_LTLIBRARIES = liburcrypt.la
Expand Down Expand Up @@ -51,7 +54,8 @@ liburcrypt_la_CFLAGS = $(LIBCRYPTO_CFLAGS) \
$(LIBAES_SIV_CFLAGS)
# urcrypt_ is used for public symbols, urcrypt__ for internal.
liburcrypt_la_LDFLAGS = -export-symbols-regex '^urcrypt_[^_]' \
-version-info $(URCRYPT_LT_VERSION)
-version-info $(URCRYPT_LT_VERSION) \
-L/usr/local/lib -Wl,-rpath,/usr/local/lib
liburcrypt_la_SOURCES = urcrypt/aes_cbc.c \
urcrypt/aes_ecb.c \
urcrypt/aes_siv.c \
Expand Down Expand Up @@ -162,3 +166,42 @@ libkeccak_tiny_la_CFLAGS = -std=c11 -Wextra -Wpedantic -Wall
libkeccak_tiny_la_SOURCES = keccak-tiny/keccak-tiny.c \
keccak-tiny/define-macros.h \
keccak-tiny/keccak-tiny.h

# test suite
TESTS = test_runner
check_PROGRAMS = test_runner

test_runner_SOURCES = tests/test_runner.c \
tests/test_aes.c \
tests/test_argon2.c \
tests/test_blake3.c \
tests/test_ed25519.c \
tests/test_ge_additions.c \
tests/test_keccak.c \
tests/test_monocypher.c \
tests/test_ripemd.c \
tests/test_scrypt.c \
tests/test_secp256k1.c \
tests/test_sha.c

test_runner_CPPFLAGS = -I$(srcdir) \
-I$(srcdir)/ed25519/src \
-I$(srcdir)/ge-additions \
-I$(srcdir)/argon2/include \
-I$(srcdir)/blake3 \
-I$(srcdir)/monocypher \
-I$(srcdir)/keccak-tiny \
-I$(srcdir)/scrypt \
-I$(srcdir)/urcrypt

test_runner_CFLAGS = $(LIBCRYPTO_CFLAGS) \
$(LIBSECP256K1_CFLAGS) \
$(LIBAES_SIV_CFLAGS)

test_runner_LDFLAGS = -L/usr/local/lib -Wl,-rpath,/usr/local/lib

test_runner_LDADD = liburcrypt.la \
urcrypt/liburcrypt_la-util.o \
$(LIBCRYPTO_LIBS) \
$(LIBSECP256K1_LIBS) \
$(LIBAES_SIV_LIBS)
76 changes: 74 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,79 @@ libcrypto. Either build statically (pass `--disable-shared` to `./configure`)
or provide a shared libcrypto for urcrypt to link against. It is the library
user's responsibility to initialize openssl, set custom memory functions, etc.

Dependencies
------------
Urcrypt requires the following libraries:

- **OpenSSL (libcrypto)** - For cryptographic primitives
- **libsecp256k1** - For secp256k1 elliptic curve operations (must have recovery and Schnorr signature support enabled)
- **libaes_siv** - For AES-SIV authenticated encryption

### macOS Installation

Install the required tools and most dependencies via Homebrew:

```bash
# Install build tools
brew install autoconf automake libtool autoconf-archive pkg-config

# Install crypto libraries
brew install openssl@3 secp256k1
```

**libaes_siv** is not available via Homebrew and must be built from source:

```bash
git clone https://github.com/dfoxfranke/libaes_siv.git
cd libaes_siv
mkdir build && cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local
make
sudo make install
```

### Linux Installation

On Debian/Ubuntu:

```bash
sudo apt-get install autoconf automake libtool autoconf-archive pkg-config
sudo apt-get install libssl-dev libsecp256k1-dev

# libaes_siv must be built from source (same instructions as macOS)
```

Installation
------------
Note that, in addition to standard `autotools` packages, `urcrypt` requires
`autoconf-archive` in order to use a macro it provides.

Once dependencies are installed:

```bash
./autogen.sh
./configure
make
sudo make install
```

Building and Testing
--------------------
After installing dependencies, build the library:

```bash
./autogen.sh # Generate configure script
./configure # Configure the build (add --disable-shared for static linking)
make # Build the library
```

To run the test suite:

```bash
make check
```

To clean up build artifacts:

```bash
make clean # Remove built files
make distclean # Remove all generated files (including configure artifacts)
```
59 changes: 56 additions & 3 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,57 @@ PKG_INSTALLDIR
# Checks for programs
AC_PROG_CC

# macOS/Homebrew support: Add common Homebrew paths to PKG_CONFIG_PATH
# This helps find libraries installed via Homebrew on both Intel and Apple Silicon Macs
AS_CASE([$host_os],
[darwin*], [
# Check for Homebrew installation
AC_MSG_CHECKING([for Homebrew])
AS_IF([test -d /opt/homebrew], [
HOMEBREW_PREFIX="/opt/homebrew"
AC_MSG_RESULT([found at $HOMEBREW_PREFIX (Apple Silicon)])
], [test -d /usr/local/Cellar], [
HOMEBREW_PREFIX="/usr/local"
AC_MSG_RESULT([found at $HOMEBREW_PREFIX (Intel)])
], [
HOMEBREW_PREFIX=""
AC_MSG_RESULT([not found])
])

# Add Homebrew paths to PKG_CONFIG_PATH if Homebrew is present
AS_IF([test -n "$HOMEBREW_PREFIX"], [
AS_IF([test -n "$PKG_CONFIG_PATH"], [
export PKG_CONFIG_PATH="$HOMEBREW_PREFIX/lib/pkgconfig:$HOMEBREW_PREFIX/opt/openssl@3/lib/pkgconfig:$PKG_CONFIG_PATH"
], [
export PKG_CONFIG_PATH="$HOMEBREW_PREFIX/lib/pkgconfig:$HOMEBREW_PREFIX/opt/openssl@3/lib/pkgconfig"
])
AC_MSG_NOTICE([Added Homebrew paths to PKG_CONFIG_PATH: $PKG_CONFIG_PATH])
])
]
)

# Checks for pkg-config capable libraries
PKG_CHECK_MODULES([LIBSECP256K1], [libsecp256k1])
PKG_CHECK_MODULES([LIBSECP256K1], [libsecp256k1], [],
[AC_MSG_ERROR([
libsecp256k1 is required but was not found via pkg-config.

On macOS with Homebrew:
brew install secp256k1
])])
save_CPPFLAGS=$CPPFLAGS
CPPFLAGS="$CPPFLAGS $LIBSECP256K1_CFLAGS"
AC_CHECK_HEADER([secp256k1_recovery.h], [],
[AC_MSG_ERROR([libsecp256k1 must have recovery enabled.])])
AC_CHECK_HEADER([secp256k1_schnorrsig.h], [],
[AC_MSG_ERROR([libsecp256k1 must have Schnorr signatures enabled.])])
CPPFLAGS=$save_CPPFLAGS
PKG_CHECK_MODULES([LIBCRYPTO], [libcrypto])
PKG_CHECK_MODULES([LIBCRYPTO], [libcrypto], [],
[AC_MSG_ERROR([
libcrypto (OpenSSL) is required but was not found via pkg-config.

On macOS with Homebrew:
brew install openssl@3
])])

AS_IF([test "$enable_shared" == "yes"],
[# ensure crypto will be shared for shared object (see README.md)
Expand All @@ -91,7 +132,19 @@ AS_IF([test "$enable_shared" == "yes"],
# Checks for non pkg-config libraries
AC_CHECK_LIB([aes_siv], [AES_SIV_CTX_new],
[AC_SUBST([LIBAES_SIV_LIBS], "-laes_siv")],
[AC_MSG_ERROR([libaes_siv is required.])],
[AC_MSG_ERROR([
libaes_siv is required but was not found.

On macOS, you can install it from source:
git clone https://github.com/dfoxfranke/libaes_siv.git
cd libaes_siv
mkdir build && cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local
make
sudo make install

Make sure /usr/local/lib is in your DYLD_LIBRARY_PATH or library search path.
])],
[-lcrypto])

# Checks for header files.
Expand Down
23 changes: 23 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Urcrypt Test Suite

This directory contains the test suite for the urcrypt cryptography library.

## Structure

- `test_common.h` - Common test macros and utilities used by all test files
- `test_runner.c` - Main test runner that executes all test suites
- `test_*.c` - Individual test suite files for each module:
- `test_argon2.c` - Tests for Argon2 password hashing
- `test_blake3.c` - Tests for BLAKE3 cryptographic hash function
- `test_ed25519.c` - Tests for Ed25519 digital signatures
- `test_ge_additions.c` - Tests for Ed25519 curve group element operations
- `test_keccak.c` - Tests for Keccak/SHA-3 hash functions
- `test_monocypher.c` - Tests for ChaCha20 and Poly1305 primitives
- `test_scrypt.c` - Tests for scrypt key derivation function
- `test_urcrypt.c` - Tests for main library (AES, SHA, RIPEMD, secp256k1)

## Running Tests

```bash
make check
```
Loading