Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > SHA-1 in fully-portable C89?

Reply
Thread Tools

SHA-1 in fully-portable C89?

 
 
Tomás Ó hÉilidhe
Guest
Posts: n/a
 
      01-01-2008

(SHA-1 is a cryptographic hash function. For info on what SHA-1 is:
http://en.wikipedia.org/wiki/SHA-1)

I'm writing fullportable C89 code that needs to make use of the SHA-1
algorithm. Does anyone know if there's been a fully-portable C89
implementation of the SHA-1 algorithm?

If not, could someone please point me to a very good implementation of the
algorithm, an implementation which is very portable (perhaps portable to
machines with 8-Bit bytes and which have exact 16-Bit, 32-Bit and 64-Bit
integer types)?

I've done a few Google searches but I'm getting back a lot of sub-standard
platform-specific code.

Thanks.

--
Tomás Ó hÉilidhe
 
Reply With Quote
 
 
 
 
user923005
Guest
Posts: n/a
 
      01-01-2008
On Dec 31, 7:31*pm, "Tomás Ó hÉilidhe" <(E-Mail Removed)> wrote:
> (SHA-1 is a cryptographic hash function. For info on what SHA-1 is:http://en.wikipedia.org/wiki/SHA-1)
>
> I'm writing fullportable C89 code that needs to make use of the SHA-1
> algorithm. Does anyone know if there's been a fully-portable C89
> implementation of the SHA-1 algorithm?
>
> If not, could someone please point me to a very good implementation of the
> algorithm, an implementation which is very portable (perhaps portable to
> machines with 8-Bit bytes and which have exact 16-Bit, 32-Bit and 64-Bit
> integer types)?
>
> I've done a few Google searches but I'm getting back a lot of sub-standard
> platform-specific code.


Here:
http://www.mirrors.wiretapped.net/se.../call-6/sha1.c
http://www.mirrors.wiretapped.net/se.../call-6/sha1.h

A google search for "sha1.c" turns up a zillion hits.

FWIW, the best implementations (typically a factor of 2x-4x faster)
will have inline assembly, so no wonder you are pulling up non-
portable stuff.

Try this as well:
http://ece.gmu.edu/courses/Crypto_re.../libraries.htm

I guess with a little more practice you will learn how to find things
yourself with google.
Another good bet is SourceForge.

Oh, and by the way, searches for C source are not topical on
news:comp.lang.c (but the FAQ reference for news:comp.sources.wanted
is hopelessly outdated)
 
Reply With Quote
 
 
 
 
user923005
Guest
Posts: n/a
 
      01-01-2008
On Dec 31, 7:31*pm, "Tomás Ó hÉilidhe" <(E-Mail Removed)> wrote:
> (SHA-1 is a cryptographic hash function. For info on what SHA-1 is:http://en.wikipedia.org/wiki/SHA-1)
>
> I'm writing fullportable C89 code that needs to make use of the SHA-1
> algorithm. Does anyone know if there's been a fully-portable C89
> implementation of the SHA-1 algorithm?
>
> If not, could someone please point me to a very good implementation of the
> algorithm, an implementation which is very portable (perhaps portable to
> machines with 8-Bit bytes and which have exact 16-Bit, 32-Bit and 64-Bit
> integer types)?
>
> I've done a few Google searches but I'm getting back a lot of sub-standard
> platform-specific code.


One more thing, there is a newsgroup called news:sci.crypt for this
sort of thing.
Unfortunately, it is spam bombarded right now, so it's a little hard
to read.
Some newsreaders can remove most of the junk, though.
 
Reply With Quote
 
Chris Hills
Guest
Posts: n/a
 
      01-01-2008
In article <Xns9A1823D9220Dtoelavabitcom@194.125.133.14>, Tomás Ó
hÉilidhe <(E-Mail Removed)> writes
>
>(SHA-1 is a cryptographic hash function. For info on what SHA-1 is:
>http://en.wikipedia.org/wiki/SHA-1)
>
>I'm writing fullportable C89 code that needs to make use of the SHA-1
>algorithm. Does anyone know if there's been a fully-portable C89
>implementation of the SHA-1 algorithm?


You will probably want an ISO C95 version. C89 was superseded by ISO
C90 and some amendments in 93-95. You will find more compilers support
c95 than anything else.

>If not, could someone please point me to a very good implementation of
>the algorithm, an implementation which is very portable (perhaps
>portable to machines with 8-Bit bytes and which have exact 16-Bit,
>32-Bit and 64-Bit integer types)?


You don't want much do you... I am sure some one can sell you what you
need.

>I've done a few Google searches but I'm getting back a lot of
>sub-standard platform-specific code.


I think for a lot of crypto work you are going to find most of the
implementations are architecture or compiler specific. People usually
need the crypto code to be fast and compact. Generic code will be
neither.

Also in many cases for security the writer will want it less accessible
to hackers. We used various hardware resources to make things less
obvious and more secure. Whist security by concealment is not
recommended as a prime defence it does help when layered on top of other
things.


BTW for a repository of cypher sources see

http://www.phaedsys.demon.co.uk/chris/index.htm

And click on ciphers. There is an SHA1, SHA2 and SHA3 implementation

Apologies for the state of the web site but it needs an overhaul.


--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
/\/\/ http://www.velocityreviews.com/forums/(E-Mail Removed) www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/



 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      01-01-2008
Chris Hills <(E-Mail Removed)> writes:
> In article <Xns9A1823D9220Dtoelavabitcom@194.125.133.14>, Tomás Ó
> hÉilidhe <(E-Mail Removed)> writes
>> (SHA-1 is a cryptographic hash function. For info on what SHA-1 is:
>> http://en.wikipedia.org/wiki/SHA-1)
>>
>> I'm writing fullportable C89 code that needs to make use of the
>> SHA-1 algorithm. Does anyone know if there's been a fully-portable
>> C89 implementation of the SHA-1 algorithm?

>
> You will probably want an ISO C95 version. C89 was superseded by ISO
> C90 and some amendments in 93-95. You will find more compilers support
> c95 than anything else.


C89 (ANSI) and C90 (ISO) describe exactly the same language; the only
changes were some introductory material and a renumbering of some of
the sections.

C95 made some minor changes to C90; I don't think anything added by
C95 would be relevant to an implementation of SHA-1.

I think C95 is entirely upward compatible with C90; C99 is *almost*
entirely upward compatible with C90 and C95. A sufficiently portable
C89/C90 implementation of SHA-1 should work with any C implementation.

[...]

--
Keith Thompson (The_Other_Keith) <(E-Mail Removed)>
[...]
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
Army1987
Guest
Posts: n/a
 
      01-01-2008
Chris Hills wrote:

> In article <Xns9A1823D9220Dtoelavabitcom@194.125.133.14>, Tomás Ó
> hÉilidhe <(E-Mail Removed)> writes


>>I'm writing fullportable C89 code that needs to make use of the SHA-1
>>algorithm. Does anyone know if there's been a fully-portable C89
>>implementation of the SHA-1 algorithm?

>
> You will probably want an ISO C95 version. C89 was superseded by ISO
> C90 and some amendments in 93-95. You will find more compilers support
> c95 than anything else.

I don't think C95 added anything useful to implement the SHA-1 algorithm,
or that it broke any C89 program.

--
Army1987 (Replace "NOSPAM" with "email")
 
Reply With Quote
 
Chris Hills
Guest
Posts: n/a
 
      01-01-2008
In article <fldrai$tpo$(E-Mail Removed)>, Army1987 <(E-Mail Removed)>
writes
>Chris Hills wrote:
>
>> In article <Xns9A1823D9220Dtoelavabitcom@194.125.133.14>, Tomás Ó
>> hÉilidhe <(E-Mail Removed)> writes

>
>>>I'm writing fullportable C89 code that needs to make use of the SHA-1
>>>algorithm. Does anyone know if there's been a fully-portable C89
>>>implementation of the SHA-1 algorithm?

>>
>> You will probably want an ISO C95 version. C89 was superseded by ISO
>> C90 and some amendments in 93-95. You will find more compilers support
>> c95 than anything else.

>I don't think C95 added anything useful to implement the SHA-1 algorithm,
>or that it broke any C89 program.


Then why reference an obsolete standard?
--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
/\/\/ (E-Mail Removed) www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/



 
Reply With Quote
 
Philip Potter
Guest
Posts: n/a
 
      01-01-2008
Chris Hills wrote:
> In article <fldrai$tpo$(E-Mail Removed)>, Army1987 <(E-Mail Removed)>
> writes
>> Chris Hills wrote:
>>
>>> In article <Xns9A1823D9220Dtoelavabitcom@194.125.133.14>, Tomás Ó
>>> hÉilidhe <(E-Mail Removed)> writes
>>>> I'm writing fullportable C89 code that needs to make use of the SHA-1
>>>> algorithm. Does anyone know if there's been a fully-portable C89
>>>> implementation of the SHA-1 algorithm?
>>> You will probably want an ISO C95 version. C89 was superseded by ISO
>>> C90 and some amendments in 93-95. You will find more compilers support
>>> c95 than anything else.

>> I don't think C95 added anything useful to implement the SHA-1 algorithm,
>> or that it broke any C89 program.

>
> Then why reference an obsolete standard?


You know C95 is obsolete, right?
 
Reply With Quote
 
Chris Hills
Guest
Posts: n/a
 
      01-01-2008
In article <fldv43$377$(E-Mail Removed)>, Philip Potter <(E-Mail Removed)>
writes
>Chris Hills wrote:
>> In article <fldrai$tpo$(E-Mail Removed)>, Army1987 <(E-Mail Removed)>
>>writes
>>> Chris Hills wrote:
>>>
>>>> In article <Xns9A1823D9220Dtoelavabitcom@194.125.133.14>, Tomás Ó
>>>> hÉilidhe <(E-Mail Removed)> writes
>>>>> I'm writing fullportable C89 code that needs to make use of the SHA-1
>>>>> algorithm. Does anyone know if there's been a fully-portable C89
>>>>> implementation of the SHA-1 algorithm?
>>>> You will probably want an ISO C95 version. C89 was superseded by ISO
>>>> C90 and some amendments in 93-95. You will find more compilers support
>>>> c95 than anything else.
>>> I don't think C95 added anything useful to implement the SHA-1 algorithm,
>>> or that it broke any C89 program.

>> Then why reference an obsolete standard?

>
>You know C95 is obsolete, right?


Yes but it is the one that most compiler vendors used.

--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
/\/\/ (E-Mail Removed) www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/



 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      01-01-2008
Chris Hills <(E-Mail Removed)> writes:
> In article <fldv43$377$(E-Mail Removed)>, Philip Potter <(E-Mail Removed)>
> writes

[...]
>>You know C95 is obsolete, right?

>
> Yes but it is the one that most compiler vendors used.


Most, but not all. In a discussion here a while ago, it was said that
some implementations support C90 but not C95. Given that C95 is a
superset of C90, more vendors support C90 than C95, and using
C95-specific features in SHA-1 code would make that code slightly less
portable.

--
Keith Thompson (The_Other_Keith) <(E-Mail Removed)>
[...]
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments