Giter Site home page Giter Site logo

otrv4 / libgoldilocks Goto Github PK

View Code? Open in Web Editor NEW
18.0 6.0 6.0 1.74 MB

An implementation of Mike Hamburg's Ed448 (Goldilocks) curve - derived from libdecaf. This is a mirror of https://bugs.otr.im/otrv4/libgoldilocks

License: Other

Makefile 1.06% Shell 0.01% Python 8.75% M4 2.53% C++ 32.92% C 54.74%
elliptic-curves decaf edwards-curve curve goldilocks ed448 ecc cryptography

libgoldilocks's Introduction

Goldilocks library

The Goldilocks library is a production library, providing the ed448 elliptic curve. It is based on Mike Hamburg's libdecaf library: ed448goldilocks.

This library is intended for developers who have experience with cryptography. It doesn't (yet?) include documentation on how to use digital signatures or key exchange securely. Consult your local cryptographer for advice.

Building the library

Before you try to build libgoldilocks, verify you have installed:

To generate project configuration:

$ autoreconf --install

To configure the project:

$ ./configure

To build and install:

$ make && make install

To run the tests:

$ make test

Using the library

  • To run the python wrapper: python setup.py install --user
  • To generate the code based on the curve data, per field and the decaf tables: make gen-code
  • To generate the code based on the curve data and per field: make gen-code-static
  • To test the programs: make test
  • To generate the main decaf library and its symlinks: make lib

Mailing lists

Because this is new software, please expect it to have bugs, perhaps even critical security bugs. If you are using it, please sign up for updates on Mike Hamburg's library (note here that any update that we consider useful for this library from libdecaf will be incorporated):

General elliptic curve operations.

This is a multi-purpose elliptic curve library. There is a C library, and a set of C++ wrapper headers. The C++ code consists entirely of inline calls, and has no compiled component.

The library implements a fairly complete suite of operations on ed448-Goldilocks:

  • Point and scalar serialization and deserialization.
  • Point addition, subtraction, doubling, and equality.
  • Point multiplication by scalars. Accelerated double- and dual-scalar multiply.
  • Scalar addition, subtraction, multiplication, division, and equality.
  • Construction of precomputed tables from points. Precomputed scalarmul.
  • Hashing to the curve with an Elligator variant. Inverse of elligator for steganography. These are useful for advanced protocols such as password-authenticated key exchange (PAKE) and verifiable random functions (VRFs).

Internally, the library uses twisted Edwards curves with the "decaf" and "ristretto" technique to remove the curve's cofactor of 4. The upshot is that systems using the "decaf" interface will be using a prime-order group, which mitigates one of the few disadvantages of Edwards curves. However, this means that it is not able to implement systems which care about cofactor information.

The goal of this library is not only to follow best practices, but to make it easier for clients of the library to follow best practices. With a few well-marked exceptions, the functions in this library should be strongly constant-time: they do not allow secret data to flow to array indices, nor to control decisions except for a final failure check. Furthermore, the C++ wrapping uses RAII to automatically clear sensitive data, and has interfaces designed to prevent certain mistakes.

CFRG cryptosystems.

The library additionally supports the two cryptosystem defined by the Crypto Forum Research Group (CFRG): the X448 Diffie-Hellman functions (RFC 7748), and the EdDSA signature scheme (RFC 8032). Future versions might support additional operations on these curves, such as precomputed signature verification.

Symmetric crypto and hashing

The Goldilocks library doesn't implement much symmetric crypto, but it does contain the hash functions required by the CFRG cryptosystems: SHA-3 and SHAKE.

Internals

The "decaf" technique is described in https://eprint.iacr.org/2015/673 While the title of that paper is "removing cofactors through point compression", it might be more accurate to say "through quotients and isogenies". The internal representation of points is as "even" elements of a twisted Edwards curve with a=-1. Using this subgroup removes a factor of 2 from the cofactor. The remaining factor of 2 or 4 is removed with a quotient group: any two points which differ by an element of the 2- or 4-torsion subgroup are considered equal to each other.

When a point is written out to wire format, it is converted (by isogeny) to a Jacobi quartic curve, which is halfway between an Edwards curve and a Montgomery curve. One of the 4 or 8 equivalent points on the Jacobi quartic is chosen (it is "distinguished" according to certain criteria, such as having a positive x-coordinate). The x-coordinate of this point is written out. The y-coordinate is not written out, but the decoder knows which of the two possible y-coordinates is correct because of the distinguishing rules. See the paper for more details.

Licensing

See LICENSE.txt.

Caveats

As mentioned in the license, there is absolutely NO WARRANTY on any of this code. This code might well have security-critical bugs despite best efforts.

It has been attempted to protect against timing attacks and invalid point attacks, but as of yet there is no attempt to protect against power analysis.

libgoldilocks's People

Contributors

claucece avatar coruus avatar jeannotlapin avatar jmgurney avatar nwilson avatar olabini avatar potatosalad avatar

Stargazers

 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

