SlideShare a Scribd company logo
1 of 30
Download to read offline
Exploring the Cryptol Toolset

     Pedro Pereira             Ulisses Costa

    Formal Methods in Software Engineering


                   April 30, 2009




Pedro Pereira, Ulisses Costa   Exploring the Cryptol Toolset
Previously in last month’s Episode!

We had to
    Learn the Cryptol language
    Build a high-level specification of SNOW3G

We showed you
    The language was a combination of arithmetics and sequence
    manipulation
    Some of its wonderful features: infinite and recursive streams,
    polymorphism
    The SNOW3G algorithm
    A complete (and compact, and elegant!) specification of a
    stream cipher in Cryptol


              Pedro Pereira, Ulisses Costa   Exploring the Cryptol Toolset
This time



We had to
    Derive an implementation from the specification
    Generate (fast) C source code using Cryptol’s C-backend
    Use the evaluation version ⇒ access to the complete toolset

We will show you
   A user’s perspective of the toolset so far
    Cryptol → C conversion
    Safety + Theorems in Cryptol ⇒ Formal Methods Galore!




               Pedro Pereira, Ulisses Costa   Exploring the Cryptol Toolset
Cryptol Interpreter



The interpreter provides various environments and so far we’ve
used a few of them to:
    Bit mode
         Run Cryptol programs
    C mode
         Generate C source code
    Symbolic Bit-Vector mode
         Apply formal methods




               Pedro Pereira, Ulisses Costa   Exploring the Cryptol Toolset
Bit Mode - useful commands



Usage
:set bit

Base display
:set base=N

Little/Big endianness
:set -/+B




               Pedro Pereira, Ulisses Costa   Exploring the Cryptol Toolset
Base display




Example
Cryptol > [0 1 2 3]
[0x0 0x1 0x2 0x3]
Cryptol > :set base=10
Cryptol > [0 1 2 3]
[0 1 2 3]




              Pedro Pereira, Ulisses Costa   Exploring the Cryptol Toolset
Little/Big endianness

hexbyte.cry
HexByte : [4] Bit ;
HexByte = [ True False False False ];



Example
Cryptol > :load hexbyte.cry
Loading ”hexbyte.cry”.. Checking types.. Processing.. Done!
hexbyte> :set base=2
hexbyte> HexByte
0b0001
hexbyte> :set +B
hexbyte> HexByte
0b1000


              Pedro Pereira, Ulisses Costa   Exploring the Cryptol Toolset
C Mode - useful commands


Usage
:set C

Generation of source code
:compile <filename>

Out-of-bounds checking
:set +b

Specialize polymorphic definitions (automatically on)
:set +S



               Pedro Pereira, Ulisses Costa   Exploring the Cryptol Toolset
Generation of source code


Cryptol → C conversion depends on:
    Cryptol .h
        Contains all the necessary prototypes, macros and a few
        standard C includes.
    CryAlloc.o
        Implements a custom memory allocator/deallocator for
        Cryptol run-time.
    CryPrim.o
        Implements C-equivalents of Cryptol ’s built-in functions.
    CryStream.o
        C library for representing/manipulating infinite streams.




                 Pedro Pereira, Ulisses Costa   Exploring the Cryptol Toolset
Out-of-bounds checking
lookup.cry
lookup : ([4] , [2]) -> Bit ;
lookup ( xs , i ) = xs @ i ;



lookup.c without bounds checking
...
lookup res = GETBIT(xs lookup, i lookup);
...

lookup.c with bounds checking
...
lookup res = GETBIT CHECKED(xs lookup, i lookup, 0x3);
...

                NB: It incurs a performance cost.

              Pedro Pereira, Ulisses Costa   Exploring the Cryptol Toolset
Specialize polymorphic definitions I
size.cry
size : { a b } ( fin a , c >= 1) -> [ a ] b -> [ c ];
size ss = ls ! 0
where ls = [0] # [| ( l +1) || l <- ls || s <- ss |];



Example
size> :set C
size> :compile size.c

size.c
#include ”Cryptol .h”
#include ”size.h”


                                    It’s empty!
               Pedro Pereira, Ulisses Costa   Exploring the Cryptol Toolset
Specialize polymorphic definitions II



Because
Cryptol generates monomorphic definitions ⇒ We must provide
arguments

size.cry
size : { a b } ( fin a , c >= 1) -> [ a ] b -> [ c ];
size ss = ls ! 0
where ls = [0] # [| ( l +1) || l <- ls || s <- ss |];

force_size = size [0 1 2 3 4];




              Pedro Pereira, Ulisses Costa   Exploring the Cryptol Toolset
Generated size.c
size.c
# include quot; cryptol . h quot;
# include quot; size . h quot;

static uint8 const [5] = {0 x0 , 0 x1 , 0 x2 , 0 x3 , 0 x4 };
uint8 size_5 ( uint8 * ss_size ) {
      uint32 local4 = 0 x0 ;
      uint8 local5 = 0 x0 ;
      uint8 size_5_res = 0 x0 ;
      uint8 local8 = 0 x0 ;
      uint32 * mrk = getAllocMark () ;

         size_5_res = 0 x0 ;
         for ( local4 = 0 x0 ; local4 < 0 x5 ; local4 += 0 x1 ) {
                   local8 = size_5_res + 0 x1 ;
                   local5 = local8 & 0 x1f ;
                   size_5_res = local5 ;
         }
         freeUntil ( mrk ) ;
         return size_5_res ;
}

                 Pedro Pereira, Ulisses Costa   Exploring the Cryptol Toolset
Optimizing the C code?


We found out
    Not much, the documentation didn’t even address this
    specifically
       Infinite streams take a heavy toll on performance (it figures...
       besides, an implementation isn’t suposed to have these)

But!
       Hand-made implementation wasn’t much better
       We aren’t done with this yet, it’s just that other stuff grabbed
       our attention




                 Pedro Pereira, Ulisses Costa   Exploring the Cryptol Toolset
