473,809 Members | 2,668 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SHA-1 in fully-portable C89?


(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
Jan 1 '08 #1
18 2435
On Dec 31, 7:31*pm, "Tomás Ó hÉilidhe" <t...@lavabit.c omwrote:
(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.sourc es.wanted
is hopelessly outdated)
Jan 1 '08 #2
On Dec 31, 7:31*pm, "Tomás Ó hÉilidhe" <t...@lavabit.c omwrote:
(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.
Jan 1 '08 #3
In article <Xn************ **************@ 194.125.133.14> , Tomás Ó
hÉilidhe <to*@lavabit.co mwrites
>
(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
implementati on 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 /\/\/\/\/
/\/\/ ch***@phaedsys. org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

Jan 1 '08 #4
Chris Hills <ch***@phaedsys .orgwrites:
In article <Xn************ **************@ 194.125.133.14> , Tomás Ó
hÉilidhe <to*@lavabit.co mwrites
>(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_Keit h) <ks***@mib.or g>
[...]
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jan 1 '08 #5
Chris Hills wrote:
In article <Xn************ **************@ 194.125.133.14> , Tomás Ó
hÉilidhe <to*@lavabit.co mwrites
>>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
implementatio n 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")
Jan 1 '08 #6
In article <fl**********@t di.cu.mi.it>, Army1987 <ar******@NOSPA M.it>
writes
>Chris Hills wrote:
>In article <Xn************ **************@ 194.125.133.14> , Tomás Ó
hÉilidhe <to*@lavabit.co mwrites
>>>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
implementati on 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 /\/\/\/\/
/\/\/ ch***@phaedsys. org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

Jan 1 '08 #7
Chris Hills wrote:
In article <fl**********@t di.cu.mi.it>, Army1987 <ar******@NOSPA M.it>
writes
>Chris Hills wrote:
>>In article <Xn************ **************@ 194.125.133.14> , Tomás Ó
hÉilidhe <to*@lavabit.co mwrites
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
implementati on 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?
Jan 1 '08 #8
In article <fl**********@a ioe.org>, Philip Potter <pg*@doc.ic.ac. uk>
writes
>Chris Hills wrote:
>In article <fl**********@t di.cu.mi.it>, Army1987 <ar******@NOSPA M.it>
writes
>>Chris Hills wrote:

In article <Xn************ **************@ 194.125.133.14> , Tomás Ó
hÉilidhe <to*@lavabit.co mwrites
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
implementat ion 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 /\/\/\/\/
/\/\/ ch***@phaedsys. org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

Jan 1 '08 #9
Chris Hills <ch***@phaedsys .orgwrites:
In article <fl**********@a ioe.org>, Philip Potter <pg*@doc.ic.ac. uk>
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_Keit h) <ks***@mib.or g>
[...]
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jan 1 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
3712
by: Paul Rubin | last post by:
http://www.nightsong.com/phr/python/sharandom.c This is intended to be less predicable/have fewer correlations than the default Mersenne Twister or Wichmann-Hill generators. Comments are appreciated.
4
1948
by: Florian Lindner | last post by:
Hello, I try to compute SHA hashes for different files: for root, dirs, files in os.walk(sys.argv): for file in files: path = os.path.join(root, file) print path f = open(path) sha = sha.new(f.read())
4
6778
by: Ravi Singh (UCSD) | last post by:
Hello all I am trying to compare the SHA 256 algorithm as implemented by Christophe Devine and on using the .NET "SHA256Managed" but they do not give me similar hashes. Here is the Christophes implementation .
5
2661
by: EP | last post by:
This inquiry may either turn out to be about the suitability of the SHA-1 (160 bit digest) for file identification, the sha function in Python ... or about some error in my script. Any insight appreciated in advance. I am trying to reduce duplicate files in storage at home - I have a large number files (e.g. MP3s) which have been stored on disk multiple times under different names or on different paths. The using applications will...
0
3094
by: rene.rugerio | last post by:
I am developing an application using dot net fw 2.0 I am using the signedcms for the digital signature. I certainly do not understand why this generates long string as a result of the signing, because it is supposed to generate a string after SHA-1 hashing. Is this implemented as a part of the method for signedcms? I am asking because, lets say you want to sign the word "google" the output is 150 based 64 characters. If you wanted to sign...
3
4317
by: mirandacascade | last post by:
Operating system: Win XP Vsn of Python: 2.4 Situation is this: Required to calcluate a message digest. The process for calcluating the digest must use an SHA-256 algorithm. Questions: 1) Is it correct that the sha module comes with python 2.4? 2) Is it correct that the sha module that ships with python 2.4 does NOT have the SHA-256 capability as part of the module?
1
1931
by: David Rees | last post by:
The Forms-encryption module includes a handy (if long-winded) hash function: FormsAuthentication.HashPasswordForStoringInConfigFile It only supports MD5 and SHA1, but ages ago MD5 was torn apart, and more recently (http://it.slashdot.org/article.pl?sid=07/01/20/1936257&threshold=2) they've broken SHA-1, so obviously we're going to need something a little stronger. I was thinking SHA-256, but that's too similar to SHA-1. Fortunately I...
0
1557
by: cooljoel27 | last post by:
can any one of youll write a code in microsoft Visual basics for secure Hash algorithm please see additional information below (this is for my final year project) ALGORITHM  Append padding bits : The message length should be congruent to 448 mod 512.Padding is always added even if the msg is already of the desired length.Padding consists of a single 1-bit followed by the necessary number of 0-bits.  Append length : A block of 64-bits is...
0
2607
by: Antony Clements | last post by:
I can't find one anywhere on the net and my skills are lacking in that particular area of coding. The closest I can find is a truncated version of SHA-384 that someone is trying to pass off as SHA-1. The official SHA-1 standard has an output string of 160 bits, or 20 characters, the module that I have has an output string of 320 bits or 40 characters. Is anyone here a classy enough coder to write a properly working module of SHA-1 that...
12
4213
by: gulyan | last post by:
Hi, I'm trying to make the sha-1 algorithm based on the wikipedia pseudocode. For the 'The quick brown fox jumps over the lazy dog" string I should get 2fd4e1c6 7a2d28fc ed849ee1 bb76e739 1b93eb12 but what I get is 1D8B8841 A544939A 98BB54FE 4C325476 C44AE1F0 (after I convert from dec to hex) I have no idea what the problem is :( Thx in advance #define ROTL ( a , b ) ( ( ( b ) << a ) | ( ( b ) >> ( 32 - a ) ) )
0
9603
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10391
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10121
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9200
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7664
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3862
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.