libgoldilocks's Issues

`make test` fails due to overflow in conversion

Hello.

When I run make test, I get the following:

make test -f ./Makefile.custom                                                                                               
make[1]: Entering directory '/tmp/libgoldilocks'                                                                             
g++ -fno-strict-aliasing -pedantic -Wall -Wextra -Werror -Wunreachable-code -Wmissing-declarations -Wunused-function -Wno-overlength-strings -Isrc -Isrc/include -Isrc/public_include -Isrc/include/arch_x86_64 -Isrc/arch_x86_64 -Os -march=native -ffunction-sections -fdata-sections -fvisibility=hidden -fomit-frame-pointer -fPIC -c -o build/obj/test_goldilocks.o test/test_goldilocks.cxx                                                                              
In file included from src/public_include/goldilocks/point_448.h:16,                                                          
                 from src/public_include/goldilocks/point_448.hxx:33,                                                        
                 from src/public_include/goldilocks/ed448.hxx:22,                                                            
                 from src/public_include/goldilocks.hxx:16,                                                                  
                 from test/test_goldilocks.cxx:12:                                                                           
src/public_include/goldilocks/common.h: In function ‘goldilocks_bool_t goldilocks_successful(goldilocks_error_t)’:           
src/public_include/goldilocks/common.h:97:55: error: overflow in conversion from ‘goldilocks_word_t’ {aka ‘long unsigned int’} to ‘goldilocks_error_t’ changes value from ‘18446744073709551615’ to ‘GOLDILOCKS_SUCCESS’ [-Werror=overflow]                                                                                                                     
   97 |     goldilocks_dword_t w = ((goldilocks_word_t)e) ^  ((goldilocks_word_t)GOLDILOCKS_SUCCESS);                        
      |                                                      ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                         