SBV Mode - useful commands

Usage
:set sbv

Safety checks
:safe <expression>

Quickcheck
:check <expression>

Theorem prover
:prove <expression>

Satisfiability
:sat <expression>

              Pedro Pereira, Ulisses Costa   Exploring the Cryptol Toolset
Safety checks




Statically catches
     Index out-of-bounds;
    Division/modulus by 0;
    ...and more!

                   Safe programs really don’t crash!




               Pedro Pereira, Ulisses Costa   Exploring the Cryptol Toolset
Safety checking I



lookup.cry
lookup : ([4] , [2]) -> Bit ;
lookup ( xs , i ) = xs @ i ;



Example
lookup> :set sbv
lookup> :safe lookup
”lookup” is safe; no safety violations exist.




                Pedro Pereira, Ulisses Costa   Exploring the Cryptol Toolset
Safety checking II


lookup2.cry
lookup2 : ([4] , [3]) -> Bit ;
lookup2 ( xs , i ) = xs @ i ;



Example
lookup2> :safe lookup2
*** 1 safety condition to be checked.
*** Violation detected:
lookup (0, 4) = ”lookup2.cry”, line 2, col 20: index of 4 is out of
bounds (valid range is 0 thru 3).
*** 1 problem found.



               Pedro Pereira, Ulisses Costa   Exploring the Cryptol Toolset
Safety checking III



lookup3.cry
lookup3 : ([4] , [3]) -> Bit ;
lookup3 ( xs , i ) = if i >= 3 then False else xs @ i ;



Example
lookup3> :safe lookup3
*** 1 safety condition to be checked.
*** Verified safe.
*** All safety checks pass, safe to execute.




               Pedro Pereira, Ulisses Costa   Exploring the Cryptol Toolset
Quickcheck




The :check command
    Cryptol ’s implementation of Quickcheck
    Consists in randomly generating test-cases and running
    property definitions on these
    Validity of theorems




              Pedro Pereira, Ulisses Costa   Exploring the Cryptol Toolset
Quickchecking theorems
Plaintext ⇔ Decrypt . Encrypt
theorem EncDec : { pt k i }. pt == decrypt ( encrypt ( pt , k , i ) , k
    , i);



