How To Design Apis For Cryptographic Protocols: Crypto Group, University of Maryland, Usa
How To Design Apis For Cryptographic Protocols: Crypto Group, University of Maryland, Usa
Lior Malka
Bob Alice
Cons
Inappropriate for large projects.
Code has a limited (as opposed to general) functionality.
Code is not reusable.
Code is hard to maintain/modify.
Prone to errors and bugs.
Bob Alice
Xb null
All Rights Reserved, Lior Malka, 2010 8
Oblivious Transfer (OT) - Formally
In an oblivious transfer protocol, Alice allows Bob to learn only one of
her inputs, but Bob does not tell Alice which one it is. Formally:
Security properties:
Alice does not learn b, and Bob does not learn X1-b.
All Rights Reserved, Lior Malka, 2010 9
Implementing OT : 1st Attempt
class Alice {
String X0,X1;
encryption_key_length;
main(){
// open a socket and wait to hear from Bob..
:
send_first_message();
}
Exercise:
• List all the flaws in the OT protocol.
• How would you modify the code so that it has an API?
Next slides:
Improve design and provide an API.
We will only consider class Alice ; the same improvements apply to
class Bob .
main(){
// open a socket and wait to hear from Bob..
:
send_first_message();
}
Networking functions have
// methods for sending and receiving messages nothing to do with OT. They
void send(byte[] m) { … } should be in a separate class
byte[] receive() { … }
called “Server”
/* methods for constructing the messages of Alice
and processing the replies of Bob */
void send_first_message(){
m1 = new byte[encryption_key_length];
:
send(m1);
receive_second_message();
}
void receive_second_message(){
byte[] m2 = receive();
:
}
}
All Rights Reserved, Lior Malka, 2010 12
Redesign - Phase 1
First Objective
Separate networking functionality from the protocol.
Socket socket;
class Server{
ServerSocket socket;
main(){
Alice alice = new Alice();
alice.server = new Server(..);
send_first_message();
}
Socket socket;
ServerSocket socket;
Socket socket;
main(){
Alice alice = new Alice();
alice.party = new Server(..);
send_first_message();
}
void run() {
party.send(first_message()); Method run centrally defines message
process_second_message(party.receive()); flow in the protocol. This makes the code
: easier to maintain and read.
}
void byte[] first_message(){
m1 = new byte[encryption_key_length]; Methods first_message and
: process_second_message are
return m1; now defined purely in terms of input
} and output. This enables us to test
void process_second_message(byte[] m2){ their correctness independently
: (without having to run the protocol).
}
}
void run() {
party.send(first_message());
process_second_message(party.receive());
:
}
void setInput(String X0, String X1) {
this.X0 = X0; Method setInput sets Alice’s input.
this.X1 = X1; It should be called before the protocol
} starts (method run). Method
String getOutput() { getOutput returns Alice’s output.
return null; Alice could also return an error code
} (0 or -1 depending on successful
} completion).
class MyProjectClient {
main() {
Client client = new Client();
Bob bob = new Bob(client);
// Bob chooses message 0.
bob.setInput(0);
bob.run();
System.out.println(“Message 0 is “ + bob.getOutput());
}
}
Java interfaces can only declare functions. Java abstract classes can do that, and
in addition provide implementations and data members. A class can implement
several interfaces, but only extend one class (either abstract or not).
Class B can extend abstract class A without implementing all abstract methods of
class A. However, only sub classes of A (or B) implementing all abstract methods
of A can be instantiated.
void run() {
:
}
void setInput(String X0, String X1) {
this.X0 = X0;
this.X1 = X1;
}
String getOutput() {
return null;
}
}
Party party;
Protocol(Party party) {
this.party = party;
}
Java and C++ are strongly typed languages. They disallow writing code that
ignores types. In some cases this is a disadvantage. To overcome this issue, Java
provides Generics and C++ provides Templates.
void run() {
:
}
void setInput(String[] X) {
X0 = X[0];
X1 = X[1];
}
String getOutput() {
return null;
}
}