Git Product home page Git Product logo

libffx's People

Contributors

beny23m avatar crondaemon avatar kpdyer avatar sergeybe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

libffx's Issues

over padding when right block is 2^16

seems to over pad when right block is 2^16

    plain = FFXInteger('0000065536', radix=10)
    tweak = FFXInteger('0000000000', radix=10)
    key = FFXInteger('2b7e151628aed2a6abf7158809cf4f3c', radix=16, blocksize=32)

    ffx_obj = ffx.new(key.to_bytes(16), 10)
    cypher = ffx_obj.encrypt(tweak, plain)

Implementation differs from the paper for input with a range that exceeds 8^24

While working on a PHP implementation of the FFX[radix] algorithm, I compared the output of my implementation with this implementation. I noticed that the output begin to differ if the input range exceeds 8^24. This is due to a wrong implementation of the "expansion" of the Y variable.

In the paper Addendum to “The FFX Mode of Operation for Format-Preserving Encryption” it says:

Y ← first d + 4 bytes of (Y || AESK(Y ⊕ [1]16) || AESK(Y ⊕ [2]16) || AESK(Y ⊕ [3]16)··· )

However this implementation does actually:

Y ← first d + 4 bytes of (Y || AESK(Y ⊞ [1]16) || AESK(Y ⊞ [2]16) || AESK(Y ⊞ [3]16)··· )

Notice the difference between and . The paper states that for the scheme FFX[radix] is block-wise addition. While it is nowhere explicitly stated in the paper that means an XOR operation. However, it could be interpreted from the description of the CBC-MACK(X) algorithm (on page 2) as it states: for j ← 1 to m, set Y ← AESK(Y ⊕ Xi).

To correct this implementation these lines:

            left = FFXInteger(bytes_to_long(Y), radix=self._radix, blocksize=32)
            right = FFXInteger(str(i), radix=10, blocksize=16)
            X = self.add(left, right)
            TMP += self._ecb.encrypt(X.to_bytes(16))

should be replaced with:

            I = FFXInteger(str(i), radix=10, blocksize=16).to_bytes(16)
            X = "".join(chr(ord(Yi) ^ ord(Ii)) for Yi, Ii in zip(Y, I))
            TMP += self._ecb.encrypt(X)

Test data:

radix=16 key=0x00000000000000000000000000000000 tweak=

Current implementation
input  000000000000000000000000000000000000000000000000
output ddb77d3be91a8e255fca9389a3d48da2b4476919744febea
input  0000000000000000000000000000000000000000000000000
output 1dad7e05f03706e8af695246afa40a49876c1d3e0699c5be1

Expected
input  000000000000000000000000000000000000000000000000
output ddb77d3be91a8e255fca9389a3d48da2b4476919744febea
input  0000000000000000000000000000000000000000000000000
output 1f7b9459d22b2bee17d5b5616e03241467767c9dcbc424c21 

Radix > 36 raises ValueError

If I run benchmark.py --radix 62 it raises a ValueError.

Traceback (most recent call last):
  File "benchmark.py", line 68, in <module>
    main()
  File "benchmark.py", line 47, in main
    C = ffx.encrypt(T, M1)
  File "FFX/__init__.py", line 262, in encrypt
    C = self.add(A, self.F(n, T, i, B))
  File "FFX/__init__.py", line 199, in F
    if T == 0:
  File "FFX/__init__.py", line 117, in __eq__
    retval = (self.to_int() == other)
  File "FFX/__init__.py", line 143, in to_int
    self._as_int = int(self._x, self._radix)
ValueError: int() base must be >= 2 and <= 36

Need to update libffx on PyPI

Please update libffx package on PyPI. The source is ready.

There is old version:

$ pip search libffx
libffx (0.0.1)  - FFX

Thank you!

typo in setup.py

I can't install this lib because__init__.pyx doesn't exist, there is just__init__.py:

$$$:/tmp/libffx$ sudo python setup.py build
Traceback (most recent call last):
  File "setup.py", line 8, in <module>
    ext_modules = cythonize("FFX/__init__.pyx"),
  File "/usr/local/lib/python2.7/dist-packages/Cython/Build/Dependencies.py", line 758, in cythonize
    aliases=aliases)
  File "/usr/local/lib/python2.7/dist-packages/Cython/Build/Dependencies.py", line 651, in create_extension_list
    for file in nonempty(sorted(extended_iglob(filepattern)), "'%s' doesn't match any files" % filepattern):
  File "/usr/local/lib/python2.7/dist-packages/Cython/Build/Dependencies.py", line 103, in nonempty
    raise ValueError(error_msg)
ValueError: 'FFX/__init__.pyx' doesn't match any files

Keys with prefix \x00 raises ValueError

Hi,

with zero key ('0'*128) libFFX raises a ValueError:

import FFX
ffx_key = FFX.FFXInteger('0'*128, radix=2, blocksize = 128)
ffx = FFX.new(ffx_key.to_bytes(), 2)

ValueError: AES key must be either 16, 24, or 32 bytes long

This is caused by FFXInteger.to_bytes(), which strips leading null bytes:

>>> FFXInteger('1'*8+'0'*8, radix=2, blocksize=16).to_bytes()
'\xff\x00'
>>> FFXInteger('0'*8+'1'*8, radix=2, blocksize=16).to_bytes()
'\xff'

RADIX 62

Is it possible to support RADIX 62 and hove?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.