Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rules for PrivateKey and PublicKey #152

Merged
merged 3 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions BouncyCastle-JCA/src/PrivateKey.crysl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
SPEC java.security.PrivateKey

OBJECTS
byte[] keyMaterial;

EVENTS
ge1: keyMaterial = getEncoded();
GetEnc := ge1;

ORDER
GetEnc*

ENSURES
preparedKeyMaterial[keyMaterial] after GetEnc;
14 changes: 14 additions & 0 deletions BouncyCastle-JCA/src/PublicKey.crysl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
SPEC java.security.PublicKey

OBJECTS
byte[] keyMaterial;

EVENTS
ge1: keyMaterial = getEncoded();
GetEnc := ge1;

ORDER
GetEnc*

ENSURES
preparedKeyMaterial[keyMaterial] after GetEnc;
6 changes: 3 additions & 3 deletions BouncyCastle/src/AESEngine.crysl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
SPEC org.bouncycastle.crypto.engines.AESEngine

OBJECTS
int dummy; //This section can't be empty or else the rule is marked with an error.
FORBIDDEN
AESEngine();

EVENTS
c1: AESEngine();
c1: newInstance();
Con := c1;

ORDER
Expand Down
14 changes: 1 addition & 13 deletions BouncyCastle/src/AESFastEngine.crysl
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
//The AESFastEngine class is deprecated and insecure. This crysl rule ensures that a AESFastEngine object is considered insecure.
SPEC org.bouncycastle.crypto.engines.AESFastEngine

OBJECTS
int dummy; //This section can't be empty or else the rule is marked with an error.

FORBIDDEN
AESFastEngine() ;

EVENTS
c1: AESFastEngine();
Con := c1;

ORDER
Con


AESFastEngine();
3 changes: 0 additions & 3 deletions BouncyCastle/src/AESLightEngine.crysl
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
SPEC org.bouncycastle.crypto.engines.AESLightEngine

OBJECTS
int dummy; //This section can't be empty or else the rule is marked with an error.

EVENTS
c1: AESLightEngine();
Con := c1;
Expand Down
50 changes: 3 additions & 47 deletions BouncyCastle/src/BufferedBlockCipher.crysl
Original file line number Diff line number Diff line change
@@ -1,49 +1,5 @@
// Deprecated
SPEC org.bouncycastle.crypto.BufferedBlockCipher

OBJECTS
org.bouncycastle.crypto.BlockCipher cipher;
org.bouncycastle.crypto.CipherParameters params;

byte plainTextByte;
byte[] plainText;
int plainTextOffset;
int plainTextLen;

byte[] cipherText;
int cipherTextOffset;

boolean isEncryption;


EVENTS
c1: BufferedBlockCipher(cipher);
Con := c1;

i1: init(isEncryption, params);
Init := i1;

// @return the number of output bytes copied to out.
p1: processByte(plainTextByte, cipherText, cipherTextOffset);
p2: processBytes(plainText, plainTextOffset, plainTextLen, cipherText, cipherTextOffset);
Proc := p1 | p2;

// @return the number of output bytes copied to out.
df1: doFinal(cipherText, cipherTextOffset);
DoFinal := df1;

ORDER
Con, (Init, Proc, DoFinal)+

CONSTRAINTS
length[plainText] >= plainTextOffset + plainTextLen;
length[cipherText] >= cipherTextOffset;
plainTextOffset >= 0;
plainTextLen > 0;
cipherTextOffset >= 0;

REQUIRES
generatedGCMBlockCipher[cipher];
generatedCipherParams[params];

ENSURES
encrypted[cipherText];
FORBIDDEN
BufferedBlockCipher(org.bouncycastle.crypto.BlockCipher);
7 changes: 5 additions & 2 deletions BouncyCastle/src/CBCBlockCipher.crysl
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ SPEC org.bouncycastle.crypto.modes.CBCBlockCipher

OBJECTS
org.bouncycastle.crypto.BlockCipher engine;

FORBIDDEN
CBCBlockCipher(org.bouncycastle.crypto.BlockCipher);

EVENTS
c1: CBCBlockCipher(engine);
c1: newInstance(engine);
Con := c1;

