summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anytun.org>2017-09-17 15:15:31 +0200
committerChristian Pointner <equinox@anytun.org>2017-09-17 15:15:31 +0200
commit66da93301d7e6b3cc5d5301600df85b34423da47 (patch)
tree59d563335e164c5de3f53e30cd0dc5c8b0795195
parentadded some interfaces and a skeleton squence window (diff)
minor refactoring
-rw-r--r--satp/crypto-kd.go43
1 files 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")
+}