Skip to content

Commit

Permalink
Merge branch 'release/1.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
tobihagemann committed Jan 17, 2022
2 parents 9bf1bec + 77eba0b commit ac2d182
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 14 additions & 1 deletion Sources/CryptomatorCryptoLib/Masterkey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,27 @@ public class Masterkey {
return createFromRaw(aesMasterKey: aesMasterKey, macMasterKey: macMasterKey)
}

/**
Creates masterkey from raw bytes.

- Parameter rawKey: Key combination of `aesMasterKey` (used for encryption of file specific keys) and `macMasterKey` (used for file authentication).
- Returns: New masterkey instance using the keys from the supplied raw bytes.
*/
public static func createFromRaw(rawKey: [UInt8]) -> Masterkey {
assert(rawKey.count == 2 * kCCKeySizeAES256)
let aesMasterkey = Array(rawKey[0 ..< kCCKeySizeAES256])
let macMasterKey = Array(rawKey[kCCKeySizeAES256...])
return createFromRaw(aesMasterKey: aesMasterkey, macMasterKey: macMasterKey)
}

/**
Creates masterkey from raw bytes.

- Parameter aesMasterKey: Key used for encryption of file specific keys.
- Parameter macMasterKey: Key used for file authentication.
- Returns: New masterkey instance using the keys from the supplied raw bytes.
*/
public static func createFromRaw(aesMasterKey: [UInt8], macMasterKey: [UInt8]) -> Masterkey {
static func createFromRaw(aesMasterKey: [UInt8], macMasterKey: [UInt8]) -> Masterkey {
assert(aesMasterKey.count == kCCKeySizeAES256)
assert(macMasterKey.count == kCCKeySizeAES256)
return Masterkey(aesMasterKey: aesMasterKey, macMasterKey: macMasterKey)
Expand Down
2 changes: 1 addition & 1 deletion Tests/CryptomatorCryptoLibTests/MasterkeyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class MasterkeyTests: XCTestCase {
func testCreateFromRaw() throws {
let aesMasterKey = [UInt8](repeating: 0x77, count: 32)
let macMasterKey = [UInt8](repeating: 0x55, count: 32)
let masterkey = Masterkey.createFromRaw(aesMasterKey: aesMasterKey, macMasterKey: macMasterKey)
let masterkey = Masterkey.createFromRaw(rawKey: aesMasterKey + macMasterKey)
XCTAssertEqual(aesMasterKey, masterkey.aesMasterKey)
XCTAssertEqual(macMasterKey, masterkey.macMasterKey)
}
Expand Down

0 comments on commit ac2d182

Please sign in to comment.