what-the-bank/sources/org/bouncycastle/jcajce/provider/symmetric/GcmSpecUtil.java

64 lines
2.7 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
package org.bouncycastle.jcajce.provider.symmetric;
import java.security.spec.AlgorithmParameterSpec;
import java.security.spec.InvalidParameterSpecException;
import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.asn1.cms.GCMParameters;
import org.bouncycastle.util.Integers;
/* loaded from: classes6.dex */
class GcmSpecUtil {
static final Class gcmSpecClass = lookup("javax.crypto.spec.GCMParameterSpec");
private static Class lookup(String str) {
try {
return GcmSpecUtil.class.getClassLoader().loadClass(str);
} catch (Exception unused) {
return null;
}
}
/* JADX INFO: Access modifiers changed from: package-private */
public static boolean isGcmSpec(AlgorithmParameterSpec algorithmParameterSpec) {
Class cls = gcmSpecClass;
return cls != null && cls.isInstance(algorithmParameterSpec);
}
/* JADX INFO: Access modifiers changed from: package-private */
public static boolean isGcmSpec(Class cls) {
return gcmSpecClass == cls;
}
/* JADX INFO: Access modifiers changed from: package-private */
public static boolean gcmSpecExists() {
return gcmSpecClass != null;
}
/* JADX INFO: Access modifiers changed from: package-private */
public static AlgorithmParameterSpec extractGcmSpec(ASN1Primitive aSN1Primitive) throws InvalidParameterSpecException {
try {
GCMParameters gCMParameters = GCMParameters.getInstance(aSN1Primitive);
return (AlgorithmParameterSpec) gcmSpecClass.getConstructor(Integer.TYPE, byte[].class).newInstance(Integers.valueOf(gCMParameters.getIcvLen() << 3), gCMParameters.getNonce());
} catch (NoSuchMethodException unused) {
throw new InvalidParameterSpecException("No constructor found!");
} catch (Exception e) {
StringBuilder sb = new StringBuilder("Construction failed: ");
sb.append(e.getMessage());
throw new InvalidParameterSpecException(sb.toString());
}
}
/* JADX INFO: Access modifiers changed from: package-private */
public static GCMParameters extractGcmParameters(AlgorithmParameterSpec algorithmParameterSpec) throws InvalidParameterSpecException {
try {
Class cls = gcmSpecClass;
return new GCMParameters((byte[]) cls.getDeclaredMethod("getIV", new Class[0]).invoke(algorithmParameterSpec, new Object[0]), ((Integer) cls.getDeclaredMethod("getTLen", new Class[0]).invoke(algorithmParameterSpec, new Object[0])).intValue() / 8);
} catch (Exception unused) {
throw new InvalidParameterSpecException("Cannot process GCMParameterSpec");
}
}
GcmSpecUtil() {
}
}