Skip to content

Commit

Permalink
Merge pull request #5 from g-andrade/drop-otp-19-and-20-and-21-compat…
Browse files Browse the repository at this point in the history
…ibility

By OTP 19, 20 and 21; hello, OTP 24
  • Loading branch information
g-andrade authored May 13, 2021
2 parents 8856e29 + 84fd2a1 commit acdf9e8
Show file tree
Hide file tree
Showing 14 changed files with 71 additions and 138 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ jobs:
image: erlang:${{matrix.otp_vsn}}
strategy:
matrix:
otp_vsn: [19.0, 19.1, 19.2, 19.3,
20.0, 20.1, 20.2, 20.3,
21.0, 21.1, 21.2, 21.3,
22.0, 22.1, 22.2, 22.3,
23.0, 23.1, 23.2]
otp_vsn: [22.0, 22.1, 22.2, 22.3,
23.0, 23.1, 23.2, 23.3,
24.0]
os: [ubuntu-latest]
steps:
- uses: actions/checkout@v2
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ erl_crash.dump
logs
_build
.idea
doc/overview.edoc
14 changes: 11 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,17 @@ dialyzer: $(REBAR3)
xref: $(REBAR3)
@$(REBAR3) xref

doc: build
./scripts/hackish_inject_version_in_docs.sh
./scripts/hackish_make_docs.sh
doc: $(REBAR3)
@$(REBAR3) edoc

README.md: doc
# non-portable dirty hack follows (pandoc 2.1.1 used)
# gfm: "github-flavoured markdown"
@pandoc --from html --to gfm doc/overview-summary.html -o README.md
@tail -n +11 <"README.md" >"README.md_"
@head -n -12 <"README.md_" >"README.md"
@tail -n 2 <"README.md_" >>"README.md"
@rm "README.md_"

test: $(REBAR3)
@$(REBAR3) eunit
Expand Down
88 changes: 36 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,78 +1,67 @@


# erlffx #

Copyright (c) 2017-2021 Guilherme Andrade

__Version:__ 1.1.1

__Authors:__ Guilherme Andrade ([`erlffx(at)gandrade(dot)net`](mailto:erlffx(at)gandrade(dot)net)).

`erlffx`: Format Preserving Encryption - FFX for Erlang


---------

