From: Nate on
Anyone ever heard of a pure fortran implementation of the SHA-1 hash
algorithm? I need to do hmac-sha1 hashes for a project but I would
rather not have to compile together a C function just for this. I was
going to try to port something but hashing is a complicated business.

Thanks,
Nate
From: glen herrmannsfeldt on
Nate <nate(a)grapepudding.com> wrote:

> Anyone ever heard of a pure fortran implementation of the SHA-1 hash
> algorithm? I need to do hmac-sha1 hashes for a project but I would
> rather not have to compile together a C function just for this. I was
> going to try to port something but hashing is a complicated business.

I would say the easiest is direct translation either the C source,
or the pseudocode in, for example, the wikipedia page.

You have to make a few assumptions that the Fortran standard does
not make, such as the existence of (at least) a 32 bit INTEGER type.
It is much easier if you can assume twos complement arithmetic,
and that carries are ignored (that is, wrap on overflow).
The rotate operation can be done with combinations of left shift,
right shift, AND and OR.

-- glen
From: Ron Shepard on
In article <hksfif$pa7$1(a)naig.caltech.edu>,
glen herrmannsfeldt <gah(a)ugcs.caltech.edu> wrote:

> The rotate operation can be done with combinations of left shift,
> right shift, AND and OR.

Is this the same as ishftc()? I think that is a standard intrinsic,
and has been so since 1979 if you count the milstd standard, and
since f90 otherwise.

$.02 -Ron Shepard
From: glen herrmannsfeldt on
Ron Shepard <ron-shepard(a)nospam.comcast.net> wrote:
> In article <hksfif$pa7$1(a)naig.caltech.edu>,
> glen herrmannsfeldt <gah(a)ugcs.caltech.edu> wrote:

>> The rotate operation can be done with combinations of left shift,
>> right shift, AND and OR.

> Is this the same as ishftc()? I think that is a standard intrinsic,
> and has been so since 1979 if you count the milstd standard, and
> since f90 otherwise.

It is, with the appropriate third argument. Well, since Fortran
makes no guarantee on the maximum bit width of INTEGER types,
it is hard to use ishftc() without specifying the width.
SHA1 uses a 32 bit rotation in a few places.

In one check, it seems that gfortran generates IOR, IAND, IEOR,
and ISHFT inline, but ISHFTC with a subroutine call. Two calls
to ISHFT, in that case, is likely faster than ISHFTC.

-- glen
From: steve on
On Feb 9, 10:13 pm, glen herrmannsfeldt <g...(a)ugcs.caltech.edu> wrote:

> In one check, it seems that gfortran generates IOR, IAND, IEOR,
> and ISHFT inline, but ISHFTC with a subroutine call.  Two calls
> to ISHFT, in that case, is likely faster than ISHFTC.
>

Source code?

Given the right source gfortran won't produce anything except
the answer (hint, constant folding).

--
steve

 |  Next  |  Last
Pages: 1 2
Prev: Thanks
Next: Bitwise functions with more arguments?