コード例 #1
0
ファイル: TlsPrfGenerator.java プロジェクト: ronshapiro/j86
 static byte[] concat(byte[] b1, byte[] b2) {
   int n1 = b1.length;
   int n2 = b2.length;
   byte[] b = new byte[n1 + n2];
   System.arraycopy(b1, 0, b, 0, n1);
   System.arraycopy(b2, 0, b, n1, n2);
   return b;
 }
コード例 #2
0
ファイル: P11RSACipher.java プロジェクト: ronshapiro/j86
 private byte[] doFinal() throws BadPaddingException, IllegalBlockSizeException {
   byte[] t = new byte[2048];
   int n = implDoFinal(t, 0, t.length);
   byte[] out = new byte[n];
   System.arraycopy(t, 0, out, 0, n);
   return out;
 }
コード例 #3
0
ファイル: P11RSACipher.java プロジェクト: ronshapiro/j86
 // see JCE spec
 protected byte[] engineDoFinal(byte[] in, int inOfs, int inLen)
     throws IllegalBlockSizeException, BadPaddingException {
   implUpdate(in, inOfs, inLen);
   int n = implDoFinal(buffer, 0, buffer.length);
   byte[] out = new byte[n];
   System.arraycopy(buffer, 0, out, 0, n);
   return out;
 }
コード例 #4
0
ファイル: P11RSACipher.java プロジェクト: ronshapiro/j86
 private int implDoFinal(byte[] out, int outOfs, int outLen)
     throws BadPaddingException, IllegalBlockSizeException {
   if (bufOfs > maxInputSize) {
     throw new IllegalBlockSizeException(
         "Data must not be longer " + "than " + maxInputSize + " bytes");
   }
   try {
     ensureInitialized();
     PKCS11 p11 = token.p11;
     int n;
     switch (mode) {
       case MODE_ENCRYPT:
         n = p11.C_Encrypt(session.id(), buffer, 0, bufOfs, out, outOfs, outLen);
         break;
       case MODE_DECRYPT:
         n = p11.C_Decrypt(session.id(), buffer, 0, bufOfs, out, outOfs, outLen);
         break;
       case MODE_SIGN:
         byte[] tmpBuffer = new byte[bufOfs];
         System.arraycopy(buffer, 0, tmpBuffer, 0, bufOfs);
         tmpBuffer = p11.C_Sign(session.id(), tmpBuffer);
         if (tmpBuffer.length > outLen) {
           throw new BadPaddingException("Output buffer too small");
         }
         System.arraycopy(tmpBuffer, 0, out, outOfs, tmpBuffer.length);
         n = tmpBuffer.length;
         break;
       case MODE_VERIFY:
         n = p11.C_VerifyRecover(session.id(), buffer, 0, bufOfs, out, outOfs, outLen);
         break;
       default:
         throw new ProviderException("internal error");
     }
     return n;
   } catch (PKCS11Exception e) {
     throw (BadPaddingException) new BadPaddingException("doFinal() failed").initCause(e);
   } finally {
     initialized = false;
     session = token.releaseSession(session);
   }
 }
コード例 #5
0
ファイル: P11RSACipher.java プロジェクト: ronshapiro/j86
 private void implUpdate(byte[] in, int inOfs, int inLen) {
   try {
     ensureInitialized();
   } catch (PKCS11Exception e) {
     throw new ProviderException("update() failed", e);
   }
   if ((inLen == 0) || (in == null)) {
     return;
   }
   if (bufOfs + inLen > maxInputSize) {
     bufOfs = maxInputSize + 1;
     return;
   }
   System.arraycopy(in, inOfs, buffer, bufOfs, inLen);
   bufOfs += inLen;
 }