`erlffx` is an Erlang implementation of the mechanism described in the 2010 paper [The FFX Mode of Operation for Format-Preserving Encryption](http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.304.1736&rep=rep1&type=pdf) by Bellare, Rogaway and Spies. It is based on an existing [Java implementation](https://github.com/michaeltandy/java-ffx-format-preserving-encryption) by Michael Tandy.

* AES-128 / AES-192 (only Erlang 19 and up) / AES-256 keys are supported (CBC mode)
* Any positive word length is supported
* Any radix / alphabet size between 2 and 255 is acceptable (10 by default)
* Optional 'tweak' values may be defined
* Number of rounds is configurable (10 by default)

The code was successfully tested on generations 17, 18 and 19 of Erlang/OTP; the unit tests themselves were written using the following lists of test vectors:
* [AES FFX Test Vector Data](http://csrc.nist.gov/groups/ST/toolkit/BCM/documents/proposedmodes/ffx/aes-ffx-vectors.txt)
* [FF1 samples](http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/FF1samples.pdf)


### <a name="Examples">Examples</a> ###


```erlang

# erlffx

[![](https://img.shields.io/hexpm/v/erlffx.svg?style=flat)](https://hex.pm/packages/erlffx)
[![](https://github.com/g-andrade/erlffx/workflows/build/badge.svg)](https://github.com/g-andrade/erlffx/actions?query=workflow%3Abuild)

`erlffx` is an Erlang implementation of the mechanism described in the
2010 paper [The FFX Mode of Operation for Format-Preserving
Encryption](http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.304.1736&rep=rep1&type=pdf)
by Bellare, Rogaway and Spies. It is based on an existing [Java
implementation](https://github.com/michaeltandy/java-ffx-format-preserving-encryption)
by Michael Tandy.

\* AES-128 / AES-192 (only Erlang 19 and up) / AES-256 keys are
supported (CBC mode) \* Any positive word length is supported \* Any
radix / alphabet size between 2 and 255 is acceptable (10 by default) \*
Optional 'tweak' values may be defined \* Number of rounds is
configurable (10 by default)

The code was successfully tested on generations 17, 18 and 19 of
Erlang/OTP; the unit tests themselves were written using the following
lists of test vectors: \* [AES FFX Test Vector
Data](http://csrc.nist.gov/groups/ST/toolkit/BCM/documents/proposedmodes/ffx/aes-ffx-vectors.txt)
\* [FF1
samples](http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/FF1samples.pdf)

### <span id="Examples">Examples</span>

``` erlang
% AES-128 CBC / 10-digit decimal words
AesKey = <<43,126,21,22,40,174,210,166,171,247,21,136,9,207,79,60>>,
ValueLength = 10,
Config = erlffx:config(AesKey, ValueLength).

Encrypted = erlffx:encrypt(Config, 123456789). % 2433477484
Decrypted = erlffx:decrypt(Config, Encrypted). % 123456789

```

---------

```erlang
-----

``` erlang
% AES-128 CBC / 10-digit decimal words / custom tweak
AesKey = <<43,126,21,22,40,174,210,166,171,247,21,136,9,207,79,60>>,
ValueLength = 10,
Config = erlffx:config(AesKey, ValueLength, #{ tweak => "9876543210" }).

Encrypted = erlffx:encrypt(Config, 123456789). % 6124200773
Decrypted = erlffx:decrypt(Config, Encrypted). % 123456789

```

---------

```erlang
-----

``` erlang
% AES-128 CBC / 16-digit base-36 words / custom tweak
AesKey = <<43,126,21,22,40,174,210,166,171,247,21,136,9,207,79,60>>,
ValueLength = 16,
Config = erlffx:config(AesKey, ValueLength, #{ tweak => "TQF9J5QDAGSCSPB1", radix => 36 }).

Encrypted = erlffx:encrypt(Config, 36#C4XPWULBM3M863JH). % 36#C8AQ3U846ZWH6QZP
Decrypted = erlffx:decrypt(Config, Encrypted). % 36#C4XPWULBM3M863JH

```

---------

```erlang
-----

``` erlang
% AES-256 CBC / 6-digit binary words
AesKey = <<43,126,21,22,40,174,210,166,171,247,21,136,9,207,79,60,
239,67,89,216,213,128,170,79,127,3,109,111,4,252,106,148>>,
Expand All @@ -81,13 +70,8 @@ Config = erlffx:config(AesKey, ValueLength, #{ radix => 2 }).

Encrypted = erlffx:encrypt(Config, 2#000001). % 2#100100
Decrypted = erlffx:decrypt(Config, Encrypted). % 2#000001

```

-----

## Modules ##


<table width="100%" border="0" summary="list of modules">
<tr><td><a href="https://github.com/g-andrade/erlffx/blob/master/doc/erlffx.md" class="module">erlffx</a></td></tr></table>

*Generated by EDoc*
1 change: 1 addition & 0 deletions doc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*
18 changes: 9 additions & 9 deletions doc/overview-summary.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
<body bgcolor="white">
<div class="navbar"><a name="#navbar_top"></a><table width="100%" border="0" cellspacing="0" cellpadding="2" summary="navigation bar"><tr><td><a href="overview-summary.html" target="overviewFrame">Overview</a></td><td><a href="http://www.erlang.org/"><img src="erlang.png" align="right" border="0" alt="erlang logo"></a></td></tr></table></div>
<h1>erlffx</h1>
<p>Copyright © 2017-2021 Guilherme Andrade</p>
<p><b>Version:</b> 1.1.1</p>
<p><b>Authors:</b> Guilherme Andrade (<a href="mailto:erlffx(at)gandrade(dot)net"><tt>erlffx(at)gandrade(dot)net</tt></a>).</p>
<p><code>erlffx</code>: Format Preserving Encryption - FFX for Erlang</p>

<hr>

<p><a target="_parent" href="https://hex.pm/packages/erlffx" alt="Hex.pm Package">
<img src="https://img.shields.io/hexpm/v/erlffx.svg?style=flat"></a>
<a target="_parent" href="https://github.com/g-andrade/erlffx/actions?query=workflow%3Abuild" alt="Travis CI Build Status">
<img src="https://github.com/g-andrade/erlffx/workflows/build/badge.svg"></a></p>

<p><code>erlffx</code> is an Erlang implementation of the mechanism described in the 2010 paper <a href="http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.304.1736&amp;rep=rep1&amp;type=pdf">The FFX Mode of Operation for Format-Preserving Encryption</a> by Bellare, Rogaway and Spies. It is based on an existing <a href="https://github.com/michaeltandy/java-ffx-format-preserving-encryption">Java implementation</a> by Michael Tandy.</p>

Expand All @@ -28,7 +28,7 @@ <h1>erlffx</h1>
* <a href="http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/FF1samples.pdf">FF1 samples</a></p>

<h3><a name="Examples">Examples</a></h3>
<pre lang="erlang">
<pre lang="erlang" class="erlang">
% AES-128 CBC / 10-digit decimal words
AesKey = &lt;&lt;43,126,21,22,40,174,210,166,171,247,21,136,9,207,79,60&gt;&gt;,
ValueLength = 10,
Expand All @@ -40,7 +40,7 @@ <h3><a name="Examples">Examples</a></h3>

<hr>

<pre lang="erlang">
<pre lang="erlang" class="erlang">
% AES-128 CBC / 10-digit decimal words / custom tweak
AesKey = &lt;&lt;43,126,21,22,40,174,210,166,171,247,21,136,9,207,79,60&gt;&gt;,
ValueLength = 10,
Expand All @@ -52,7 +52,7 @@ <h3><a name="Examples">Examples</a></h3>

<hr>

<pre lang="erlang">
<pre lang="erlang" class="erlang">
% AES-128 CBC / 16-digit base-36 words / custom tweak
AesKey = &lt;&lt;43,126,21,22,40,174,210,166,171,247,21,136,9,207,79,60&gt;&gt;,
ValueLength = 16,
Expand All @@ -64,7 +64,7 @@ <h3><a name="Examples">Examples</a></h3>

<hr>

<pre lang="erlang">
<pre lang="erlang" class="erlang">
% AES-256 CBC / 6-digit binary words
AesKey = &lt;&lt;43,126,21,22,40,174,210,166,171,247,21,136,9,207,79,60,
239,67,89,216,213,128,170,79,127,3,109,111,4,252,106,148&gt;&gt;,
Expand Down
18 changes: 9 additions & 9 deletions overview.edoc → doc/overview.edoc
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
@author Guilherme Andrade <erlffx(at)gandrade(dot)net>
@copyright 2017-2021 Guilherme Andrade
@version 1.1.1
@title erlffx
@doc `erlffx': Format Preserving Encryption - FFX for Erlang
@doc

<hr/>
<a target="_parent" href="https://hex.pm/packages/erlffx" alt="Hex.pm Package">
<img src="https://img.shields.io/hexpm/v/erlffx.svg?style=flat"/></a>
<a target="_parent" href="https://github.com/g-andrade/erlffx/actions?query=workflow%3Abuild" alt="Travis CI Build Status">
<img src="https://github.com/g-andrade/erlffx/workflows/build/badge.svg"/></a>

`erlffx' is an Erlang implementation of the mechanism described in the 2010 paper <a href="http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.304.1736&amp;rep=rep1&amp;type=pdf">The FFX Mode of Operation for Format-Preserving Encryption</a> by Bellare, Rogaway and Spies. It is based on an existing <a href="https://github.com/michaeltandy/java-ffx-format-preserving-encryption">Java implementation</a> by Michael Tandy.

Expand All @@ -19,7 +19,7 @@ The code was successfully tested on generations 17, 18 and 19 of Erlang/OTP; the
* <a href="http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/FF1samples.pdf">FF1 samples</a>

== Examples ==
<pre lang="erlang">
<pre lang="erlang" class="erlang">
% AES-128 CBC / 10-digit decimal words
AesKey = &lt;&lt;43,126,21,22,40,174,210,166,171,247,21,136,9,207,79,60&gt;&gt;,
ValueLength = 10,
Expand All @@ -31,7 +31,7 @@ Decrypted = erlffx:decrypt(Config, Encrypted). % 123456789

<hr/>

<pre lang="erlang">
<pre lang="erlang" class="erlang">
% AES-128 CBC / 10-digit decimal words / custom tweak
AesKey = &lt;&lt;43,126,21,22,40,174,210,166,171,247,21,136,9,207,79,60&gt;&gt;,
ValueLength = 10,
Expand All @@ -43,7 +43,7 @@ Decrypted = erlffx:decrypt(Config, Encrypted). % 123456789

<hr/>

<pre lang="erlang">
<pre lang="erlang" class="erlang">
% AES-128 CBC / 16-digit base-36 words / custom tweak
AesKey = &lt;&lt;43,126,21,22,40,174,210,166,171,247,21,136,9,207,79,60&gt;&gt;,
ValueLength = 16,
Expand All @@ -55,7 +55,7 @@ Decrypted = erlffx:decrypt(Config, Encrypted). % 36#C4XPWULBM3M863JH

<hr/>

<pre lang="erlang">
<pre lang="erlang" class="erlang">
% AES-256 CBC / 6-digit binary words
AesKey = &lt;&lt;43,126,21,22,40,174,210,166,171,247,21,136,9,207,79,60,
239,67,89,216,213,128,170,79,127,3,109,111,4,252,106,148&gt;&gt;,
Expand Down
5 changes: 2 additions & 3 deletions rebar.config
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{minimum_otp_vsn, "19"}.
{minimum_otp_vsn, "22"}.

{erl_opts,
[{platform_define, "^[2-9]", 'POST_OTP_19'},
{platform_define, "^((2[3-9])|([3-9]))", 'POST_OTP_22'},
[{platform_define, "^((2[3-9])|([3-9]))", 'POST_OTP_22'},
%bin_opt_info,
debug_info,
warn_export_all,
Expand Down
5 changes: 0 additions & 5 deletions scripts/hackish_inject_version_in_docs.sh

This file was deleted.

11 changes: 0 additions & 11 deletions scripts/hackish_make_docs.sh

This file was deleted.

1 change: 0 additions & 1 deletion scripts/requirements.txt

This file was deleted.

19 changes: 0 additions & 19 deletions scripts/version_from_git.py

This file was deleted.

6 changes: 0 additions & 6 deletions scripts/version_from_git.sh

This file was deleted.

14 changes: 0 additions & 14 deletions src/erlffx.erl
Original file line number Diff line number Diff line change
Expand Up @@ -226,20 +226,6 @@ fk(Config, P, RoundIndex, B_Value) ->
integer_to_list(ParamZ, Radix)]),
ParamZ.

-ifndef(POST_OTP_19).
-spec ceil(float()) -> integer().
ceil(V) when V < 0.0 ->
case (V - trunc(V)) >= -0.5 of
true -> trunc(V);
false -> trunc(V - 1)
end;
ceil(V) ->
case (V - trunc(V)) >= 0.5 of
true -> trunc(V + 1);
false -> trunc(V)
end.
-endif.

-spec generate_p(config()) -> p_value().
generate_p(#{ tweak := Tweak,
radix := Radix,
Expand Down

0 comments on commit acdf9e8

Please sign in to comment.