cc1plus: all warnings being treated as errors                                                                                
make[1]: *** [Makefile.custom:168: build/obj/test_goldilocks.o] Error 1                                                      
make[1]: Leaving directory '/tmp/libgoldilocks'                                                                              
make: *** [Makefile:864: test] Error 2
diff --git a/src/public_include/goldilocks/common.h b/src/public_include/goldilocks/common.h
index 927369b..2bf3428 100644
--- a/src/public_include/goldilocks/common.h
+++ b/src/public_include/goldilocks/common.h
@@ -94,7 +94,7 @@ goldilocks_succeed_if(goldilocks_bool_t x) {
 /** Return GOLDILOCKS_TRUE iff x == GOLDILOCKS_SUCCESS */
 static GOLDILOCKS_INLINE goldilocks_bool_t
 goldilocks_successful(goldilocks_error_t e) {
-    goldilocks_dword_t w = ((goldilocks_word_t)e) ^  ((goldilocks_word_t)GOLDILOCKS_SUCCESS);
+    goldilocks_dword_t w = ((goldilocks_word_t)e) ^  GOLDILOCKS_SUCCESS;
     return (w-1)>>GOLDILOCKS_WORD_BITS;
 }

seems to suppress the error (warning) and the tests do pass. Thoughts?

Using commit c8d994098ff9094e3021f1a01e43faa3c6cf6fe4.

Fix "make test"

rc/GENERATED/include/decaf/point_448.hxx: In constructor ‘decaf::Ed448Goldilocks::Point::Point(const decaf::FixedBlock<56>&, bool)’:
../src/GENERATED/include/decaf/point_448.hxx:321:64: error: ?: using integer constants in boolean context [-Werror=int-in-bool-context]
if (GOLDILOCKS_SUCCESS != decode(buffer,allow_identity ? GOLDILOCKS_TRUE : GOLDILOCKS_FALSE)) {
~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

musl-gcc: `goldilocks_gen_tables` is not a statically linked executable when `--enable-static` and `--disable-shared` is passed to `./configure`

Hello.

Due to goldilocks_gen_tables being a dynamically linked executable, it cannot be executed when compiled with musl-gcc:

$ ./configure --enable-static --disable-shared CC=musl-gcc --host amd64 && make -j2

Result:

[...]
libtool: link: musl-gcc -std=c99 -fno-strict-aliasing -pedantic -Wall -Wextra -Werror -Wunreachable-code -Wmissing-declarations -Wunused-function -Wno-overlength-strings -I../src -I../src/include -I../src/public_include -I../src/arch_x86_64 -I../src/include/arch_x86_64 -O2 -maes -ffunction-sections -fdata-sections -fvisibility=hidden -fomit-frame-pointer -fPIC -g -O2 -o goldilocks_gen_tables goldilocks_gen_tables-utils.o goldilocks_gen_tables-goldilocks_gen_tables.o arch_x86_64/goldilocks_gen_tables-f_impl.o goldilocks_gen_tables-f_arithmetic.o goldilocks_gen_tables-f_generic.o goldilocks_gen_tables-goldilocks.o goldilocks_gen_tables-scalar.o 
./goldilocks_gen_tables > GEN/decaf_tables.c || (rm GEN/decaf_tables.c; exit 1)
/bin/sh: ./goldilocks_gen_tables: No such file or directory
make[2]: *** [Makefile:1078: GEN/decaf_tables.c] Error 1
make[2]: Leaving directory '/tmp/libgoldilocks/src'
make[1]: *** [Makefile:419: all-recursive] Error 1
make[1]: Leaving directory '/tmp/libgoldilocks'
make: *** [Makefile:350: all] Error 2

The solution is adding -static to create a statically linked executable instead of a dynamically linked one:

cd src && musl-gcc -static -std=c99 -fno-strict-aliasing -pedantic -Wall -Wextra -Werror -Wunreachable-code -Wmissing-declarations -Wunused-function -Wno-overlength-strings -I../src -I../src/include -I../src/public_include -I../src/arch_x86_64 -I../src/include/arch_x86_64 -O2 -maes -ffunction-sections -fdata-sections -fvisibility=hidden -fomit-frame-pointer -fPIC -g -O2 -o goldilocks_gen_tables goldilocks_gen_tables-utils.o goldilocks_gen_tables-goldilocks_gen_tables.o arch_x86_64/goldilocks_gen_tables-f_impl.o goldilocks_gen_tables-f_arithmetic.o goldilocks_gen_tables-f_generic.o goldilocks_gen_tables-goldilocks.o goldilocks_gen_tables-scalar.o

It seems to be the case that if we append -static, everything seems to work, the executable can be executed (it cannot if we omit -static, ldd shows invalid ELF header), and all tests pass.

The issue arises only when CC is set to musl-gcc. It works with gcc.

I apologize for the long title, I could not come up with a shorter one that summarizes the issue. :/

Remove code generation

No point in having it, now that we only have one field and curve. And removing it removes a bunch of complexity.

[FYI] make test fails with gcc 9

Hi, I just noticed that building from git master (6b7851c) throws an error in make test on my Arch Linux box. On another machine running Ubuntu 16.04 LTS it builds fine. So I assume the gcc 9 version from Arch Linux is responsible here.

OS: Arch Linux
$ pacman -Q gcc
gcc 9.2.0-4

Build snippet:

...
gcc -std=c99 -fno-strict-aliasing -pedantic -Wall -Wextra -Werror -Wunreachable-code -Wmissing-declarations -Wunused-function -Wno-overlength-strings   -Isrc -Isrc/include -Isrc/public_include -Isrc/include/arch_x86_64 -Isrc/arch_x86_64 -Os -march=native  -ffunction-sections -fdata-sections -fvisibility=hidden -fomit-frame-pointer -fPIC  -c -o build/obj/f_generic.o src/f_generic.c
In file included from src/public_include/goldilocks/point_448.h:16,
                 from src/public_include/goldilocks/point_448.hxx:33,
                 from src/public_include/goldilocks/ed448.hxx:22,
                 from src/public_include/goldilocks.hxx:16,
                 from test/test_goldilocks.cxx:12:
src/public_include/goldilocks/common.h: In function ‘goldilocks_bool_t goldilocks_successful(goldilocks_error_t)’:
src/public_include/goldilocks/common.h:97:55: error: overflow in conversion from ‘goldilocks_word_t’ {aka ‘long unsigned int’} to ‘goldilocks_error_t’ changes value from ‘18446744073709551615’ to ‘GOLDILOCKS_SUCCESS’ [-Werror=overflow]
   97 |     goldilocks_dword_t w = ((goldilocks_word_t)e) ^  ((goldilocks_word_t)GOLDILOCKS_SUCCESS);
      |                                                      ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1plus: all warnings being treated as errors
make[1]: *** [Makefile.custom:168: build/obj/test_goldilocks.o] Error 1

Regards

Failing to build from git master on Arch Linux

Hi, after noticing recent commit activity I held back reporting broken build failures on Arch Linux for a while, assuming things would sort themselves out. Today I tried another build from latest git at commit d07cb5b. Here are my observations:

...
./goldilocks_gen_tables > GEN/goldilocks_tables.c || (rm GEN/goldilocks_tables.c; exit 1)
/bin/sh: line 1: 104188 Illegal instruction     (core dumped) ./goldilocks_gen_tables > GEN/goldilocks_tables.c
make[2]: *** [Makefile:1333: GEN/goldilocks_tables.c] Error 1
make[2]: Leaving directory '/home/glitsj16/libgoldilocks/src'
make[1]: *** [Makefile:420: all-recursive] Error 1
make[1]: Leaving directory '/home/glitsj16/libgoldilocks'
make: *** [Makefile:351: all] Error 2

OS: Arch Linux

$ pacman -Q gcc make
gcc 9.3.0-1
make 4.3-1

Full build log: https://gist.github.com/glitsj16/67836b5e1c7aac97deeff161500d40c3

Check imagine twist on point_eq

On decaf.c, there seems to be an unreachable case regarding the Imagine Twist flag. This might be something to change on libdecaf too.

Should be reported to Mike Hamburg

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.