Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 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
2 changes: 2 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BasedOnStyle: Google
ColumnLimit: 100
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ name: CI

on:
push:
branches: ['**']
branches: [master]
pull_request:
branches: [master]

jobs:
build:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,4 @@ gprof2dot.py
bin/
cryfa
keygen
results/
63 changes: 60 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,54 @@ cmake_minimum_required(VERSION 4.0.0)

project(cryfa)

set(CRYFA_VERSION_OVERRIDE "" CACHE STRING "Override the version embedded in Cryfa")
set(CRYFA_VERSION "0.0.0-dev")

if(CRYFA_VERSION_OVERRIDE)
set(CRYFA_VERSION "${CRYFA_VERSION_OVERRIDE}")
elseif(DEFINED ENV{GITHUB_REF_TYPE} AND "$ENV{GITHUB_REF_TYPE}" STREQUAL "tag")
set(CRYFA_VERSION "$ENV{GITHUB_REF_NAME}")
string(REGEX REPLACE "^v" "" CRYFA_VERSION "${CRYFA_VERSION}")
else()
find_package(Git QUIET)

if(Git_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
execute_process(
COMMAND "${GIT_EXECUTABLE}" describe --tags --exact-match
--match "v[0-9]*" --match "[0-9]*"
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE CRYFA_GIT_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
RESULT_VARIABLE CRYFA_GIT_VERSION_RESULT
)

if(NOT CRYFA_GIT_VERSION_RESULT EQUAL 0)
execute_process(
COMMAND "${GIT_EXECUTABLE}" describe --tags --dirty --always
--match "v[0-9]*" --match "[0-9]*"
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE CRYFA_GIT_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
RESULT_VARIABLE CRYFA_GIT_VERSION_RESULT
)
endif()

if(CRYFA_GIT_VERSION_RESULT EQUAL 0 AND CRYFA_GIT_VERSION)
string(REGEX REPLACE "^v" "" CRYFA_VERSION "${CRYFA_GIT_VERSION}")
endif()
endif()
endif()

set(CRYFA_GENERATED_INCLUDE_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated")
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/version.hpp.in"
"${CRYFA_GENERATED_INCLUDE_DIR}/cryfa/version.hpp"
@ONLY
)
message(STATUS "Cryfa version: ${CRYFA_VERSION}")

# On MSVC x64 the cryptopp runtime uses hand-coded MASM routines
# (CPUID64, XGETBV64, Baseline_Add/Sub, SHA256/GCM/Rijndael_*_SSE2).
# Enable the MASM language so CMake can assemble x64dll.asm.
Expand Down Expand Up @@ -169,13 +217,19 @@ add_library(libCryfaCommon OBJECT
src/fastq.cpp
src/security.cpp
)
target_include_directories(libCryfaCommon PRIVATE src/include)
target_include_directories(libCryfaCommon PRIVATE
src/include
"${CRYFA_GENERATED_INCLUDE_DIR}"
)
target_link_libraries(libCryfaCommon PRIVATE cryptopp-dep)

add_executable(cryfa
src/cryfa.cpp
)
target_include_directories(cryfa PRIVATE src/include)
target_include_directories(cryfa PRIVATE
src/include
"${CRYFA_GENERATED_INCLUDE_DIR}"
)
target_link_libraries(cryfa PRIVATE
Threads::Threads
libCryfaCommon
Expand All @@ -185,7 +239,10 @@ target_link_libraries(cryfa PRIVATE
add_executable(keygen
src/keygen.cpp
)
target_include_directories(keygen PRIVATE src/include)
target_include_directories(keygen PRIVATE
src/include
"${CRYFA_GENERATED_INCLUDE_DIR}"
)

# ── CTest round-trip integration test ────────────────────────────────────────
enable_testing()
Expand Down
42 changes: 20 additions & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
# ── Stage 1: builder ─────────────────────────────────────────────────────────-
FROM ubuntu:22.04 AS builder
LABEL maintainer="Morteza Hosseini"

ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update \
&& apt-get install -y --no-install-recommends build-essential git python3-pip \
&& pip3 install cmake \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /src
COPY . .
RUN cmake -B build -DCMAKE_BUILD_TYPE=Release \
&& cmake --build build --parallel "$(nproc)" --config Release

# ── Stage 2: runtime ─────────────────────────────────────────────────────────-
FROM debian:bookworm-slim

COPY --from=builder /src/build/cryfa /usr/local/bin/cryfa
COPY --from=builder /src/build/keygen /usr/local/bin/keygen

ENTRYPOINT ["cryfa"]
FROM ubuntu:22.04 AS builder
LABEL maintainer="Morteza Hosseini"

ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update \
&& apt-get install -y --no-install-recommends build-essential git python3-pip \
&& pip3 install cmake \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /src
COPY . .
RUN cmake -B build -DCMAKE_BUILD_TYPE=Release \
&& cmake --build build --parallel "$(nproc)" --config Release

FROM debian:bookworm-slim AS runtime

COPY --from=builder /src/build/cryfa /usr/local/bin/cryfa
COPY --from=builder /src/build/keygen /usr/local/bin/keygen

ENTRYPOINT ["cryfa"]
42 changes: 25 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<p align="center"><img src="logo.png" alt="Cryfa" height="150"/></p>

[![Conda Version](https://anaconda.org/bioconda/cryfa/badges/version.svg)](https://anaconda.org/bioconda/cryfa)
[![Anaconda version](https://anaconda.org/bioconda/cryfa/badges/version.svg)](https://anaconda.org/bioconda/cryfa)
[![Anaconda downloads](https://anaconda.org/bioconda/cryfa/badges/downloads.svg)](https://anaconda.org/bioconda/cryfa)
[![CI](https://github.com/cobilab/cryfa/actions/workflows/ci.yml/badge.svg)](https://github.com/cobilab/cryfa/actions/workflows/ci.yml)
[![Platforms](https://anaconda.org/bioconda/cryfa/badges/platforms.svg)](https://anaconda.org/bioconda/cryfa)
[![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](LICENSE)
[![License](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](LICENSE)

Cryfa is an ultrafast encryption tool specifically designed for genomic data. Besides providing robust security, it also compresses FASTA/FASTQ sequences by a factor of three, making it an efficient solution for managing genomic data.

# Installation
## Installation

## Conda
### Conda

```sh
conda install -y bioconda::cryfa
```

## Docker
### Docker

The image is available for **linux/amd64** and **linux/arm64** (Apple Silicon, AWS Graviton).

Expand All @@ -32,9 +32,9 @@ docker run --rm -v /path/to/data:/data smortezah/cryfa \
-k /data/pass.txt -d /data/out.crf > restored.fq
```

## Build from source
### Build from source

### Linux
#### Linux

```sh
# Install git and cmake (≥ 4.0)
Expand All @@ -48,7 +48,7 @@ cd cryfa;
sh install.sh;
```

### macOS
#### macOS

```sh
# Install Homebrew, git and cmake
Expand All @@ -61,7 +61,7 @@ cd cryfa;
sh install.sh;
```

### Windows
#### Windows

```powershell
# Install CMake and Visual Studio Build Tools (requires winget)
Expand All @@ -77,7 +77,7 @@ cd cryfa
> [!NOTE]
> Pre-compiled binaries for 64-bit Linux, macOS, and Windows are available as assets on the [Releases](https://github.com/cobilab/cryfa/releases) page.

# Usage
## Usage

Run Cryfa with:

Expand All @@ -102,7 +102,7 @@ A sample file, `in.fq`, is available in the `example/` directory.
> [!NOTE]
> Cryfa supports a maximum file size of 64 GB. For larger files, consider splitting them into smaller chunks, e.g. using the `split` command in Linux, and then encrypt each chunk separately. After decryption, you can reassemble the chunks using the `cat` command.

## Input file format
### Input file format

Cryfa identifies the format of a genomic data file by examining its content, not its extension. For instance, a FASTA file named `test` can be provided with any extension — `test`, `test.fa`, `test.fasta`, `test.fas`, `test.fsa`, etc. So, running

Expand All @@ -119,7 +119,7 @@ is equivalent to running
> [!NOTE]
> The password file can have any extension or none at all -- `pass`, `pass.txt`, `pass.dat`, etc. are all valid and yield the same result.

## Options
### Options

Cryfa supports the following options:

Expand All @@ -139,7 +139,7 @@ Cryfa supports the following options:

Cryfa leverages the standard output stream, allowing seamless integration with existing data processing pipelines.

## Creating a Key File
### Creating a Key File

There are two ways to create a `KEY_FILE` for use with `-k` / `--key`: save a raw password in a file, or use the `keygen` program to generate a strong one. The latter is strongly recommended.

Expand Down Expand Up @@ -182,7 +182,7 @@ The generated key will be saved to the file you specify (e.g., `key.txt`). Note

To learn more about key management (generation, exchange, storage, usage, and replacement of keys), see [[1]](https://en.wikipedia.org/wiki/Key_management), [[2]](https://info.townsendsecurity.com/definitive-guide-to-encryption-key-management-fundamentals), [[3]](https://csrc.nist.gov/projects/key-management/cryptographic-key-management-systems) and [[4]](https://www.cryptomathic.com/news-events/blog/what-is-key-management-a-ciso-perspective).

## Benchmarking Cryfa Against Other Methods
### Benchmarking Cryfa Against Other Methods

To benchmark Cryfa against other methods, configure the parameters in the **bench_cryfa.sh** bash script and execute it:

Expand All @@ -192,13 +192,21 @@ To benchmark Cryfa against other methods, configure the parameters in the **benc

This script automates the process of downloading datasets, installing dependencies, setting up compression and encryption tools, executing these tools, and finally, displaying the results.

# Citation
For quick local performance and correctness checks, use the local harness:

```sh
sh scripts/runtime/run_local_perf.sh --label local-check --input example/in.fq --target-mb 200 --threads "1 4 8" --runs 1 --modes both --no-prompt
```

The local harness expands the seed input to the requested size, measures compression and decompression, verifies every round trip with `cmp`, and writes CSV/Markdown reports under `results/local_perf/`.

## Citation

If you use Cryfa in your research, please cite the following references:

- M. Hosseini, D. Pratas and A.J. Pinho, "Cryfa: a secure encryption tool for genomic data," _Bioinformatics_, vol. 35, no. 1, pp. 146--148, 2018. [DOI: 10.1093/bioinformatics/bty645](https://doi.org/10.1093/bioinformatics/bty645)
- **[OPTIONAL]** D. Pratas, M. Hosseini and A.J. Pinho, "Cryfa: a tool to compact and encrypt FASTA files," _11'th International Conference on Practical Applications of Computational Biology & Bioinformatics_ (PACBB), Springer, June 2017. [DOI: 10.1007/978-3-319-60816-7_37](https://doi.org/10.1007/978-3-319-60816-7_37)

# License
## License

Cryfa is licensed under the [GPLv3](http://www.gnu.org/licenses/gpl-3.0.html).
14 changes: 14 additions & 0 deletions bench_cryfa.sh
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,20 @@ RUN_CRYFA_THR=1
# Results
RESULTS_CRYFA_THR=0

# Run lightweight local performance harness
RUN_LOCAL_PERF=0
LOCAL_PERF_LABEL="baseline"
LOCAL_PERF_COMPARE_TO=""
LOCAL_PERF_INPUT="example/in.fq"
LOCAL_PERF_TARGET_MB=200
LOCAL_PERF_THREADS="1 4 8"
LOCAL_PERF_RUNS=1
LOCAL_PERF_MODES="default stop-shuffle"
LOCAL_PERF_INTERACTIVE="auto"
LOCAL_PERF_BIN="build/cryfa"
LOCAL_PERF_KEY_FILE="pass.txt"
LOCAL_PERF_OUT_DIR="results/local_perf"

# Run different methods to explore redundancy
RUN_REDUNDANCY=0 # Cryfa, DELIMINATE, MFCompress
# Dataset (FASTA) -- archaea, bacteria, fungi, plants, viruses
Expand Down
10 changes: 10 additions & 0 deletions cmake/version.hpp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef CRYFA_VERSION_HPP
#define CRYFA_VERSION_HPP

#include <string>

namespace cryfa {
inline const std::string VERSION = "@CRYFA_VERSION@";
} // namespace cryfa

#endif // CRYFA_VERSION_HPP
Loading