//No need to specify the order, must be wrapped in PaddedBufferedCipher!
// No need to specify the order, must be wrapped in PaddedBufferedCipher!
ORDER
Con

Expand Down
5 changes: 4 additions & 1 deletion BouncyCastle/src/CCMBlockCipher.crysl
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ OBJECTS
int cipherTextOffset;

boolean isEncryption;

FORBIDDEN
CCMBlockCipher(org.bouncycastle.crypto.BlockCipher);

EVENTS
c1: CCMBlockCipher(engine);
c1: newInstance(engine);
Con := c1;

i1: init(isEncryption, params);
Expand Down
48 changes: 48 additions & 0 deletions BouncyCastle/src/DefaultBufferedBlockCipher.crysl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
SPEC org.bouncycastle.crypto.DefaultBufferedBlockCipher

OBJECTS
org.bouncycastle.crypto.BlockCipher cipher;
org.bouncycastle.crypto.CipherParameters params;

byte plainTextByte;
byte[] plainText;
int plainTextOffset;
int plainTextLen;

byte[] cipherText;
int cipherTextOffset;

boolean isEncryption;

EVENTS
c1: DefaultBufferedBlockCipher(cipher);
Con := c1;

i1: init(isEncryption, params);
Init := i1;

// @return the number of output bytes copied to out.
p1: processByte(plainTextByte, cipherText, cipherTextOffset);
p2: processBytes(plainText, plainTextOffset, plainTextLen, cipherText, cipherTextOffset);
Proc := p1 | p2;

// @return the number of output bytes copied to out.
df1: doFinal(cipherText, cipherTextOffset);
DoFinal := df1;

ORDER
Con, (Init, Proc, DoFinal)+

CONSTRAINTS
length[plainText] >= plainTextOffset + plainTextLen;
length[cipherText] >= cipherTextOffset;
plainTextOffset >= 0;
plainTextLen > 0;
cipherTextOffset >= 0;

REQUIRES
generatedGCMBlockCipher[cipher];
generatedCipherParams[params];

ENSURES
encrypted[cipherText];
5 changes: 4 additions & 1 deletion BouncyCastle/src/GCMBlockCipher.crysl
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ OBJECTS
int cipherTextOffset;

boolean isEncryption;

FORBIDDEN
GCMBlockCipher(org.bouncycastle.crypto.BlockCipher);

EVENTS
c1: GCMBlockCipher(engine);
c1: newInstance(engine);
Con := c1;

i1: init(isEncryption, params);
Expand Down
2 changes: 1 addition & 1 deletion BouncyCastle/src/SHA256Digest.crysl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ CONSTRAINTS
inputBytesOffset >= 0;
inputBytesLen > 0;
length[outputBytes] >= outputBytesOffset;
outputBytesOffset > 0;
outputBytesOffset >= 0;

REQUIRES
generatedSHA256Digest[digest];
Expand Down
9 changes: 5 additions & 4 deletions BouncyCastle/src/SICBlockCipher.crysl
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
SPEC org.bouncycastle.crypto.modes.SICBlockCipher

OBJECTS

org.bouncycastle.crypto.BlockCipher engine;

FORBIDDEN
SICBlockCipher(org.bouncycastle.crypto.BlockCipher);

EVENTS
c1: SICBlockCipher(engine);
c1: newInstance(engine);
Con := c1;

//No need to specify the order, must be wrapped in BufferedCipher

// No need to specify the order, must be wrapped in BufferedCipher
ORDER
Con

Expand Down
14 changes: 14 additions & 0 deletions JavaCryptographicArchitecture/src/PrivateKey.crysl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
SPEC java.security.PrivateKey

OBJECTS
byte[] keyMaterial;

EVENTS
ge1: keyMaterial = getEncoded();
GetEnc := ge1;

ORDER
GetEnc*

ENSURES
preparedKeyMaterial[keyMaterial] after GetEnc;
14 changes: 14 additions & 0 deletions JavaCryptographicArchitecture/src/PublicKey.crysl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
SPEC java.security.PublicKey

OBJECTS
byte[] keyMaterial;

EVENTS
ge1: keyMaterial = getEncoded();
GetEnc := ge1;

ORDER
GetEnc*

ENSURES
preparedKeyMaterial[keyMaterial] after GetEnc;