From 66da93301d7e6b3cc5d5301600df85b34423da47 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sun, 17 Sep 2017 15:15:31 +0200 Subject: minor refactoring --- satp/crypto-kd.go | 43 ++++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/satp/crypto-kd.go b/satp/crypto-kd.go index 208c4a9..b2b63df 100644 --- a/satp/crypto-kd.go +++ b/satp/crypto-kd.go @@ -35,21 +35,42 @@ type KeyUsage int type Label uint32 const ( - KeyLeft KeyDirection = iota - KeyRight + DirLeft KeyDirection = iota + DirRight - Encrypt KeyUsage = iota - Salt - Auth + UsageEncryptKey KeyUsage = iota + UsageEncryptSalt + UsageAuthKey - LabelLeftEncrypt = 0x356A192B - LabelRightEncrypt = 0xDA4B9237 - LabelLeftSalt = 0x77DE68DA - LabelRightSalt = 0x1B645389 - LabelLeftAuth = 0xAC3478D6 - LabelRightAuth = 0xC1DFD96E + LabelLeftEncrypt = 0x356A192B + LabelRightEncrypt = 0xDA4B9237 + LabelLeftEncryptSalt = 0x77DE68DA + LabelRightEncryptSalt = 0x1B645389 + LabelLeftAuthKey = 0xAC3478D6 + LabelRightAuthKey = 0xC1DFD96E ) type KeyDerivation interface { Generate(dir KeyDirection, usage KeyUsage, sequenceNumber uint32) ([]byte, error) } + +func getLabel(dir KeyDirection, usage KeyUsage) uint32 { + switch usage { + case UsageEncryptKey: + if dir == DirLeft { + return LabelLeftEncrypt + } + return LabelRightEncrypt + case UsageEncryptSalt: + if dir == DirLeft { + return LabelLeftEncryptSalt + } + return LabelRightEncryptSalt + case UsageAuthKey: + if dir == DirLeft { + return LabelLeftAuthKey + } + return LabelRightAuthKey + } + panic("Key-derivation: invalid direction and/or usage") +} -- cgit v1.2.3