I found a Curve25519 implementation on the net and created a ".lib" (x86, '_stdcall') out of it.
There is also a x64 implementation in the original sources, see (http://github.com/agl/curve25519-donna) for that.
For those who don't know what 'Curve25519' is - here's a link to the authors page.
I have coded a little example using the .lib:
Code: Select all
;+++++++++++++++++++++++++++++++++++++++++++++++
;| Demonstration of the 'curve25519' algorithm |
;+++++++++++++++++++++++++++++++++++++++++++++++
;
; Demo:
; PureBasic demonstration code by javabean (2010)
; PureBasic 4.40 (x86) for Windows
;---
; Library source:
; Source code for 'curve25519_donna.lib' taken from the
; C language implementation of 'Donna' (curve25519_donna.c)
; (http://github.com/agl/curve25519-donna)
;---
; Library build:
; 'curve25519_donna.lib' built with 'PellesC for Windows 4.50.113'
; Additional objectfiles (exploded from 'crt.lib' using POLIB):
;_llmul.obj, _lldiv.obj, _llshr.obj, _llshl.obj
;---
; Original 'Curve25519' algorithm by D. J. Bernstein (Public domain).
; (http://cr.yp.to/ecdh.html)
;++++++++++++++++++++++++++++++++++++++++++++++++
Import "curve25519_donna.lib"; '_stdcall'
curve(*output, *secret, *basepoint) As "_curve25519_donna@12"
EndImport
*mysecret = AllocateMemory(32)
For i=0 To 31 : PokeA(*mysecret+i,42) : Next
PokeA(*mysecret+0, PeekA(*mysecret+0) & 248)
PokeA(*mysecret+31, PeekA(*mysecret+31) & 127)
PokeA(*mysecret+31, PeekA(*mysecret+31) | 64)
*mypublic = AllocateMemory(32)
*basepoint = AllocateMemory(32)
PokeA(*basepoint+0, 9)
;-----
*hissecret = AllocateMemory(32)
For i=0 To 31 : PokeA(*hissecret+i,11) : Next
PokeA(*hissecret+0, PeekA(*hissecret+0) & 248)
PokeA(*hissecret+31, PeekA(*hissecret+31) & 127)
PokeA(*hissecret+31, PeekA(*hissecret+31) | 64)
*hispublic = AllocateMemory(32)
;---
*myshared = AllocateMemory(32)
*hisshared = AllocateMemory(32)
OpenConsole()
ConsoleTitle("Curve25519 Test")
str$="": For i=0 To 31: str$+RSet(Hex(PeekA(*mysecret+i),#PB_Byte),2,"0"): Next : PrintN("mysecret : "+str$)
str$="": For i=0 To 31: str$+RSet(Hex(PeekA(*basepoint+i),#PB_Byte),2,"0"): Next : PrintN("basepoint: "+str$)
curve(*mypublic, *mysecret, *basepoint)
str$="": For i=0 To 31: str$+RSet(Hex(PeekA(*mypublic+i),#PB_Byte),2,"0"): Next : PrintN("mypublic : "+str$)
PrintN("")
str$="": For i=0 To 31: str$+RSet(Hex(PeekA(*hissecret+i),#PB_Byte),2,"0"): Next : PrintN("hissecret: "+str$)
str$="": For i=0 To 31: str$+RSet(Hex(PeekA(*basepoint+i),#PB_Byte),2,"0"): Next : PrintN("basepoint: "+str$)
curve(*hispublic, *hissecret, *basepoint)
str$="": For i=0 To 31: str$+RSet(Hex(PeekA(*hispublic+i),#PB_Byte),2,"0"): Next : PrintN("hispublic: "+str$)
PrintN("")
curve(*myshared, *mysecret, *hispublic)
curve(*hisshared, *hissecret, *mypublic)
str_myshared$="": For i=0 To 31: str_myshared$+RSet(Hex(PeekA(*myshared+i),#PB_Byte),2,"0"): Next : PrintN("myshared : "+str_myshared$)
str_hisshared$="": For i=0 To 31: str_hisshared$+RSet(Hex(PeekA(*hisshared+i),#PB_Byte),2,"0"): Next : PrintN("hisshared: "+str_hisshared$)
PrintN("")
If str_myshared$ = str_hisshared$
PrintN("myshared = hisshared")
Else
PrintN("myshared <> hisshared")
EndIf
PrintN("")
PrintN("")
PrintN("PRESS 'RETURN' TO QUIT.")
Input()
CloseConsole()
Cheers,
javabean
Edit: [21.02.2010]: Changed "ImportC" to "Import" (_stdcall)