Skip to content

Commit

Permalink
[pa] add protos / stub for DeriveSymmetricKey RPC
Browse files Browse the repository at this point in the history
This adds protos and a function stub for the `DeriveSymmetricKey` RPC call
which the PA must implement to support OpenTitan A1 provisioning flows.
This RPC will support:
- OpenTitan lifecycle token generation (in raw and hashed form)
- OpenTitan wafer authentication secret generation.

This partially addresses #4.

Signed-off-by: Tim Trippel <ttrippel@google.com>
  • Loading branch information
timothytrippel committed Sep 27, 2024
1 parent 2cd6c95 commit 0536d38
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
61 changes: 61 additions & 0 deletions src/pa/proto/pa.proto
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ service ProvisioningApplianceService {
returns (CreateKeyAndCertResponse) {}
rpc EndorseCerts(EndorseCertsRequest)
returns (EndorseCertsResponse) {}
rpc DeriveSymmetricKey(DeriveSymmetricKeyRequest)
returns (DeriveSymmetricKeyResponse) {}
rpc SendDeviceRegistrationPayload(RegistrationRequest)
returns (RegistrationResponse) {}
}
Expand All @@ -44,6 +46,65 @@ message EndorseCertsResponse {
repeated crypto.cert.Certificate certs = 1;
}

// Symmetric key seed type (seed is provisioned into HSM).
enum SymmetricKeySeed {
// Unspecified.
SYMMETRIC_KEY_SEED_UNSPECIFIED = 0;
// Low Security: seed is rotated infrequently.
SYMMETRIC_KEY_SEED_LOW_SECURITY = 1;
// High Security: seed is rotated frequently.
SYMMETRIC_KEY_SEED_HIGH_SECURITY = 2;
}

// Symmetric key type.
enum SymmetricKeyType {
// Unspecified.
SYMMETRIC_KEY_TYPE_UNSPECIFIED = 0;
// Raw.
//
// This format is used when the raw plaintext key must be generated.
SYMMETRIC_KEY_TYPE_RAW = 1;
// Hashed.
//
// This format is used when the cSHAKE128 hashed (with "LC_CTRL" customization
// string) form of the key needs to be generated. This type supports
// provisioning of OpenTitan lifecycle tokens, which are programmed into a
// device's OTP memory in this form.
//
// protolint:disable:next MAX_LINE_LENGTH
// See https://opentitan.org/book/hw/ip/lc_ctrl/doc/theory_of_operation.html#token-hashing-mechanism
// for more details.
SYMMETRIC_KEY_TYPE_HASHED_OT_LC_TOKEN = 2;
}

// Symmetric key size.
enum SymmetricKeySize {
// Unspecified.
SYMMETRIC_KEY_SIZE_UNSPECIFIED = 0;
// 128 bits.
SYMMETRIC_KEY_SIZE_128_BITS = 1;
// 256 bits.
SYMMETRIC_KEY_SIZE_256_BITS = 2;
}

// Derive symmetric key request.
message DeriveSymmetricKeyRequest{
// Symmetric key seed to use. Required.
SymmetricKeySeed seed = 1;
// Symmetric key type to generate. Required.
SymmetricKeyType type = 2;
// Symmetric key size. Required.
SymmetricKeySize size = 3;
// Diversifier string to use in KDF operation. Required.
string diversifier = 4;
}

// Derive symmetric key response.
message DeriveSymmetricKeyResponse{
// Key bytes. Size is provided in the request.
bytes key = 1;
}

// Create key and endorsement certificates request.
// The `sku` fields is used as an unique key to
// implement the specific key gen and endorsement certificate flow for a
Expand Down
9 changes: 9 additions & 0 deletions src/pa/services/pa.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@ func (s *server) EndorseCerts(ctx context.Context, request *pbp.EndorseCertsRequ
return nil, nil
}

// DeriveSymmetricKey generates a symmetric key from a seed (pre-provisioned in
// the SPM/HSM) and diversifier string.
func (s *server) DeriveSymmetricKey(ctx context.Context, request *pbp.DeriveSymmetricKeyRequest) (*pbp.DeriveSymmetricKeyResponse, error) {
log.Printf("In PA - Recieved DeriveSymmetricKey request with diversifier string: %s", request.Diversifier)

// TODO(#4) implement backend operations.
return nil, nil
}

// SendDeviceRegistrationPayload registers a new device record to the local MySql DB.
func (s *server) SendDeviceRegistrationPayload(ctx context.Context, request *pbp.RegistrationRequest) (*pbp.RegistrationResponse, error) {
log.Printf("In PA - Received SendDeviceRegistrationPayload request with DeviceID: %v", request.DeviceRecord.Id)
Expand Down

0 comments on commit 0536d38

Please sign in to comment.