| 123456789101112131415161718192021222324252627282930313233343536 |
- //
- // HashProtocol.swift
- // CryptoSwift
- //
- // Created by Marcin Krzyzanowski on 17/08/14.
- // Copyright (c) 2014 Marcin Krzyzanowski. All rights reserved.
- //
- internal protocol HashProtocol: class {
- var message: Array<UInt8> { get }
-
- /** Common part for hash calculation. Prepare header data. */
- func prepare(_ len:Int) -> Array<UInt8>
- }
- extension HashProtocol {
-
- func prepare(_ len:Int) -> Array<UInt8> {
- var tmpMessage = message
-
- // Step 1. Append Padding Bits
- tmpMessage.append(0x80) // append one bit (UInt8 with one bit) to message
-
- // append "0" bit until message length in bits ≡ 448 (mod 512)
- var msgLength = tmpMessage.count
- var counter = 0
-
- while msgLength % len != (len - 8) {
- counter += 1
- msgLength += 1
- }
- tmpMessage += Array<UInt8>(repeating: 0, count: counter)
- return tmpMessage
- }
- }
|