Skip to content

Commit 3e45a1f

Browse files
committed
Initial version.
0 parents  commit 3e45a1f

27 files changed

Lines changed: 2297 additions & 0 deletions

.gitignore

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/aclocal.m4
2+
/autom4te.cache/
3+
/compile
4+
/config.guess
5+
/config.log
6+
/config.status
7+
/config.sub
8+
/configure
9+
/depcomp
10+
/include/config.h
11+
/include/config.h.in
12+
/include/stamp-h1
13+
/install-sh
14+
/libcurvecpr.pc
15+
/libtool
16+
/ltmain.sh
17+
/m4/libtool.m4
18+
/m4/ltoptions.m4
19+
/m4/ltsugar.m4
20+
/m4/ltversion.m4
21+
/m4/lt~obsolete.m4
22+
/missing
23+
/t/test_*
24+
!/t/test_*.*
25+
26+
.deps/
27+
.dirstamp
28+
.libs/
29+
Makefile
30+
Makefile.in
31+
*~
32+
*.Plo
33+
*.la
34+
*.lai
35+
*.lo
36+
*.o

Makefile.am

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
ACLOCAL_AMFLAGS = -I m4
2+
3+
LIBCURVECPR_API_VERSION = 1:0:0
4+
5+
lib_LTLIBRARIES = libcurvecpr.la
6+
7+
libcurvecpr_la_CPPFLAGS = -I$(top_srcdir)/include
8+
libcurvecpr_la_CFLAGS = \
9+
-Wall -W -Wcast-qual -Wcast-align -Winline -Wmissing-prototypes -Wwrite-strings \
10+
-Wredundant-decls -Wpointer-arith -Wchar-subscripts -Wshadow -Wstrict-prototypes -Werror
11+
libcurvecpr_la_LDFLAGS = -version-info $(LIBCURVECPR_API_VERSION)
12+
13+
AUTOMAKE_OPTIONS = subdir-objects
14+
libcurvecpr_la_SOURCES = \
15+
lib/bytes.c \
16+
lib/chicago.c \
17+
lib/client.c \
18+
lib/client_recv.c \
19+
lib/client_send.c \
20+
lib/messager.c \
21+
lib/server.c \
22+
lib/server_recv.c \
23+
lib/server_send.c \
24+
lib/session.c \
25+
lib/util.c
26+
27+
curvecprincludedir = $(includedir)/curvecpr
28+
curvecprinclude_HEADERS = \
29+
include/block.h \
30+
include/bytes.h \
31+
include/chicago.h \
32+
include/client.h \
33+
include/messager.h \
34+
include/packet.h \
35+
include/server.h \
36+
include/session.h \
37+
include/util.h
38+
39+
check_PROGRAMS =
40+
41+
check_PROGRAMS += t/test_messager
42+
t_test_messager_SOURCES = t/test_messager.c
43+
t_test_messager_CPPFLAGS = -I$(top_srcdir)/include
44+
t_test_messager_CFLAGS = @CHECK_CFLAGS@
45+
t_test_messager_LDADD = $(top_builddir)/libcurvecpr.la @CHECK_LIBS@
46+
47+
TESTS = $(check_PROGRAMS)
48+
49+
pkgconfigdir = $(libdir)/pkgconfig
50+
pkgconfig_DATA = libcurvecpr.pc

README.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# libcurvecpr
2+
3+
libcurvecpr is a low-level, networking-independent implementation of Daniel J. Bernstein's [CurveCP](http://curvecp.org/).
4+
5+
## How does it work?
6+
7+
libcurvecpr is based on a system of callbacks that must be implemented by library users. Like the reference CurveCP implementation, the client, server, and message-handling portions of libcurvecpr are entirely independent of each other.
8+
9+
This means that while it's slightly more effort to build software based on libcurvecpr than other packages, it provides complete freedom to use any underlying mechanism for handling network traffic you want—whether it's an IPC connection to another program, standard `poll(2)`-type functionality, or [libev](http://software.schmorp.de/pkg/libev.html).
10+
11+
## Can I see an example?
12+
13+
Here's how one might implement sending an encrypted message using `sendto(2)`:
14+
15+
```c
16+
struct cl_priv {
17+
struct sockaddr_storage dest;
18+
socklen_t dest_len;
19+
int s;
20+
};
21+
22+
static int cl_send (struct curvecpr_client *client, const unsigned char *buf, size_t num)
23+
{
24+
struct cl_priv *priv = (struct cl_priv *)client->cf.priv;
25+
if (sendto(priv->s, buf, num, 0, (struct sockaddr *)&priv->dest, priv->dest_len) != num)
26+
return -1;
27+
28+
return 0;
29+
}
30+
31+
struct curvecpr_client_cf cl_cf = {
32+
.ops = {
33+
.send = cl_send,
34+
/* ... */
35+
}
36+
};
37+
38+
int main (void)
39+
{
40+
struct curvecpr_client cl;
41+
struct cl_priv cl_priv = /* ... */;
42+
43+
cl_cf.priv = &cl_priv;
44+
45+
curvecpr_client_new(&cl, &cl_cf);
46+
curvecpr_client_connected(&cl);
47+
48+
curvecpr_client_send(&cl, "Hello,ThisIsDog", 16);
49+
}
50+
```
51+
52+
## What makes it different from the reference implementation?
53+
54+
The reference implementation is intended to be used as standalone programs. Additionally, the reference implementation source code is extremely difficult to understand.
55+
56+
libcurvecpr is a library proper: for instance, to send a message, you use one of the `curvecpr_client_send` or `curvecpr_server_send` functions, or a callback (depending on how you're sending the message).
57+
58+
## Has this been audited by anyone?
59+
60+
No. I don't claim to be a security or cryptography expert in any senses of the terms. I am inviting experts in these fields to review the source code and provide feedback as I believe it will be beneficial to the global computer security community.
61+
62+
## Where's the documentation?
63+
64+
It's coming.
65+
66+
## Is it fast?
67+
68+
It's a little slower than the reference implementation. That said, all of the quirks of the congestion control algorithm haven't been worked out yet.
69+
70+
## How is libcurvecpr licensed?
71+
72+
Like the [NaCl](http://nacl.cr.yp.to/) library on which it is based, libcurvecpr is released to the public domain. Should there be any confusion about the meaning of this statement, please consult [this document](http://creativecommons.org/publicdomain/zero/1.0/).

autogen.sh

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#! /bin/sh
2+
3+
PROGRAM="libcurvecpr"
4+
5+
SCRIPT=$( basename $0 )
6+
ERROR=0
7+
8+
error() {
9+
MESSAGE=$1
10+
echo "error: ${MESSAGE}"
11+
12+
ERROR=1
13+
}
14+
15+
hint() {
16+
MESSAGE=$1
17+
echo "hint: ${MESSAGE}"
18+
}
19+
20+
status() {
21+
MESSAGE=$1
22+
echo "${SCRIPT}: ${MESSAGE}"
23+
}
24+
25+
die_if_error() {
26+
if [ $ERROR -ne 0 ]; then
27+
exit 1
28+
fi
29+
}
30+
31+
( autoconf --version >/dev/null 2>&1 ) || {
32+
error "The \`autoconf\` program must be installed to compile ${PROGRAM}."
33+
}
34+
35+
( automake --version >/dev/null 2>&1 ) || {
36+
error "The \`automake\` program must be installed to compile ${PROGRAM}."
37+
}
38+
39+
( aclocal --version >/dev/null 2>&1 ) || {
40+
error "The \`aclocal\` program must be installed to compile ${PROGRAM}."
41+
hint "\`aclocal\` is usually provided by \`automake\`. Is your version of \`automake\`"
42+
hint "up to date?"
43+
}
44+
45+
( libtool --version >/dev/null 2>&1 ) || {
46+
error "The \`libtool\` program must be installed to compile ${PROGRAM}."
47+
}
48+
49+
( libtoolize --version >/dev/null 2>&1 ) || {
50+
error "The \`libtoolize\` program must be installed to compile ${PROGRAM}."
51+
hint "\`libtoolize\` is usually provided by \`libtool\`. Is your version of \`libtool\`"
52+
hint "up to date?"
53+
}
54+
55+
( pkg-config --version >/dev/null 2>&1 ) || {
56+
error "The \`pkg-config\` program must be installed to compile ${PROGRAM}."
57+
}
58+
59+
die_if_error
60+
61+
status "Running libtoolize"
62+
( libtoolize --force --copy ) || {
63+
error "libtoolize failed"
64+
exit 1
65+
}
66+
67+
status "Running aclocal"
68+
( aclocal ) || {
69+
error "aclocal failed"
70+
exit 1
71+
}
72+
73+
status "Running autoheader"
74+
( autoheader ) || {
75+
error "autoheader failed"
76+
exit 1
77+
}
78+
79+
status "Running automake"
80+
( automake --add-missing ) || {
81+
error "automake failed"
82+
exit 1
83+
}
84+
85+
status "Running autoconf"
86+
( autoconf ) || {
87+
error "autoconf failed"
88+
exit 1
89+
}

configure.ac

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
AC_PREREQ(2.67)
2+
AC_INIT(libcurvecpr, 0.1.0, nfontes+libcurvecpr@cynigram.com, libcurvecpr)
3+
AM_INIT_AUTOMAKE([-Wall -Werror foreign])
4+
5+
AC_CONFIG_SRCDIR([include/server.h])
6+
AC_CONFIG_HEADER([include/config.h])
7+
AC_CONFIG_MACRO_DIR([m4])
8+
9+
# Checks for programs.
10+
AC_PROG_CC
11+
AC_PROG_CPP
12+
AC_PROG_INSTALL
13+
AC_PROG_LIBTOOL
14+
AC_PROG_LN_S
15+
AC_PROG_MAKE_SET
16+
17+
AM_PROG_CC_C_O
18+
19+
# Checks for libraries.
20+
PKG_CHECK_MODULES([CHECK], [check >= 0.9.8])
21+
AC_SEARCH_LIBS([clock_gettime], [rt posix4])
22+
AC_CHECK_LIB([sodium], [crypto_onetimeauth_poly1305_ref], [], [AC_MSG_ERROR([missing libsodium])])
23+
24+
# Checks for header files.
25+
AC_HEADER_STDC
26+
AC_CHECK_HEADERS([errno.h stdint.h string.h time.h], [], [AC_MSG_ERROR([missing required header file(s)])])
27+
28+
# Checks for typedefs, structures, and compiler characteristics.
29+
AC_C_CONST
30+
AC_C_INLINE
31+
AC_TYPE_SIZE_T
32+
AC_TYPE_SSIZE_T
33+
AC_TYPE_UINT8_T
34+
AC_TYPE_UINT16_T
35+
AC_TYPE_UINT32_T
36+
AC_CHECK_TYPE([struct timespec], [], [AC_MSG_ERROR([missing struct timespec])], [[#include <time.h>]])
37+
38+
# Checks for functions.
39+
AC_CHECK_FUNCS([clock_gettime], [], [AC_MSG_ERROR([missing clock_gettime])])
40+
41+
# Done!
42+
AC_CONFIG_FILES([Makefile libcurvecpr.pc])
43+
AC_OUTPUT

include/block.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#ifndef __CURVECPR_BLOCK_H
2+
#define __CURVECPR_BLOCK_H
3+
4+
#include <string.h>
5+
6+
#include <sodium/crypto_uint32.h>
7+
#include <sodium/crypto_uint64.h>
8+
9+
struct curvecpr_block {
10+
/* This message's ID. */
11+
crypto_uint32 id;
12+
13+
/* When this message was actually sent/received. (0 means not sent.) */
14+
long long clock;
15+
16+
/* The position of this block in the stream. */
17+
crypto_uint64 offset;
18+
19+
/* Is this block an EOF indicator? */
20+
enum {
21+
CURVECPR_BLOCK_STREAM,
22+
CURVECPR_BLOCK_EOF_FAILURE,
23+
CURVECPR_BLOCK_EOF_SUCCESS
24+
} eof;
25+
26+
/* The actual data. */
27+
size_t data_len;
28+
unsigned char data[1024];
29+
};
30+
31+
#endif

include/bytes.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef __LIBCURVECPR_BYTES_H
2+
#define __LIBCURVECPR_BYTES_H
3+
4+
#include <string.h>
5+
6+
#include <sodium/crypto_uint16.h>
7+
#include <sodium/crypto_uint32.h>
8+
#include <sodium/crypto_uint64.h>
9+
10+
void curvecpr_bytes_copy (void *destination, const void *source, size_t num);
11+
void curvecpr_bytes_zero (void *destination, size_t num);
12+
int curvecpr_bytes_equal (const void *ptr1, const void *ptr2, size_t num);
13+
14+
void curvecpr_bytes_pack_uint16 (unsigned char *destination, crypto_uint16 source);
15+
crypto_uint16 curvecpr_bytes_unpack_uint16 (const unsigned char *source);
16+
void curvecpr_bytes_pack_uint32 (unsigned char *destination, crypto_uint32 source);
17+
crypto_uint32 curvecpr_bytes_unpack_uint32 (const unsigned char *source);
18+
void curvecpr_bytes_pack_uint64 (unsigned char *destination, crypto_uint64 source);
19+
crypto_uint64 curvecpr_bytes_unpack_uint64 (const unsigned char *source);
20+
21+
#endif

include/chicago.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#ifndef __CURVECPR_CHICAGO_H
2+
#define __CURVECPR_CHICAGO_H
3+
4+
struct curvecpr_chicago {
5+
long long clock;
6+
7+
long long rtt_latest;
8+
long long rtt_average;
9+
long long rtt_deviation;
10+
long long rtt_highwater;
11+
long long rtt_lowwater;
12+
long long rtt_timeout;
13+
14+
unsigned char seen_recent_high;
15+
unsigned char seen_recent_low;
16+
unsigned char seen_older_high;
17+
unsigned char seen_older_low;
18+
19+
unsigned char rtt_phase;
20+
21+
long long wr_rate;
22+
23+
long long ns_last_update;
24+
long long ns_last_edge;
25+
long long ns_last_doubling;
26+
long long ns_last_panic;
27+
};
28+
29+
void curvecpr_chicago_new (struct curvecpr_chicago *chicago);
30+
void curvecpr_chicago_refresh_clock (struct curvecpr_chicago *chicago);
31+
void curvecpr_chicago_on_timeout (struct curvecpr_chicago *chicago);
32+
void curvecpr_chicago_on_recv (struct curvecpr_chicago *chicago, long long ns_sent);
33+
34+
#endif

0 commit comments

Comments
 (0)