{"size": 1538, "ext": "scrbl", "max_stars_repo_path": "sha/sha.scrbl", "max_stars_repo_name": "greghendershott/sha", "max_stars_repo_stars_event_min_datetime": "2015-04-24T16:25:11.000Z", "max_stars_repo_stars_event_max_datetime": "2020-05-25T22:13:15.000Z", "max_issues_repo_path": "sha/sha.scrbl", "max_issues_repo_name": "greghendershott/sha", "max_issues_repo_issues_event_min_datetime": "2018-11-21T15:02:44.000Z", "max_issues_repo_issues_event_max_datetime": "2018-11-21T16:09:57.000Z", "max_forks_repo_path": "sha/sha.scrbl", "max_forks_repo_name": "greghendershott/sha", "max_forks_repo_forks_event_min_datetime": "2017-09-15T07:47:16.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-15T22:09:39.000Z"}
{"max_stars_count": 4, "max_issues_count": 2, "max_forks_count": 2, "avg_line_length": 17.4772727273, "max_line_length": 77, "alphanum_fraction": 0.6703511053}
#lang scribble/manual

@(require (for-label racket))

@title{SHA and SHA-2}

@defmodule[sha]

Provides a Racket interface to the OpenSSL implementation of SHA-1 and SHA-2.

SHA-2 includes four flavors: SHA-224, SHA-256, SHA-384, and SHA-512.


@section{SHA}

@deftogether[(

@defproc[(sha1 [bstr bytes?]) sha1?]
@defproc[(sha224 [bstr bytes?]) sha224?]
@defproc[(sha256 [bstr bytes?]) sha256?]
@defproc[(sha384 [bstr bytes?]) sha384?]
@defproc[(sha512 [bstr bytes?]) sha512?]

)]{

Calculate the SHA hash of @racket[bstr].

}


@section{HMAC-SHA}

@deftogether[(

@defproc[(hmac-sha1 [key bytes?][data bytes?]) sha1?]
@defproc[(hmac-sha224 [key bytes?][data bytes?]) sha224?]
@defproc[(hmac-sha256 [key bytes?][data bytes?]) sha256?]
@defproc[(hmac-sha384 [key bytes?][data bytes?]) sha384?]
@defproc[(hmac-sha512 [key bytes?][data bytes?]) sha512?]

)]{

HMAC-SHA encode @racket[key] and @racket[data].

}


@section{Hex string}

@defproc[(bytes->hex-string [bstr bytes?]) string?]{

Convert @racket[bstr] to a hexadecimal string represention.

}


@section{Predicates for contracts}

@defproc[(sha1? [x any/c]) boolean?]{

Is @racket[x] a @racket[bytes?] of length 20?

}

@defproc[(sha224? [x any/c]) boolean?]{

Is @racket[x] a @racket[bytes?] of length 28?

}

@defproc[(sha256? [x any/c]) boolean?]{

Is @racket[x] a @racket[bytes?] of length 32?

}

@defproc[(sha384? [x any/c]) boolean?]{

Is @racket[x] a @racket[bytes?] of length 48?

}

@defproc[(sha512? [x any/c]) boolean?]{

Is @racket[x] a @racket[bytes?] of length 64?

}
