hmac.scm 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. ;;; guile-gcrypt --- crypto tooling for guile
  2. ;;; Copyright © 2019 Ludovic Courtès <ludo@gnu.org>
  3. ;;;
  4. ;;; This file is part of guile-gcrypt.
  5. ;;;
  6. ;;; guile-gcrypt is free software; you can redistribute it and/or
  7. ;;; modify it under the terms of the GNU Lesser General Public License
  8. ;;; as published by the Free Software Foundation; either version 3 of
  9. ;;; the License, or (at your option) any later version.
  10. ;;;
  11. ;;; guile-gcrypt is distributed in the hope that it will be useful, but
  12. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. ;;; Lesser General Public License for more details.
  15. ;;;
  16. ;;; You should have received a copy of the GNU Lesser General Public License
  17. ;;; along with guile-gcrypt. If not, see <http://www.gnu.org/licenses/>.
  18. (define-module (gcrypt hmac)
  19. #:use-module ((gcrypt mac) #:prefix mac:)
  20. #:export (sign-data
  21. sign-data-base64
  22. verify-sig
  23. verify-sig-base64
  24. gen-signing-key))
  25. ;;; Code:
  26. ;;;
  27. ;;; This module is deprecated and provided for compatibility with
  28. ;;; Guile-Gcrypt 0.1.0. Use (gcrypt mac) instead.
  29. ;;;
  30. ;;; Commentary:
  31. (define (symbol->algorithm symbol)
  32. "Convert SYMBOL (e.g., 'sha256) to the corresponding MAC algorithm."
  33. ;; Note: In 0.1.0, only a few hmac algorithms were supported, without the
  34. ;; 'hmac-' prefix.
  35. (mac:lookup-mac-algorithm (symbol-append 'hmac- symbol)))
  36. (define* (sign-data key data #:key (algorithm 'sha512))
  37. "Signs DATA with KEY for ALGORITHM. Returns a bytevector."
  38. (mac:sign-data key data
  39. #:algorithm (symbol->algorithm algorithm)))
  40. (define* (sign-data-base64 key data #:key (algorithm 'sha512))
  41. "Signs DATA with KEY for ALGORITHM. Returns a bytevector."
  42. (mac:sign-data-base64 key data
  43. #:algorithm
  44. (symbol->algorithm algorithm)))
  45. (define* (verify-sig key data sig #:key (algorithm 'sha512))
  46. "Verify that DATA with KEY matches previous signature SIG for ALGORITHM."
  47. (mac:valid-signature? key data sig
  48. #:algorithm (symbol->algorithm algorithm)))
  49. (define* (verify-sig-base64 key data sig #:key (algorithm 'sha512))
  50. "Verify that DATA with KEY matches previous signature SIG for ALGORITHM."
  51. (mac:valid-base64-signature? key data sig
  52. #:algorithm (symbol->algorithm algorithm)))
  53. (define gen-signing-key
  54. mac:generate-signing-key)