@@ -43,6 +43,38 @@ public class PKCS1VectorGenerator {
4343 */
4444 public static byte [][] generatePkcs1Vectors (RSAPublicKey publicKey , BleichenbacherCommandConfig .Type type ) {
4545
46+ // compute the number of all vectors that are being generated
47+ int rsaKeyLength = publicKey .getModulus ().bitLength () / 8 ;
48+ int vectorSize = STATIC_VECTOR_SIZE ;
49+ if (type == BleichenbacherCommandConfig .Type .FULL ) {
50+ vectorSize += rsaKeyLength - 2 ;
51+ }
52+ byte [][] plainPaddedKeys = generatePlainPkcs1Vectors (publicKey , type );
53+
54+ try {
55+ Cipher rsa = Cipher .getInstance ("RSA/NONE/NoPadding" );
56+ rsa .init (Cipher .ENCRYPT_MODE , publicKey );
57+ byte [][] encryptedKeys = new byte [vectorSize ][];
58+ // encrypt all the padded keys
59+ for (int i = 0 ; i < encryptedKeys .length ; i ++) {
60+ encryptedKeys [i ] = rsa .doFinal (plainPaddedKeys [i ]);
61+ }
62+
63+ return encryptedKeys ;
64+ } catch (BadPaddingException | IllegalBlockSizeException | InvalidKeyException | NoSuchAlgorithmException
65+ | NoSuchPaddingException ex ) {
66+ throw new ConfigurationException ("The different PKCS#1 attack vectors could not be generated." , ex );
67+ }
68+ }
69+
70+ /**
71+ * Generates different plain PKCS1 vectors
72+ *
73+ * @param publicKey
74+ * @param type
75+ * @return
76+ */
77+ public static byte [][] generatePlainPkcs1Vectors (RSAPublicKey publicKey , BleichenbacherCommandConfig .Type type ) {
4678 // we do not need secure random here
4779 Random random = new Random ();
4880 byte [] keyBytes = new byte [HandshakeByteLength .PREMASTER_SECRET ];
@@ -74,21 +106,7 @@ public static byte[][] generatePkcs1Vectors(RSAPublicKey publicKey, Bleichenbach
74106 byte [][] additionalPaddedKeys = getEK_DifferentPositionsOf0x00 (rsaKeyLength , keyBytes );
75107 System .arraycopy (additionalPaddedKeys , 0 , plainPaddedKeys , STATIC_VECTOR_SIZE , additionalPaddedKeys .length );
76108 }
77-
78- try {
79- Cipher rsa = Cipher .getInstance ("RSA/NONE/NoPadding" );
80- rsa .init (Cipher .ENCRYPT_MODE , publicKey );
81- byte [][] encryptedKeys = new byte [vectorSize ][];
82- // encrypt all the padded keys
83- for (int i = 0 ; i < encryptedKeys .length ; i ++) {
84- encryptedKeys [i ] = rsa .doFinal (plainPaddedKeys [i ]);
85- }
86-
87- return encryptedKeys ;
88- } catch (BadPaddingException | IllegalBlockSizeException | InvalidKeyException | NoSuchAlgorithmException
89- | NoSuchPaddingException ex ) {
90- throw new ConfigurationException ("The different PKCS#1 attack vectors could not be generated." , ex );
91- }
109+ return plainPaddedKeys ;
92110 }
93111
94112 /**
0 commit comments