-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
66 changed files
with
63,550 additions
and
48 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
|
||
=============== | ||
Botan Interface | ||
=============== | ||
|
||
|
||
|
||
|
||
|
||
Random number generators. | ||
========================= | ||
|
||
|
||
.. code-block:: felix | ||
library Botan { class Rng | ||
{ | ||
requires package "botan_rng", package "botan_system_rng"; | ||
type RandomNumberGenerator = "Botan::RandomNumberGenerator*"; | ||
fun System_RNG: 1 -> RandomNumberGenerator = "new Botan::System_RNG()"; | ||
proc add_entropy: RandomNumberGenerator * +byte * size = "$1->add_entropy($2,$3);"; | ||
proc randomize_with_input: | ||
RandomNumberGenerator * +byte * size * +byte * size= | ||
"$1->add_entropy($2,$3,$4,$5);" | ||
; | ||
proc randomize_with_ts_input: RandomNumberGenerator * +byte * size = | ||
"$1->randomize_with_ts_input($2,$3);" | ||
; | ||
proc randomize: RandomNumberGenerator * +byte * size = | ||
"$1->randomize_with_input($2,$3);" | ||
; | ||
}} | ||
@ | ||
Big Integers | ||
============ | ||
|
||
|
||
.. code-block:: felix | ||
library Botan { class BigInt | ||
{ | ||
requires package "botan_bigint"; | ||
type bigint = "Botan::BigInt"; | ||
body strbigint = """ | ||
static ::std::string strbigint (Botan::BigInt const &pi) { | ||
::std::stringstream s; | ||
s << pi; | ||
return s.str(); | ||
} | ||
"""; | ||
ctor bigint : string = "Botan::BigInt ($1)"; | ||
instance Forward[bigint] { | ||
fun succ: bigint -> bigint = "$1+Botan::BigInt(1)"; | ||
proc pre_incr: &bigint = "$1->operator++();"; | ||
proc post_incr: &bigint = "$1->operator++();"; | ||
} | ||
instance Bidirectional[bigint] { | ||
fun pred: bigint -> bigint = "$1-Botan::BigInt(1)"; | ||
proc pre_decr: &bigint = "$1->operator--();"; | ||
proc post_decr: &bigint = "$1->operator--();"; | ||
} | ||
instance FloatAddgrp[bigint] { | ||
fun zero: 1 -> bigint = "Botan::Bigint(0)"; | ||
fun neg: bigint -> bigint = "-$1"; | ||
proc += : &bigint * bigint = "$1->operator+= ($2);"; | ||
proc -= : &bigint * bigint = "$1->operator-=($2);"; | ||
fun + : bigint * bigint -> bigint = "$1+$2"; | ||
fun - : bigint * bigint -> bigint = "$1-$2"; | ||
} | ||
instance FloatMultSemi1[bigint] { | ||
fun one : 1 -> bigint = "Botan::BigInt(1)"; | ||
fun * : bigint * bigint -> bigint = "$1*$2"; | ||
proc *= : &bigint * bigint = "$1->operator*=($2);"; | ||
} | ||
instance FloatDring[bigint] { | ||
fun / : bigint * bigint -> bigint = "$1/$2"; | ||
fun % : bigint * bigint -> bigint = "$1%$2"; | ||
proc /= : &bigint * bigint = "$1->operator/=($2);"; | ||
proc %= : &bigint * bigint = "$1->operator%=($2);"; | ||
} | ||
instance Integer[bigint] { | ||
body bigintshl = """ | ||
// throws if right argument abs value is too big | ||
static Botan::BigInt shl(Botan::BigInt const &l, Botan::BigInt r) { | ||
if (r.is_negative()) { | ||
r = -r; | ||
::std::size_t rr = r.to_u32bit(); | ||
return l >> rr; | ||
} else { | ||
::std::size_t rr = r.to_u32bit(); | ||
return l << rr; | ||
} | ||
} | ||
"""; | ||
fun << : bigint * bigint -> bigint = "bigint_shl($1,$2)" requires bigintshl; | ||
fun >> : bigint * bigint -> bigint = "bigint_shl($1,-$2)" requires bigintshl; | ||
} | ||
instance Signed_integer[bigint] { | ||
fun abs: bigint -> bigint = "$1.abs()"; | ||
fun sgn: bigint -> int = "$1.is_zero()? 0 : ($1.is_positive() ? 1 : -1)"; | ||
} | ||
inherit Signed_integer[bigint]; | ||
instance Eq[bigint] { | ||
fun == : bigint * bigint -> bool = "$1==$2"; | ||
} | ||
instance Tord[bigint] { | ||
fun < : bigint * bigint -> bool = "$1<$2"; | ||
fun <= : bigint * bigint -> bool = "$1<=$2"; | ||
fun > : bigint * bigint -> bool = "$1>$2"; | ||
fun >= : bigint * bigint -> bool = "$1>=$2"; | ||
} | ||
inherit Tord[bigint]; // includes Eq | ||
instance Str[bigint] { | ||
fun str: bigint -> string = "strbigint($1)" requires strbigint; | ||
} | ||
fun gcd: bigint * bigint -> bigint = "Botan::gcd($1,$2)"; | ||
fun lcm: bigint * bigint -> bigint = "Botan::lcm($1,$2)"; | ||
fun jacobi: bigint * bigint -> bigint = "Botan::jacobi($1,$2)"; | ||
// b^x % m | ||
fun power_mod: bigint * bigint * bigint -> bigint = "Botan::power_mod($1,$2,$3)"; | ||
}} | ||
@ | ||
Hash functions | ||
============== | ||
|
||
|
||
.. code-block:: felix | ||
library Botan { class Hash { | ||
type BufferedComputation = "::Botan::BufferedComputation*"; | ||
fun output_length : BufferedComputation -> size = "$1->output_length()"; | ||
proc update : BufferedComputation * +byte * size = "$1->update($2,$3);"; | ||
proc update : BufferedComputation * byte = "$1->update($2);"; | ||
proc final: BufferedComputation * +byte = "$1->final($2);"; | ||
}} | ||
@ | ||
.. code-block:: text | ||
.. code-block:: text | ||
Name: botan | ||
Platform: Unix | ||
Description: Botan Crypto Library | ||
provides_dlib: -L/usr/local/lib -lbotan-2 | ||
provides_slib: -L/usr/local/lib -lbotan-2 | ||
cflags: -I/usr/local/include/botan-2.0 | ||
@ | ||
.. code-block:: text | ||
Requires: botan | ||
includes: '"botan/rng.h"' | ||
cflags: -I/usr/local/include/botan-2.0 | ||
@ | ||
.. code-block:: text | ||
Requires: botan | ||
includes: '"botan/system_rng.h"' | ||
cflags: -I/usr/local/include/botan-2.0 | ||
@ | ||
.. code-block:: text | ||
Requires: botan | ||
includes: '"botan/bigint.h"' '"botan/numthry.h"' | ||
cflags: -I/usr/local/include/botan-2.0 | ||
@ | ||
Oops, something went wrong.