Example
Cryptol > :set quickCheckCount=100
Cryptol > :load SNOW 3G v0.93.cry
Loading ”SNOW 3G v0.93.cry”.. Checking types.. Processing..
Done!
*** Auto quickchecking 1 theorems.
*** Checking ”EncDec” [”SNOW 3G v0.93.cry”, line 23, col 1]
Checking case 100 of 100 (100.00%)
100 tests passed OK
[Coverage : 0.00%.[(100/3940200619639447921227904010014...)]
SNOW 3G v0.93>
                Pedro Pereira, Ulisses Costa   Exploring the Cryptol Toolset
Test coverage




EncDec coverage
[Coverage: 0.00%. [(100/3940200619639447921227904010014...)]


      2(128+128+128) diferent cases = insane number above




             Pedro Pereira, Ulisses Costa   Exploring the Cryptol Toolset
Theorems are boolean functions!
In First Order Logic
∀x : 2x ⇔ x + x

In Cryptol
double : [8] -> Bit ;
theorem double : { x }. 2* x == x + x ;


Example
double> :prove double
Q.E.D.

The :prove command
    Shows they’re equivalent to the constant function that always
    returns True
     Finds counter-examples
                Pedro Pereira, Ulisses Costa   Exploring the Cryptol Toolset
Counter-example


FG.cry
f , g : [8] -> [8];
f x = (x -1) *( x +1) ;
g x = x * x + 1;

theorem FG : { x }. f x == g x ;



Example
FG> :prove FG
*** Proving ”FG” [”FG.cry”, line 5, col 1]
Falsifiable.
FG 0 = False



                 Pedro Pereira, Ulisses Costa   Exploring the Cryptol Toolset
Satisfiability

Definition
Determining if the variables of a given Boolean formula can be
assigned in such a way as to make the formula evaluate to True.

FH.cry
f , h : [8] -> [8];
f x = (x -1) *( x +1) ;
h x = x * x - 1;

theorem FH : { x }. f x == h x ;



Example
FH> :sat FH
FH 0 = True

                 Pedro Pereira, Ulisses Costa   Exploring the Cryptol Toolset
Oveview of formal methods subset

Highs:
    Fully automated ⇒ it’s a ”push button” package
    If not automated, there’s manual ⇒ Isabelle/HOL translation
    (:isabelle)
    Fast enough

Lows:
    Doesn’t cover the entire Cryptol language:
         Finiteness restriction ⇒ incapable of induction
         Monomorphic restriction
         First order restriction (not really a problem, can be rewritten)
         Symbolic termination ⇒ cant’t use recursive functions (again
         not really a problem, use recursive streams instead)


               Pedro Pereira, Ulisses Costa   Exploring the Cryptol Toolset
Conclusions




Cryptol provides a vast and truly useful toolset for
cryptographers
Formal methods are ”free” in Cryptol ⇒ No need to learn an
external language or tool




          Pedro Pereira, Ulisses Costa   Exploring the Cryptol Toolset
Coming up!




Field-programmable gate arrays!
VHDL!
Space-time tradeoffs!

                               Stay tuned!




          Pedro Pereira, Ulisses Costa   Exploring the Cryptol Toolset
Acknowledgments




        A special thanks to Mr. Levent for his patience.

We also ripped off some ideas from his papers about Cryptol for
                      this presentation!




             Pedro Pereira, Ulisses Costa   Exploring the Cryptol Toolset
Questions




                                       ?




        Pedro Pereira, Ulisses Costa       Exploring the Cryptol Toolset

More Related Content

What's hot

C++20 the small things - Timur Doumler
C++20 the small things - Timur DoumlerC++20 the small things - Timur Doumler
C++20 the small things - Timur Doumlercorehard_by
 
Metrics ekon 14_2_kleiner
Metrics ekon 14_2_kleinerMetrics ekon 14_2_kleiner
Metrics ekon 14_2_kleinerMax Kleiner
 
Evgeniy Muralev, Mark Vince, Working with the compiler, not against it
Evgeniy Muralev, Mark Vince, Working with the compiler, not against itEvgeniy Muralev, Mark Vince, Working with the compiler, not against it
Evgeniy Muralev, Mark Vince, Working with the compiler, not against itSergey Platonov
 
Building High-Performance Language Implementations With Low Effort
Building High-Performance Language Implementations With Low EffortBuilding High-Performance Language Implementations With Low Effort
Building High-Performance Language Implementations With Low EffortStefan Marr
 
Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...
Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...
Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...Stefan Marr
 
Конверсия управляемых языков в неуправляемые
Конверсия управляемых языков в неуправляемыеКонверсия управляемых языков в неуправляемые
Конверсия управляемых языков в неуправляемыеPlatonov Sergey
 
The Cryptol Epilogue: Swift and Bulletproof VHDL
The Cryptol Epilogue: Swift and Bulletproof VHDLThe Cryptol Epilogue: Swift and Bulletproof VHDL
The Cryptol Epilogue: Swift and Bulletproof VHDLUlisses Costa
 
C++ How I learned to stop worrying and love metaprogramming
C++ How I learned to stop worrying and love metaprogrammingC++ How I learned to stop worrying and love metaprogramming
C++ How I learned to stop worrying and love metaprogrammingcppfrug
 
개발 과정 최적화 하기 내부툴로 더욱 강력한 개발하기 Stephen kennedy _(11시40분_103호)
개발 과정 최적화 하기 내부툴로 더욱 강력한 개발하기 Stephen kennedy _(11시40분_103호)개발 과정 최적화 하기 내부툴로 더욱 강력한 개발하기 Stephen kennedy _(11시40분_103호)
개발 과정 최적화 하기 내부툴로 더욱 강력한 개발하기 Stephen kennedy _(11시40분_103호)changehee lee
 
What has to be paid attention when reviewing code of the library you develop
What has to be paid attention when reviewing code of the library you developWhat has to be paid attention when reviewing code of the library you develop
What has to be paid attention when reviewing code of the library you developAndrey Karpov
 
200 Open Source Projects Later: Source Code Static Analysis Experience
200 Open Source Projects Later: Source Code Static Analysis Experience200 Open Source Projects Later: Source Code Static Analysis Experience
200 Open Source Projects Later: Source Code Static Analysis ExperienceAndrey Karpov
 
Address/Thread/Memory Sanitizer
Address/Thread/Memory SanitizerAddress/Thread/Memory Sanitizer
Address/Thread/Memory SanitizerPlatonov Sergey
 
Whats new in_csharp4
Whats new in_csharp4Whats new in_csharp4
Whats new in_csharp4Abed Bukhari
 
An Embedded Error Recovery and Debugging Mechanism for Scripting Language Ext...
An Embedded Error Recovery and Debugging Mechanism for Scripting Language Ext...An Embedded Error Recovery and Debugging Mechanism for Scripting Language Ext...
An Embedded Error Recovery and Debugging Mechanism for Scripting Language Ext...David Beazley (Dabeaz LLC)
 
Design and Implementation of GCC Register Allocation
Design and Implementation of GCC Register AllocationDesign and Implementation of GCC Register Allocation
Design and Implementation of GCC Register AllocationKito Cheng
 
Story of static code analyzer development
Story of static code analyzer developmentStory of static code analyzer development
Story of static code analyzer developmentAndrey Karpov
 
Egor Bogatov - .NET Core intrinsics and other micro-optimizations
Egor Bogatov - .NET Core intrinsics and other micro-optimizationsEgor Bogatov - .NET Core intrinsics and other micro-optimizations
Egor Bogatov - .NET Core intrinsics and other micro-optimizationsEgor Bogatov
 
C++ idioms by example (Nov 2008)
C++ idioms by example (Nov 2008)C++ idioms by example (Nov 2008)
C++ idioms by example (Nov 2008)Olve Maudal
 

What's hot (20)

C++20 the small things - Timur Doumler
C++20 the small things - Timur DoumlerC++20 the small things - Timur Doumler
C++20 the small things - Timur Doumler
 
Metrics ekon 14_2_kleiner
Metrics ekon 14_2_kleinerMetrics ekon 14_2_kleiner
Metrics ekon 14_2_kleiner
 
Evgeniy Muralev, Mark Vince, Working with the compiler, not against it
Evgeniy Muralev, Mark Vince, Working with the compiler, not against itEvgeniy Muralev, Mark Vince, Working with the compiler, not against it
Evgeniy Muralev, Mark Vince, Working with the compiler, not against it
 
Building High-Performance Language Implementations With Low Effort
Building High-Performance Language Implementations With Low EffortBuilding High-Performance Language Implementations With Low Effort
Building High-Performance Language Implementations With Low Effort
 
Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...
Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...
Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...
 
Конверсия управляемых языков в неуправляемые
Конверсия управляемых языков в неуправляемыеКонверсия управляемых языков в неуправляемые
Конверсия управляемых языков в неуправляемые
 
The Cryptol Epilogue: Swift and Bulletproof VHDL
The Cryptol Epilogue: Swift and Bulletproof VHDLThe Cryptol Epilogue: Swift and Bulletproof VHDL
The Cryptol Epilogue: Swift and Bulletproof VHDL
 
C++ How I learned to stop worrying and love metaprogramming
C++ How I learned to stop worrying and love metaprogrammingC++ How I learned to stop worrying and love metaprogramming
C++ How I learned to stop worrying and love metaprogramming
 
개발 과정 최적화 하기 내부툴로 더욱 강력한 개발하기 Stephen kennedy _(11시40분_103호)
개발 과정 최적화 하기 내부툴로 더욱 강력한 개발하기 Stephen kennedy _(11시40분_103호)개발 과정 최적화 하기 내부툴로 더욱 강력한 개발하기 Stephen kennedy _(11시40분_103호)
개발 과정 최적화 하기 내부툴로 더욱 강력한 개발하기 Stephen kennedy _(11시40분_103호)
 
What has to be paid attention when reviewing code of the library you develop
What has to be paid attention when reviewing code of the library you developWhat has to be paid attention when reviewing code of the library you develop
What has to be paid attention when reviewing code of the library you develop
 
200 Open Source Projects Later: Source Code Static Analysis Experience
200 Open Source Projects Later: Source Code Static Analysis Experience200 Open Source Projects Later: Source Code Static Analysis Experience
200 Open Source Projects Later: Source Code Static Analysis Experience
 
Address/Thread/Memory Sanitizer
Address/Thread/Memory SanitizerAddress/Thread/Memory Sanitizer
Address/Thread/Memory Sanitizer
 
Whats new in_csharp4
Whats new in_csharp4Whats new in_csharp4
Whats new in_csharp4
 
An Embedded Error Recovery and Debugging Mechanism for Scripting Language Ext...
An Embedded Error Recovery and Debugging Mechanism for Scripting Language Ext...An Embedded Error Recovery and Debugging Mechanism for Scripting Language Ext...
An Embedded Error Recovery and Debugging Mechanism for Scripting Language Ext...
 
Interpreter, Compiler, JIT from scratch
Interpreter, Compiler, JIT from scratchInterpreter, Compiler, JIT from scratch
Interpreter, Compiler, JIT from scratch
 
Design and Implementation of GCC Register Allocation
Design and Implementation of GCC Register AllocationDesign and Implementation of GCC Register Allocation
Design and Implementation of GCC Register Allocation
 
Story of static code analyzer development
Story of static code analyzer developmentStory of static code analyzer development
Story of static code analyzer development
 
Egor Bogatov - .NET Core intrinsics and other micro-optimizations
Egor Bogatov - .NET Core intrinsics and other micro-optimizationsEgor Bogatov - .NET Core intrinsics and other micro-optimizations
Egor Bogatov - .NET Core intrinsics and other micro-optimizations
 
TensorFlow XLA RPC
TensorFlow XLA RPCTensorFlow XLA RPC
TensorFlow XLA RPC
 
C++ idioms by example (Nov 2008)
C++ idioms by example (Nov 2008)C++ idioms by example (Nov 2008)
C++ idioms by example (Nov 2008)
 

Viewers also liked

Snort - capturar e dissecar o tráfego da rede
Snort - capturar e dissecar o tráfego da redeSnort - capturar e dissecar o tráfego da rede
Snort - capturar e dissecar o tráfego da redeUlisses Costa
 
Fast Resilient Jumbo Frames in Wireless LANs
Fast Resilient Jumbo Frames in Wireless LANsFast Resilient Jumbo Frames in Wireless LANs
Fast Resilient Jumbo Frames in Wireless LANsanandpiyer
 
Captura de Informação em Rede
Captura de Informação em RedeCaptura de Informação em Rede
Captura de Informação em RedeUlisses Costa
 
Rac Seminar Presentation 30.04.08
Rac Seminar Presentation 30.04.08Rac Seminar Presentation 30.04.08
Rac Seminar Presentation 30.04.08RememberACharity
 
frizzled blush
 frizzled blush frizzled blush
frizzled blushsfalan
 
GD::Graph - Graph Plotting Module
GD::Graph - Graph Plotting ModuleGD::Graph - Graph Plotting Module
GD::Graph - Graph Plotting ModuleUlisses Costa
 
Correct sorting with Frama-C
Correct sorting with Frama-CCorrect sorting with Frama-C
Correct sorting with Frama-CUlisses Costa
 
Splint the C code static checker
Splint the C code static checkerSplint the C code static checker
Splint the C code static checkerUlisses Costa
 
Automatic Test Generation for Space
Automatic Test Generation for SpaceAutomatic Test Generation for Space
Automatic Test Generation for SpaceUlisses Costa
 
Static Code Analyzer - Part II
Static Code Analyzer - Part IIStatic Code Analyzer - Part II
Static Code Analyzer - Part IIUlisses Costa
 
Automatic Test Generation for Space
Automatic Test Generation for SpaceAutomatic Test Generation for Space
Automatic Test Generation for SpaceUlisses Costa
 
adtechtokyo2010 Augmented Reality - A Showcase What The Marketers Need To Know
adtechtokyo2010 Augmented Reality - A Showcase What The Marketers Need To Knowadtechtokyo2010 Augmented Reality - A Showcase What The Marketers Need To Know
adtechtokyo2010 Augmented Reality - A Showcase What The Marketers Need To KnowAkihiko Tokuhisa
 
Specifying and Implementing SNOW3G with Cryptol
Specifying and Implementing SNOW3G with CryptolSpecifying and Implementing SNOW3G with Cryptol
Specifying and Implementing SNOW3G with CryptolUlisses Costa
 
Uso de Honeypots com Honeyd
Uso de Honeypots com HoneydUso de Honeypots com Honeyd
Uso de Honeypots com HoneydUlisses Costa
 
Specification of SNOW 3G in Cryptol
Specification of SNOW 3G in CryptolSpecification of SNOW 3G in Cryptol
Specification of SNOW 3G in CryptolUlisses Costa
 

Viewers also liked (18)

LDAP em VDM++
LDAP em VDM++LDAP em VDM++
LDAP em VDM++
 
Cryptol experience
Cryptol experienceCryptol experience
Cryptol experience
 
Apresentacao JML
Apresentacao JMLApresentacao JML
Apresentacao JML
 
Snort - capturar e dissecar o tráfego da rede
Snort - capturar e dissecar o tráfego da redeSnort - capturar e dissecar o tráfego da rede
Snort - capturar e dissecar o tráfego da rede
 
Fast Resilient Jumbo Frames in Wireless LANs
Fast Resilient Jumbo Frames in Wireless LANsFast Resilient Jumbo Frames in Wireless LANs
Fast Resilient Jumbo Frames in Wireless LANs
 
Captura de Informação em Rede
Captura de Informação em RedeCaptura de Informação em Rede
Captura de Informação em Rede
 
Rac Seminar Presentation 30.04.08
Rac Seminar Presentation 30.04.08Rac Seminar Presentation 30.04.08
Rac Seminar Presentation 30.04.08
 
frizzled blush
 frizzled blush frizzled blush
frizzled blush
 
GD::Graph - Graph Plotting Module
GD::Graph - Graph Plotting ModuleGD::Graph - Graph Plotting Module
GD::Graph - Graph Plotting Module
 
Correct sorting with Frama-C
Correct sorting with Frama-CCorrect sorting with Frama-C
Correct sorting with Frama-C
 
Splint the C code static checker
Splint the C code static checkerSplint the C code static checker
Splint the C code static checker
 
Automatic Test Generation for Space
Automatic Test Generation for SpaceAutomatic Test Generation for Space
Automatic Test Generation for Space
 
Static Code Analyzer - Part II
Static Code Analyzer - Part IIStatic Code Analyzer - Part II
Static Code Analyzer - Part II
 
Automatic Test Generation for Space
Automatic Test Generation for SpaceAutomatic Test Generation for Space
Automatic Test Generation for Space
 
adtechtokyo2010 Augmented Reality - A Showcase What The Marketers Need To Know
adtechtokyo2010 Augmented Reality - A Showcase What The Marketers Need To Knowadtechtokyo2010 Augmented Reality - A Showcase What The Marketers Need To Know
adtechtokyo2010 Augmented Reality - A Showcase What The Marketers Need To Know
 
Specifying and Implementing SNOW3G with Cryptol
Specifying and Implementing SNOW3G with CryptolSpecifying and Implementing SNOW3G with Cryptol
Specifying and Implementing SNOW3G with Cryptol
 
Uso de Honeypots com Honeyd
Uso de Honeypots com HoneydUso de Honeypots com Honeyd
Uso de Honeypots com Honeyd
 
Specification of SNOW 3G in Cryptol
Specification of SNOW 3G in CryptolSpecification of SNOW 3G in Cryptol
Specification of SNOW 3G in Cryptol
 

Similar to Exploring the Cryptol Toolset

Protocol T50: Five months later... So what?
Protocol T50: Five months later... So what?Protocol T50: Five months later... So what?
Protocol T50: Five months later... So what?Nelson Brito
 
App secforum2014 andrivet-cplusplus11-metaprogramming_applied_to_software_obf...
App secforum2014 andrivet-cplusplus11-metaprogramming_applied_to_software_obf...App secforum2014 andrivet-cplusplus11-metaprogramming_applied_to_software_obf...
App secforum2014 andrivet-cplusplus11-metaprogramming_applied_to_software_obf...Cyber Security Alliance
 
Aaron Bedra - Effective Software Security Teams
Aaron Bedra - Effective Software Security TeamsAaron Bedra - Effective Software Security Teams
Aaron Bedra - Effective Software Security Teamscentralohioissa
 
PVS-Studio. Static code analyzer. Windows/Linux, C/C++/C#. 2017
PVS-Studio. Static code analyzer. Windows/Linux, C/C++/C#. 2017PVS-Studio. Static code analyzer. Windows/Linux, C/C++/C#. 2017
PVS-Studio. Static code analyzer. Windows/Linux, C/C++/C#. 2017Andrey Karpov
 
Georgy Nosenko - An introduction to the use SMT solvers for software security
Georgy Nosenko - An introduction to the use SMT solvers for software securityGeorgy Nosenko - An introduction to the use SMT solvers for software security
Georgy Nosenko - An introduction to the use SMT solvers for software securityDefconRussia
 
Static code analysis: what? how? why?
Static code analysis: what? how? why?Static code analysis: what? how? why?
Static code analysis: what? how? why?Andrey Karpov
 
Cluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in CCluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in CSteffen Wenz
 
Mind your language(s), A Discussion about Languages and Security
Mind your language(s), A Discussion about Languages and SecurityMind your language(s), A Discussion about Languages and Security
Mind your language(s), A Discussion about Languages and SecurityAdaCore
 
Machine Learning on Code - SF meetup
Machine Learning on Code - SF meetupMachine Learning on Code - SF meetup
Machine Learning on Code - SF meetupsource{d}
 
maXbox Starter 45 Robotics
maXbox Starter 45 RoboticsmaXbox Starter 45 Robotics
maXbox Starter 45 RoboticsMax Kleiner
 
Tdd with python unittest for embedded c
Tdd with python unittest for embedded cTdd with python unittest for embedded c
Tdd with python unittest for embedded cBenux Wei
 
Tutorial s crypto api session keys
Tutorial   s crypto api session keysTutorial   s crypto api session keys
Tutorial s crypto api session keysDr. Edwin Hernandez
 
#ifndef CRYPTO_HPP#define CRYPTO_HPP#include functional#.docx
#ifndef CRYPTO_HPP#define CRYPTO_HPP#include functional#.docx#ifndef CRYPTO_HPP#define CRYPTO_HPP#include functional#.docx
#ifndef CRYPTO_HPP#define CRYPTO_HPP#include functional#.docxgertrudebellgrove
 
Beyond Breakpoints: A Tour of Dynamic Analysis
Beyond Breakpoints: A Tour of Dynamic AnalysisBeyond Breakpoints: A Tour of Dynamic Analysis
Beyond Breakpoints: A Tour of Dynamic AnalysisFastly
 
ESL Anyone?
ESL Anyone? ESL Anyone?
ESL Anyone? DVClub
 
Security and Encryption on iOS
Security and Encryption on iOSSecurity and Encryption on iOS
Security and Encryption on iOSGraham Lee
 
An Overview of SystemVerilog for Design and Verification
An Overview of SystemVerilog  for Design and VerificationAn Overview of SystemVerilog  for Design and Verification
An Overview of SystemVerilog for Design and VerificationKapilRaghunandanTrip
 
The System of Automatic Searching for Vulnerabilities or how to use Taint Ana...
The System of Automatic Searching for Vulnerabilities or how to use Taint Ana...The System of Automatic Searching for Vulnerabilities or how to use Taint Ana...
The System of Automatic Searching for Vulnerabilities or how to use Taint Ana...Positive Hack Days
 

Similar to Exploring the Cryptol Toolset (20)

Protocol T50: Five months later... So what?
Protocol T50: Five months later... So what?Protocol T50: Five months later... So what?
Protocol T50: Five months later... So what?
 
App secforum2014 andrivet-cplusplus11-metaprogramming_applied_to_software_obf...
App secforum2014 andrivet-cplusplus11-metaprogramming_applied_to_software_obf...App secforum2014 andrivet-cplusplus11-metaprogramming_applied_to_software_obf...
App secforum2014 andrivet-cplusplus11-metaprogramming_applied_to_software_obf...
 
Aaron Bedra - Effective Software Security Teams
Aaron Bedra - Effective Software Security TeamsAaron Bedra - Effective Software Security Teams
Aaron Bedra - Effective Software Security Teams
 
PVS-Studio. Static code analyzer. Windows/Linux, C/C++/C#. 2017
PVS-Studio. Static code analyzer. Windows/Linux, C/C++/C#. 2017PVS-Studio. Static code analyzer. Windows/Linux, C/C++/C#. 2017
PVS-Studio. Static code analyzer. Windows/Linux, C/C++/C#. 2017
 
Georgy Nosenko - An introduction to the use SMT solvers for software security
Georgy Nosenko - An introduction to the use SMT solvers for software securityGeorgy Nosenko - An introduction to the use SMT solvers for software security
Georgy Nosenko - An introduction to the use SMT solvers for software security
 
Static code analysis: what? how? why?
Static code analysis: what? how? why?Static code analysis: what? how? why?
Static code analysis: what? how? why?
 
Cluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in CCluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in C
 
Mind your language(s), A Discussion about Languages and Security
Mind your language(s), A Discussion about Languages and SecurityMind your language(s), A Discussion about Languages and Security
Mind your language(s), A Discussion about Languages and Security
 
Machine Learning on Code - SF meetup
Machine Learning on Code - SF meetupMachine Learning on Code - SF meetup
Machine Learning on Code - SF meetup
 
maXbox Starter 45 Robotics
maXbox Starter 45 RoboticsmaXbox Starter 45 Robotics
maXbox Starter 45 Robotics
 
Software Engineering
Software EngineeringSoftware Engineering
Software Engineering
 
Tdd with python unittest for embedded c
Tdd with python unittest for embedded cTdd with python unittest for embedded c
Tdd with python unittest for embedded c
 
Tutorial s crypto api session keys
Tutorial   s crypto api session keysTutorial   s crypto api session keys
Tutorial s crypto api session keys
 
Python lec1
Python lec1Python lec1
Python lec1
 
#ifndef CRYPTO_HPP#define CRYPTO_HPP#include functional#.docx
#ifndef CRYPTO_HPP#define CRYPTO_HPP#include functional#.docx#ifndef CRYPTO_HPP#define CRYPTO_HPP#include functional#.docx
#ifndef CRYPTO_HPP#define CRYPTO_HPP#include functional#.docx
 
Beyond Breakpoints: A Tour of Dynamic Analysis
Beyond Breakpoints: A Tour of Dynamic AnalysisBeyond Breakpoints: A Tour of Dynamic Analysis
Beyond Breakpoints: A Tour of Dynamic Analysis
 
ESL Anyone?
ESL Anyone? ESL Anyone?
ESL Anyone?
 
Security and Encryption on iOS
Security and Encryption on iOSSecurity and Encryption on iOS
Security and Encryption on iOS
 
An Overview of SystemVerilog for Design and Verification
An Overview of SystemVerilog  for Design and VerificationAn Overview of SystemVerilog  for Design and Verification
An Overview of SystemVerilog for Design and Verification
 
The System of Automatic Searching for Vulnerabilities or how to use Taint Ana...
The System of Automatic Searching for Vulnerabilities or how to use Taint Ana...The System of Automatic Searching for Vulnerabilities or how to use Taint Ana...
The System of Automatic Searching for Vulnerabilities or how to use Taint Ana...
 

More from Ulisses Costa

Static Code Analyzer - Part IV
Static Code Analyzer - Part IVStatic Code Analyzer - Part IV
Static Code Analyzer - Part IVUlisses Costa
 
Static Code Analyzer - Part III
Static Code Analyzer - Part IIIStatic Code Analyzer - Part III
Static Code Analyzer - Part IIIUlisses Costa
 
Static Code Analyzer - Part I
Static Code Analyzer - Part IStatic Code Analyzer - Part I
Static Code Analyzer - Part IUlisses Costa
 
Linux Instalation Party
Linux Instalation PartyLinux Instalation Party
Linux Instalation PartyUlisses Costa
 
Calculador Pointfree
Calculador PointfreeCalculador Pointfree
Calculador PointfreeUlisses Costa
 

More from Ulisses Costa (8)

Static Code Analyzer - Part IV
Static Code Analyzer - Part IVStatic Code Analyzer - Part IV
Static Code Analyzer - Part IV
 
Static Code Analyzer - Part III
Static Code Analyzer - Part IIIStatic Code Analyzer - Part III
Static Code Analyzer - Part III
 
Static Code Analyzer - Part I
Static Code Analyzer - Part IStatic Code Analyzer - Part I
Static Code Analyzer - Part I
 
logCesium01
logCesium01logCesium01
logCesium01
 
Cesium Log ed2
Cesium Log ed2Cesium Log ed2
Cesium Log ed2
 
Linux Instalation Party
Linux Instalation PartyLinux Instalation Party
Linux Instalation Party
 
Workshop LaTeX
Workshop LaTeXWorkshop LaTeX
Workshop LaTeX
 
Calculador Pointfree
Calculador PointfreeCalculador Pointfree
Calculador Pointfree
 

Recently uploaded

Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 

Recently uploaded (20)

Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 

Exploring the Cryptol Toolset

  • 1. Exploring the Cryptol Toolset Pedro Pereira Ulisses Costa Formal Methods in Software Engineering April 30, 2009 Pedro Pereira, Ulisses Costa Exploring the Cryptol Toolset
  • 2. Previously in last month’s Episode! We had to Learn the Cryptol language Build a high-level specification of SNOW3G We showed you The language was a combination of arithmetics and sequence manipulation Some of its wonderful features: infinite and recursive streams, polymorphism The SNOW3G algorithm A complete (and compact, and elegant!) specification of a stream cipher in Cryptol Pedro Pereira, Ulisses Costa Exploring the Cryptol Toolset
  • 3. This time We had to Derive an implementation from the specification Generate (fast) C source code using Cryptol’s C-backend Use the evaluation version ⇒ access to the complete toolset We will show you A user’s perspective of the toolset so far Cryptol → C conversion Safety + Theorems in Cryptol ⇒ Formal Methods Galore! Pedro Pereira, Ulisses Costa Exploring the Cryptol Toolset
  • 4. Cryptol Interpreter The interpreter provides various environments and so far we’ve used a few of them to: Bit mode Run Cryptol programs C mode Generate C source code Symbolic Bit-Vector mode Apply formal methods Pedro Pereira, Ulisses Costa Exploring the Cryptol Toolset
  • 5. Bit Mode - useful commands Usage :set bit Base display :set base=N Little/Big endianness :set -/+B Pedro Pereira, Ulisses Costa Exploring the Cryptol Toolset
  • 6. Base display Example Cryptol > [0 1 2 3] [0x0 0x1 0x2 0x3] Cryptol > :set base=10 Cryptol > [0 1 2 3] [0 1 2 3] Pedro Pereira, Ulisses Costa Exploring the Cryptol Toolset
  • 7. Little/Big endianness hexbyte.cry HexByte : [4] Bit ; HexByte = [ True False False False ]; Example Cryptol > :load hexbyte.cry Loading ”hexbyte.cry”.. Checking types.. Processing.. Done! hexbyte> :set base=2 hexbyte> HexByte 0b0001 hexbyte> :set +B hexbyte> HexByte 0b1000 Pedro Pereira, Ulisses Costa Exploring the Cryptol Toolset
  • 8. C Mode - useful commands Usage :set C Generation of source code :compile <filename> Out-of-bounds checking :set +b Specialize polymorphic definitions (automatically on) :set +S Pedro Pereira, Ulisses Costa Exploring the Cryptol Toolset
  • 9. Generation of source code Cryptol → C conversion depends on: Cryptol .h Contains all the necessary prototypes, macros and a few standard C includes. CryAlloc.o Implements a custom memory allocator/deallocator for Cryptol run-time. CryPrim.o Implements C-equivalents of Cryptol ’s built-in functions. CryStream.o C library for representing/manipulating infinite streams. Pedro Pereira, Ulisses Costa Exploring the Cryptol Toolset
  • 10. Out-of-bounds checking lookup.cry lookup : ([4] , [2]) -> Bit ; lookup ( xs , i ) = xs @ i ; lookup.c without bounds checking ... lookup res = GETBIT(xs lookup, i lookup); ... lookup.c with bounds checking ... lookup res = GETBIT CHECKED(xs lookup, i lookup, 0x3); ... NB: It incurs a performance cost. Pedro Pereira, Ulisses Costa Exploring the Cryptol Toolset
  • 11. Specialize polymorphic definitions I size.cry size : { a b } ( fin a , c >= 1) -> [ a ] b -> [ c ]; size ss = ls ! 0 where ls = [0] # [| ( l +1) || l <- ls || s <- ss |]; Example size> :set C size> :compile size.c size.c #include ”Cryptol .h” #include ”size.h” It’s empty! Pedro Pereira, Ulisses Costa Exploring the Cryptol Toolset
  • 12. Specialize polymorphic definitions II Because Cryptol generates monomorphic definitions ⇒ We must provide arguments size.cry size : { a b } ( fin a , c >= 1) -> [ a ] b -> [ c ]; size ss = ls ! 0 where ls = [0] # [| ( l +1) || l <- ls || s <- ss |]; force_size = size [0 1 2 3 4]; Pedro Pereira, Ulisses Costa Exploring the Cryptol Toolset
  • 13. Generated size.c size.c # include quot; cryptol . h quot; # include quot; size . h quot; static uint8 const [5] = {0 x0 , 0 x1 , 0 x2 , 0 x3 , 0 x4 }; uint8 size_5 ( uint8 * ss_size ) { uint32 local4 = 0 x0 ; uint8 local5 = 0 x0 ; uint8 size_5_res = 0 x0 ; uint8 local8 = 0 x0 ; uint32 * mrk = getAllocMark () ; size_5_res = 0 x0 ; for ( local4 = 0 x0 ; local4 < 0 x5 ; local4 += 0 x1 ) { local8 = size_5_res + 0 x1 ; local5 = local8 & 0 x1f ; size_5_res = local5 ; } freeUntil ( mrk ) ; return size_5_res ; } Pedro Pereira, Ulisses Costa Exploring the Cryptol Toolset
  • 14. Optimizing the C code? We found out Not much, the documentation didn’t even address this specifically Infinite streams take a heavy toll on performance (it figures... besides, an implementation isn’t suposed to have these) But! Hand-made implementation wasn’t much better We aren’t done with this yet, it’s just that other stuff grabbed our attention Pedro Pereira, Ulisses Costa Exploring the Cryptol Toolset
  • 15. SBV Mode - useful commands Usage :set sbv Safety checks :safe <expression> Quickcheck :check <expression> Theorem prover :prove <expression> Satisfiability :sat <expression> Pedro Pereira, Ulisses Costa Exploring the Cryptol Toolset
  • 16. Safety checks Statically catches Index out-of-bounds; Division/modulus by 0; ...and more! Safe programs really don’t crash! Pedro Pereira, Ulisses Costa Exploring the Cryptol Toolset
  • 17. Safety checking I lookup.cry lookup : ([4] , [2]) -> Bit ; lookup ( xs , i ) = xs @ i ; Example lookup> :set sbv lookup> :safe lookup ”lookup” is safe; no safety violations exist. Pedro Pereira, Ulisses Costa Exploring the Cryptol Toolset
  • 18. Safety checking II lookup2.cry lookup2 : ([4] , [3]) -> Bit ; lookup2 ( xs , i ) = xs @ i ; Example lookup2> :safe lookup2 *** 1 safety condition to be checked. *** Violation detected: lookup (0, 4) = ”lookup2.cry”, line 2, col 20: index of 4 is out of bounds (valid range is 0 thru 3). *** 1 problem found. Pedro Pereira, Ulisses Costa Exploring the Cryptol Toolset
  • 19. Safety checking III lookup3.cry lookup3 : ([4] , [3]) -> Bit ; lookup3 ( xs , i ) = if i >= 3 then False else xs @ i ; Example lookup3> :safe lookup3 *** 1 safety condition to be checked. *** Verified safe. *** All safety checks pass, safe to execute. Pedro Pereira, Ulisses Costa Exploring the Cryptol Toolset
  • 20. Quickcheck The :check command Cryptol ’s implementation of Quickcheck Consists in randomly generating test-cases and running property definitions on these Validity of theorems Pedro Pereira, Ulisses Costa Exploring the Cryptol Toolset
  • 21. Quickchecking theorems Plaintext ⇔ Decrypt . Encrypt theorem EncDec : { pt k i }. pt == decrypt ( encrypt ( pt , k , i ) , k , i); Example Cryptol > :set quickCheckCount=100 Cryptol > :load SNOW 3G v0.93.cry Loading ”SNOW 3G v0.93.cry”.. Checking types.. Processing.. Done! *** Auto quickchecking 1 theorems. *** Checking ”EncDec” [”SNOW 3G v0.93.cry”, line 23, col 1] Checking case 100 of 100 (100.00%) 100 tests passed OK [Coverage : 0.00%.[(100/3940200619639447921227904010014...)] SNOW 3G v0.93> Pedro Pereira, Ulisses Costa Exploring the Cryptol Toolset
  • 22. Test coverage EncDec coverage [Coverage: 0.00%. [(100/3940200619639447921227904010014...)] 2(128+128+128) diferent cases = insane number above Pedro Pereira, Ulisses Costa Exploring the Cryptol Toolset
  • 23. Theorems are boolean functions! In First Order Logic ∀x : 2x ⇔ x + x In Cryptol double : [8] -> Bit ; theorem double : { x }. 2* x == x + x ; Example double> :prove double Q.E.D. The :prove command Shows they’re equivalent to the constant function that always returns True Finds counter-examples Pedro Pereira, Ulisses Costa Exploring the Cryptol Toolset
  • 24. Counter-example FG.cry f , g : [8] -> [8]; f x = (x -1) *( x +1) ; g x = x * x + 1; theorem FG : { x }. f x == g x ; Example FG> :prove FG *** Proving ”FG” [”FG.cry”, line 5, col 1] Falsifiable. FG 0 = False Pedro Pereira, Ulisses Costa Exploring the Cryptol Toolset
  • 25. Satisfiability Definition Determining if the variables of a given Boolean formula can be assigned in such a way as to make the formula evaluate to True. FH.cry f , h : [8] -> [8]; f x = (x -1) *( x +1) ; h x = x * x - 1; theorem FH : { x }. f x == h x ; Example FH> :sat FH FH 0 = True Pedro Pereira, Ulisses Costa Exploring the Cryptol Toolset
  • 26. Oveview of formal methods subset Highs: Fully automated ⇒ it’s a ”push button” package If not automated, there’s manual ⇒ Isabelle/HOL translation (:isabelle) Fast enough Lows: Doesn’t cover the entire Cryptol language: Finiteness restriction ⇒ incapable of induction Monomorphic restriction First order restriction (not really a problem, can be rewritten) Symbolic termination ⇒ cant’t use recursive functions (again not really a problem, use recursive streams instead) Pedro Pereira, Ulisses Costa Exploring the Cryptol Toolset
  • 27. Conclusions Cryptol provides a vast and truly useful toolset for cryptographers Formal methods are ”free” in Cryptol ⇒ No need to learn an external language or tool Pedro Pereira, Ulisses Costa Exploring the Cryptol Toolset
  • 28. Coming up! Field-programmable gate arrays! VHDL! Space-time tradeoffs! Stay tuned! Pedro Pereira, Ulisses Costa Exploring the Cryptol Toolset
  • 29. Acknowledgments A special thanks to Mr. Levent for his patience. We also ripped off some ideas from his papers about Cryptol for this presentation! Pedro Pereira, Ulisses Costa Exploring the Cryptol Toolset
  • 30. Questions ? Pedro Pereira, Ulisses Costa Exploring the Cryptol Toolset