2014-04-18 02:34:25 +04:00
|
|
|
\chapter{Cryptol primitive functions}
|
|
|
|
|
|
|
|
\commentout{
|
|
|
|
\begin{code}
|
|
|
|
primsPlaceHolder=1;
|
|
|
|
\end{code}
|
|
|
|
}
|
|
|
|
|
|
|
|
\paragraph*{Bitwise operations}
|
|
|
|
\begin{Verbatim}
|
|
|
|
&&, ||, ^ : {a} a -> a -> a
|
|
|
|
~ : {a} a -> a
|
|
|
|
\end{Verbatim}
|
|
|
|
\paragraph*{Comparisons}
|
|
|
|
\begin{Verbatim}
|
|
|
|
==, != : {a} (Cmp a) => a -> a -> Bit
|
2016-08-04 02:18:31 +03:00
|
|
|
<, >, <=, >= : {a} (Cmp a) => a -> a -> Bit
|
2014-04-18 02:34:25 +04:00
|
|
|
\end{Verbatim}
|
|
|
|
\paragraph*{Arithmetic}
|
|
|
|
\begin{Verbatim}
|
|
|
|
+, -, *, /, %, ** : {a} (Arith a) => a -> a -> a
|
2016-08-04 02:18:31 +03:00
|
|
|
lg2 : {a} (Arith a) => a -> a
|
2014-04-18 02:34:25 +04:00
|
|
|
\end{Verbatim}
|
|
|
|
% negate : {a b} (a >= 1) => [a]b -> [a]b
|
|
|
|
\paragraph*{Polynomial arithmetic}
|
|
|
|
\begin{Verbatim}
|
2016-07-05 19:37:07 +03:00
|
|
|
pdiv : {a, b} (fin a, fin b) => [a] -> [b] -> [a]
|
|
|
|
pmod : {a, b} (fin a, fin b) => [a] -> [1 + b] -> [b]
|
2014-04-18 02:34:25 +04:00
|
|
|
pmult : {a, b} (fin a, fin b) => [a] -> [b] -> [max 1 (a + b) - 1]
|
|
|
|
\end{Verbatim}
|
|
|
|
\paragraph*{Sequences}
|
|
|
|
\begin{Verbatim}
|
2016-08-04 02:18:31 +03:00
|
|
|
take : {front, back, elem} (fin front)
|
2016-07-05 19:37:07 +03:00
|
|
|
=> [front + back]elem -> [front]elem
|
2016-08-04 02:18:31 +03:00
|
|
|
drop : {front, back, elem} (fin front)
|
2016-07-05 19:37:07 +03:00
|
|
|
=> [front + back]elem -> [front]elem
|
|
|
|
tail : {a, b} [a+1]b -> [a]b
|
2016-08-04 02:18:31 +03:00
|
|
|
# : {front, back, a} (fin front) =>
|
|
|
|
=> [front]a -> [back]a -> [front + back]a
|
|
|
|
join : {parts, each, a} (fin each)
|
2016-07-05 19:37:07 +03:00
|
|
|
=> [parts][each]a -> [parts * each]a
|
|
|
|
split : {parts, each, a} (fin a)
|
|
|
|
=> [parts * each]a -> [parts][each]a
|
2014-04-18 02:34:25 +04:00
|
|
|
|
2016-08-04 02:18:31 +03:00
|
|
|
groupBy : {each, parts, elem} (fin each)
|
2014-04-18 02:34:25 +04:00
|
|
|
=> [parts * each]elem -> [parts][each]elem
|
|
|
|
reverse : {a, b} (fin a) => [a]b -> [a]b
|
2016-08-04 02:18:31 +03:00
|
|
|
@ : {a, b, c} (fin c) => [a]b -> [c] -> b
|
|
|
|
! : {a, b, c} (fin a, fin c) => [a]b -> [c] -> b
|
|
|
|
@@ : {a, b, c, d} (fin d) => [a]b -> [c][d] -> [c]b
|
|
|
|
!! : {a, b, c, d} (fin a, fin d) => [a]b -> [c][d] -> [c]b
|
|
|
|
width : {bits,len,elem} (fin len, fin bits, bits >= width len)
|
|
|
|
=> [len] elem -> [bits]
|
2014-04-18 02:34:25 +04:00
|
|
|
\end{Verbatim}
|
|
|
|
\paragraph*{Shifting, rotating}
|
|
|
|
\begin{Verbatim}
|
2016-08-04 02:18:31 +03:00
|
|
|
>>, << : {a, b, c} (fin b) => [a]c -> [b] -> [a]c
|
|
|
|
>>>, <<< : {a, b, c} (fin a, fin b) => [a]c -> [b] -> [a]c
|
2014-04-18 02:34:25 +04:00
|
|
|
\end{Verbatim}
|
|
|
|
\paragraph*{Miscellaneous}
|
|
|
|
\begin{Verbatim}
|
|
|
|
zero : {a} a
|
|
|
|
transpose : {a, b, c} [a][b]c -> [b][a]c
|
2016-08-04 02:18:31 +03:00
|
|
|
min, max : {a} (Cmp a) => a -> a -> a
|
2014-04-18 02:34:25 +04:00
|
|
|
\end{Verbatim}
|
|
|
|
% parity : {a} (fin a) => [a] -> Bit
|
|
|
|
\paragraph*{Representing exceptions}
|
|
|
|
\begin{Verbatim}
|
|
|
|
error : {a, b} [a][8] -> b
|
|
|
|
undefined : {a} a
|
2016-08-04 02:18:31 +03:00
|
|
|
trace : {n, a, b} [n][8] -> a -> b -> b
|
|
|
|
traceVal : {n, a} [n][8] -> a -> a
|
2014-04-18 02:34:25 +04:00
|
|
|
\end{Verbatim}
|
|
|
|
\todo[inline]{\texttt{error} and \texttt{undefined} are not covered in
|
|
|
|
the book at the moment.}
|
|
|
|
|
|
|
|
\todo[inline]{What is the state of debugging (\texttt{trace},
|
|
|
|
\texttt{ASSERT}), randomness (\texttt{random}), and pretty-printing
|
|
|
|
(\texttt{format}) built-ins?}
|
|
|
|
%\paragraph*{Debugging}
|
|
|
|
%\begin{Verbatim}
|
|
|
|
% trace : {a b c} ([a][8],b,c) -> c
|
|
|
|
% ASSERT : {a b} (Bit,[a][8],b) -> b
|
|
|
|
%\end{Verbatim}
|
|
|
|
%\paragraph*{Generating random numbers}
|
|
|
|
%\begin{Verbatim}
|
|
|
|
% random : {a b} (32 >= a) => [a] -> b
|
|
|
|
%\end{Verbatim}
|
|
|
|
%\paragraph*{Pretty printing}
|
|
|
|
%\begin{Verbatim}
|
|
|
|
% format
|
|
|
|
%\end{Verbatim}
|
|
|
|
|
|
|
|
%%% Local Variables:
|
|
|
|
%%% mode: latex
|
|
|
|
%%% TeX-master: "../main/Cryptol"
|
|
|
|
%%% End:
|