Skip to content

Commit

Permalink
(MINOR-BC) update: Replace deprecated constructors with static instan…
Browse files Browse the repository at this point in the history
…tiation calls
  • Loading branch information
smeyer198 committed Dec 7, 2023
1 parent 5c95e47 commit 3c3994b
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 58 deletions.
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
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
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

0 comments on commit 3c3994b

Please sign in to comment.