Skip to content

Commit

Permalink
update demo
Browse files Browse the repository at this point in the history
  • Loading branch information
mjfh committed May 12, 2017
1 parent a1589cf commit b0094ce
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 34 deletions.
4 changes: 2 additions & 2 deletions Makefile.simple
@@ -1,6 +1,6 @@
#!/usr/bin/make -f

default help debug release clean distclean:
default help debug release clean distclean mingw mingw-release mingw-debug:
$(MAKE) -C src -f Makefile.simple $@

# End
# End
23 changes: 14 additions & 9 deletions README.md
Expand Up @@ -43,9 +43,14 @@ decryption and further processing.
Download/clone *nim-crypto* and enter the root directory. Then type

make -f Makefile.simple
This will produce a binary command file *src/cwrap* which can
be run as

or

make -f Makefile.simple mingw

where the latter one might be needed on a Windows/MinGW set up.
This will produce a binary command file *src/cwrap* which can
be run as

./src/cwrap
Expand Down Expand Up @@ -100,21 +105,21 @@ be available by default.

## Bootstrapping

Download/clone the *nim-crypto* repository from GitHUB and enter its root
Download/clone the *nim-crypto* project from GitHUB and enter its root
directory. All bootstrapping commands are bundled into a single *make*
command script called *Build*. It is accessible in the root
command script called *Build*. It is accessible in the project root
directory. A help page is printed if called without arguments as in

./Build

This command script expects the *make* command installed as
*/usr/bin/make*. You need to edit the first line of this script
accordingly if this is not the case.
This command script expects the *make* command installed as */usr/bin/make*.
You need to edit the first line of this script accordingly if this is not
the case (or run it as *"make -f Build <args..>"* instead).

#### Optional: Local NIM Installation

Unless a *NIM* compiler is installed, it can be done locally within
the *nim-crypto* repository with the command:
the *nim-crypto* progect tree with the command:

./Build nim
Expand Down
57 changes: 37 additions & 20 deletions src/Makefile.simple
Expand Up @@ -5,24 +5,26 @@
# Simple Makefile example, works on Linux
#

MAKEFILE = Makefile.simple
ROOTDIR = lib
TARGET = cwrap
LIBS = -ldl -lm
MAKEFILE = Makefile.simple
ROOTDIR = lib
TARGET = cwrap
LIBS = -ldl

NIMLIB = `nim dump 2>&1 >/dev/null|sed '$$!d'`
INCLUDES = -Inimcache -I$(NIMLIB)
CFLAGS = $(INCLUDES) $(CDEBUG)
NIMFLAGS = -p:$(ROOTDIR) --app:staticLib --noMain --header
NIMFLAGS += -d:ignNimPaths $(NIMDBG)
NIMLIB = `nim dump 2>&1 >/dev/null|sed '$$!d'`
INCLUDES = -Inimcache -I$(NIMLIB)
NIMFLAGS = -p:$(ROOTDIR) --app:staticLib --noMain --header
NIMFLAGS += -d:ignNimPaths $(NIMDBG)

MAIN_CFLAGS = $(CFLAGS) $(INCLUDES) $(CDEBUG)
MAIN_LIBS = -L. -lsession $(LIBS) -lm

# Settings for optimised code
REL_CDEBUG = -O2 -s
REL_NIMDBG = -d:release --gc:none
REL_CDEBUG = -O2 -s
REL_NIMDBG = -d:release --gc:none

# Settings for GDB debugging session
DBG_CDEBUG = -g
DBG_NIMDBG = --debuginfo --lineDir:on --embedsrc --debugger=native
DBG_CDEBUG = -g
DBG_NIMDBG = --debuginfo --lineDir:on --embedsrc --debugger=native

# ---------------------------------------------------------------------------
# Convenience targets
Expand All @@ -32,18 +34,32 @@ DBG_NIMDBG = --debuginfo --lineDir:on --embedsrc --debugger=native
CDEBUG = $(REL_CDEBUG)
NIMDBG = $(REL_NIMDBG)

.PHONY: default debug release help

.PHONY: default help
default: $(TARGET)

help:
@echo
@echo '$(MAKE) -f $(MAKEFILE) [target]'
@echo
@echo 'target: default -- release (unless done already)'
@echo ' | debug -- force rebuild'
@echo ' | release -- force rebuild'
@echo 'target: default -- release (unless done already)'
@echo " | mingw -- like 'default' on Windiws/MinGW"
@echo ' | debug -- force rebuild'
@echo ' | release -- force rebuild'
@echo ' | [dist]clean'
@echo
@echo "Note: The debug/release targets might be prefixed by 'mingw-'."
@echo

.PHONY: mingw mingw-release mingw-debug debug release
mingw:
$(MAKE) -f $(MAKEFILE) CC=gcc LIBS= default

mingw-release:
$(MAKE) -f $(MAKEFILE) CC=gcc LIBS= release

mingw-debug:
$(MAKE) -f $(MAKEFILE) CC=gcc LIBS= debug

debug:
@rm -f $(TARGET)
Expand All @@ -57,12 +73,13 @@ release:
# BUILD recipe
# ---------------------------------------------------------------------------

$(TARGET): main.o libsession.a
$(CC) -o $@ $(CFLAGS) main.c libsession.a $(LIBS)
$(TARGET): main.o
$(CC) -o $@ $(MAIN_CFLAGS) main.o $(MAIN_LIBS)

main.o: main.c nimcache/session.h
$(CC) -c -o $@ $(MAIN_CFLAGS) main.c

libsession.a nimcache/session.h: session.nim
nimcache/session.h: session.nim
nim cc $(NIMFLAGS) session.nim

# ---------------------------------------------------------------------------
Expand Down
4 changes: 1 addition & 3 deletions src/lib/xcrypt.nim
Expand Up @@ -246,11 +246,9 @@ proc startXDecrypt(ctx: var XCryptCtx;
for n in 0..<xdt.key.len:
if xdt.key[n] == zero: # ignore zero key slot
continue
var
kPtr = cast[ptr ChaChaKey](addr xdt.key[n])
line = hdr[(4 * InLinelen) .. <(5 * InLinelen)]

# decrypt challenge with current key
var kPtr = cast[ptr ChaChaKey](addr xdt.key[n])
getChaCha(ctx.ccc, kPtr, nPtr) # try key for decryption
chachaAnyCrypt(ctx.ccc, addr xdt.oLine, # decrypt line
unsafeAddr hdr[4 * InLinelen], InLinelen)
Expand Down

0 comments on commit b0094ce

Please sign in to comment.