From: Ruediger Sonderfeld
Subject: object size
Date: 
Message-ID: <slrnb13jsr.er.cplusplushelp@news.t-online.de>
hi,
I'm trying to implement the SHA1 Hashalgorithm with Common Lisp (GNU clisp 
2.27). The SHA1 Algorithm needs Integer variables with the size of 32Bit. 
Now my problem is that I don't know how to create Integer variables with 
the size of 32Bit. It is possible to do that in ANSI Common Lisp? Or is 
there an GNU/clisp extension?

Ruediger Sonderfeld

(Happy New Year)

-- 
make love && rm -rf software/patents
http://petition.eurolinux.org/index_html

From: Kaz Kylheku
Subject: Re: object size
Date: 
Message-ID: <cf333042.0212311753.3560ca36@posting.google.com>
Ruediger Sonderfeld <·············@gmx.net> wrote in message news:<···························@news.t-online.de>...
> hi,
> I'm trying to implement the SHA1 Hashalgorithm with Common Lisp (GNU clisp 
> 2.27). The SHA1 Algorithm needs Integer variables with the size of 32Bit. 
> Now my problem is that I don't know how to create Integer variables with 
> the size of 32Bit.

Simply create a value which is restricted to the range 0 to
4294967295. If you need to reduce a result to that range to simulate
wrapping 32 bit arithmetic, just use the MOD function with a modulus
of 4294967296.

An integer in Lisp closely resembles an abstract mathematical integer.
For the purposes of bit manipulation, there is an indefinite number of
padding zero bits to the left, so for instance if you want to treat
the value 1 as having 256 bits, you can do that.
From: Nils Goesche
Subject: Re: object size
Date: 
Message-ID: <87vg1artm3.fsf@darkstar.cartan>
Ruediger Sonderfeld <·············@gmx.net> writes:

> I'm trying to implement the SHA1 Hashalgorithm with Common Lisp
> (GNU clisp 2.27). The SHA1 Algorithm needs Integer variables
> with the size of 32Bit.  Now my problem is that I don't know
> how to create Integer variables with the size of 32Bit.

It's objects, not variables, that have types in Common Lisp.  As
integer arithmetic in Common Lisp is not automatically truncated
to any size, you have to LOGAND the results back to 32 bits.  You
might want to write specialized inline functions for arithmetic
operations.  When everything works, add type declarations to get
some speed.

Regards,
-- 
Nils G�sche
Ask not for whom the <CONTROL-G> tolls.

PGP key ID #xD26EF2A0
From: Kent M Pitman
Subject: Re: object size
Date: 
Message-ID: <sfwel7xq55d.fsf@shell01.TheWorld.com>
Nils Goesche <···@cartan.de> writes:

> Ruediger Sonderfeld <·············@gmx.net> writes:
> 
> > I'm trying to implement the SHA1 Hashalgorithm with Common Lisp
> > (GNU clisp 2.27). The SHA1 Algorithm needs Integer variables
> > with the size of 32Bit.  Now my problem is that I don't know
> > how to create Integer variables with the size of 32Bit.
> 
> It's objects, not variables, that have types in Common Lisp.  As
> integer arithmetic in Common Lisp is not automatically truncated
> to any size, you have to LOGAND the results back to 32 bits.  You
> might want to write specialized inline functions for arithmetic
> operations.  When everything works, add type declarations to get
> some speed.

You can also use (unsigned-byte 32) or (signed-byte 32) as a declaration
type if you want to declare that you won't be using more bits than that.
From: Ruediger Sonderfeld
Subject: Re: object size
Date: 
Message-ID: <slrnb16rts.fg.cplusplushelp@news.t-online.de>
Nils Goesche wrote:
> It's objects, not variables, that have types in Common Lisp.  As
> integer arithmetic in Common Lisp is not automatically truncated
> to any size, you have to LOGAND the results back to 32 bits.  You
> might want to write specialized inline functions for arithmetic
> operations.  When everything works, add type declarations to get
> some speed.

Okay I wrote my own 32 Bit Arithmetic. But now I have another
problem. The SHA Algorithm works with 16 32Bit Words and my 
function gets a string with the size n as input. Now I must 
copy 64 bytes from the string into 16 32Bit objects. How can
I do that with Common Lisp? 

-- 
make love && rm -rf software/patents
http://petition.eurolinux.org/index_html
From: Matthew Danish
Subject: Re: object size
Date: 
Message-ID: <20030101202829.D12928@lain.cheme.cmu.edu>
On Wed, Jan 01, 2003 at 11:46:20PM +0100, Ruediger Sonderfeld wrote:
> Okay I wrote my own 32 Bit Arithmetic. But now I have another
> problem. The SHA Algorithm works with 16 32Bit Words and my 
> function gets a string with the size n as input. Now I must 
> copy 64 bytes from the string into 16 32Bit objects. How can
> I do that with Common Lisp? 

Here's a tentative piece of code utilizing (SETF LDB):

(defun convert (string &key (start 0))
  "Convert a given 64 1-octet character string into a vector of 
   (unsigned-byte 32)" 
  (let ((words (make-array 16
                           :element-type '(unsigned-byte 32)
                           :initial-element 0))
        (string-index start))
    (dotimes (word-index 16)
      (dotimes (octet-index 4)
        (setf (ldb (byte 8 (ash octet-index 3)) 
                   (aref words word-index))
              (char-code (char string string-index)))
        (incf string-index)))
    words))

It may not be the best for your purposes, but hopefully it'll give you
an idea.

-- 
; Matthew Danish <·······@andrew.cmu.edu>
; OpenPGP public key: C24B6010 on keyring.debian.org
; Signed or encrypted mail welcome.
; "There is no dark side of the moon really; matter of fact, it's all dark."
From: JP Massar
Subject: Re: object size
Date: 
Message-ID: <3e1394ab.112026075@netnews.attbi.com>
On Wed, 1 Jan 2003 23:46:20 +0100, Ruediger Sonderfeld  
>
>Okay I wrote my own 32 Bit Arithmetic. But now I have another
>problem. The SHA Algorithm works with 16 32Bit Words and my 
>function gets a string with the size n as input. Now I must 
>copy 64 bytes from the string into 16 32Bit objects. How can
>I do that with Common Lisp? 
>
 
Use the CHAR-CODE, ASH and LOGIOR functions to take 4 successive
characters (bytes) of the string and turn those values into
a single 32-bit integer.
From: Dennis Marti
Subject: Re: object size
Date: 
Message-ID: <dennis_marti-549D36.22010001012003@reader1.news.rcn.net>
In article <···························@news.t-online.de>,
 Ruediger Sonderfeld <·············@gmx.net> wrote:

> I'm trying to implement the SHA1 Hashalgorithm with Common Lisp (GNU clisp 
> 2.27). The SHA1 Algorithm needs Integer variables with the size of 32Bit. 

I wrote a SHA1 implementation a couple months ago. It is at 
http://users.starpower.net/marti1/sha-1.lisp

It still needs work (it's slow), but it is a pretty straight forward 
translation of FIPS PUB 180-1. It passes the tests defined in that 
document.

CL-HTTPD also includes a SHA1 library.

Dennis