-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
330 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package cmac | ||
|
||
import ( | ||
"crypto/subtle" | ||
) | ||
|
||
func shift(dst, src []byte) int { | ||
var b, bit byte | ||
for i := len(src) - 1; i >= 0; i-- { // a range would be nice | ||
bit = src[i] >> 7 | ||
dst[i] = src[i]<<1 | b | ||
b = bit | ||
} | ||
|
||
return int(b) | ||
} | ||
|
||
// XOR the contents of b into a in-place | ||
func xor(a, b []byte) { | ||
subtle.XORBytes(a, a, b) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package cmac | ||
|
||
import ( | ||
"crypto/cipher" | ||
"crypto/subtle" | ||
) | ||
|
||
// Sum computes the CMAC checksum with the given tagsize of msg using the cipher.Block. | ||
func Sum(msg []byte, c cipher.Block, tagsize int) ([]byte, error) { | ||
h, err := NewWithTagSize(c, tagsize) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
h.Write(msg) | ||
return h.Sum(nil), nil | ||
} | ||
|
||
// Verify computes the CMAC checksum with the given tagsize of msg and compares | ||
// it with the given mac. This functions returns true if and only if the given mac | ||
// is equal to the computed one. | ||
func Verify(mac, msg []byte, c cipher.Block, tagsize int) bool { | ||
sum, err := Sum(msg, c, tagsize) | ||
if err != nil { | ||
return false | ||
} | ||
|
||
return subtle.ConstantTimeCompare(mac, sum) == 1 | ||
} |
Oops, something went wrong.