Class PrfBasedDeriverKeyManager
- java.lang.Object
-
- com.google.crypto.tink.keyderivation.internal.PrfBasedDeriverKeyManager
-
- All Implemented Interfaces:
KeyManager<java.lang.Void>
public final class PrfBasedDeriverKeyManager extends java.lang.Object implements KeyManager<java.lang.Void>
com.google.crypto.tink.internal.KeyTypeManagerforPrfBasedDeriverKey.This is implemented directly as a KeyManager. Usually, we use
LegacyKeyManagerImplto provide an implementation of a KeyManager based on the individual registries based on the key objects. However, at the moment for key derivation this does not work.The reason is that the KeysetHandle still generates new keys by going through the KeyManagers (instead of going directly to the key creation registry). I don't want to change this right now -- it would require some fallback code which is always brittle.
Unfortunately, implement the required behavior of the KeyManager based on the KeyCreation registry is not generic.
Usually, the behavior of the key manager is simply this: assume that the input to generateNewKey() is a serialization with OutputPrefixType = RAW, and build the corresponding parameter serialization. Then, parse this, and give this to the key creation registry.
For key creation, the behavior is slightly different: the serialization of key derivation parameters has been defined to always satisfy that the outer OutputPrefixType is equal to the one given in the proto PrfBasedDeriverKeyFormat, field prf_key_template. Hence we cannot assume raw -- instead, we have to parse it and use this one.
Similar things hold for the creating a primitive from a Key -- but here Tink already uses the PrimitiveCreationRegistry fully, so we don't need to worry about it here. Instead, we just throw when these functions are called.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleandoesSupport(java.lang.String typeUrl)Returns true iff this KeyManager supports key type identified bytypeUrl.java.lang.StringgetKeyType()Returns the type URL that identifies the key type of keys managed by this KeyManager.java.lang.VoidgetPrimitive(com.google.protobuf.ByteString serializedKey)Constructs an instance of P for the key given inserializedKey, which must be a serialized key protocol buffer handled by this manager.java.lang.VoidgetPrimitive(com.google.protobuf.MessageLite key)Constructs an instance of P for the key given inkey.java.lang.Class<java.lang.Void>getPrimitiveClass()Returns the primitive class object of the P.intgetVersion()Returns the version number of this KeyManager.com.google.protobuf.MessageLitenewKey(com.google.protobuf.ByteString serializedKeyFormat)Generates a new key according to specification inserializedKeyFormat, which must be a serialized key format protocol buffer handled by this manager.com.google.protobuf.MessageLitenewKey(com.google.protobuf.MessageLite keyFormat)Generates a new key according to specification inkeyFormat.com.google.crypto.tink.proto.KeyDatanewKeyData(com.google.protobuf.ByteString serializedKeyFormat)Generates a newKeyDataaccording to specification inserializedKeyFormat.static voidregister(boolean newKeyAllowed)
-
-
-
Method Detail
-
getPrimitive
public java.lang.Void getPrimitive(com.google.protobuf.ByteString serializedKey) throws java.security.GeneralSecurityExceptionDescription copied from interface:KeyManagerConstructs an instance of P for the key given inserializedKey, which must be a serialized key protocol buffer handled by this manager.For primitives of type
Mac,Aead,PublicKeySign,PublicKeyVerify,DeterministicAead,HybridEncrypt, andHybridDecryptthis should be a primitive which ignores the output prefix and assumes "RAW".- Specified by:
getPrimitivein interfaceKeyManager<java.lang.Void>- Returns:
- the new constructed P
- Throws:
java.security.GeneralSecurityException- if the key given inserializedKeyis corrupted or not supported
-
getPrimitive
public final java.lang.Void getPrimitive(com.google.protobuf.MessageLite key) throws java.security.GeneralSecurityExceptionDescription copied from interface:KeyManagerConstructs an instance of P for the key given inkey.For primitives of type
Mac,Aead,PublicKeySign,PublicKeyVerify,DeterministicAead,HybridEncrypt, andHybridDecryptthis should be a primitive which ignores the output prefix and assumes "RAW".This method is not used by Tink. It does not need to be implemented.
- Specified by:
getPrimitivein interfaceKeyManager<java.lang.Void>- Returns:
- the new constructed P
- Throws:
java.security.GeneralSecurityException- if the key given inkeyis corrupted or not supported
-
newKey
public final com.google.protobuf.MessageLite newKey(com.google.protobuf.ByteString serializedKeyFormat) throws java.security.GeneralSecurityExceptionDescription copied from interface:KeyManagerGenerates a new key according to specification inserializedKeyFormat, which must be a serialized key format protocol buffer handled by this manager.This method is not used by Tink anymore. It does not need to be implemented.
- Specified by:
newKeyin interfaceKeyManager<java.lang.Void>- Returns:
- the new generated key
- Throws:
java.security.GeneralSecurityException- if the specified format is wrong or not supported
-
newKey
public final com.google.protobuf.MessageLite newKey(com.google.protobuf.MessageLite keyFormat) throws java.security.GeneralSecurityExceptionDescription copied from interface:KeyManagerGenerates a new key according to specification inkeyFormat.This method is only used by
Registry.newKeywhich is deprecated and not used by Tink anymore. This method does not need to be implemented.- Specified by:
newKeyin interfaceKeyManager<java.lang.Void>- Returns:
- the new generated key
- Throws:
java.security.GeneralSecurityException- if the specified format is wrong or not supported
-
doesSupport
public final boolean doesSupport(java.lang.String typeUrl)
Description copied from interface:KeyManagerReturns true iff this KeyManager supports key type identified bytypeUrl.This method is not used by Tink anymore. It does not need to be implemented.
- Specified by:
doesSupportin interfaceKeyManager<java.lang.Void>
-
getKeyType
public final java.lang.String getKeyType()
Description copied from interface:KeyManagerReturns the type URL that identifies the key type of keys managed by this KeyManager.- Specified by:
getKeyTypein interfaceKeyManager<java.lang.Void>
-
getVersion
public int getVersion()
Description copied from interface:KeyManagerReturns the version number of this KeyManager.This method is not used by Tink anymore. It does not need to be implemented.
- Specified by:
getVersionin interfaceKeyManager<java.lang.Void>
-
newKeyData
public final com.google.crypto.tink.proto.KeyData newKeyData(com.google.protobuf.ByteString serializedKeyFormat) throws java.security.GeneralSecurityExceptionDescription copied from interface:KeyManagerGenerates a newKeyDataaccording to specification inserializedKeyFormat.- Specified by:
newKeyDatain interfaceKeyManager<java.lang.Void>- Returns:
- the new generated key
- Throws:
java.security.GeneralSecurityException- if the specified format is wrong or not supported
-
getPrimitiveClass
public final java.lang.Class<java.lang.Void> getPrimitiveClass()
Description copied from interface:KeyManagerReturns the primitive class object of the P. Should be implemented asreturn P.class;when implementing a key manager for primitive {$code P}.- Specified by:
getPrimitiveClassin interfaceKeyManager<java.lang.Void>- Returns:
P.class
-
register
public static void register(boolean newKeyAllowed) throws java.security.GeneralSecurityException- Throws:
java.security.GeneralSecurityException
-
-