From: Paul Eggert <eggert@cs.ucla.edu>
To: Leo <sdl.web@gmail.com>
Cc: Eli Zaretskii <eliz@gnu.org>,
emacs-devel@gnu.org, sand@blarg.net,
YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>,
monnier@iro.umontreal.ca
Subject: Re: Adding sha256 and sha512 to C?
Date: Sun, 12 Jun 2011 15:37:39 -0700 [thread overview]
Message-ID: <4DF53FB3.9060208@cs.ucla.edu> (raw)
In-Reply-To: <m1d3ij2odk.fsf@th041141.ip.tsinghua.edu.cn>
On 06/12/11 06:03, Leo wrote:
> (sha OBJECT &optional START END BINARY ALGORITHM)
>
> where ALGORITHM can be 1 (default), 224, 256, 384, 512, and make sha1
> obsolete? In a sense we unify all SHA functions and leave MD5 as is.
That's better, thanks, but I still have two qualms. First, the name
"sha" is confusing at the Emacs Lisp level: it feels too much like
"ash". It's not like programmers will be using crypto functions in
every expression; their names need not be *that* short. How about the
name "secure-hash" instead? That's pretty short.
Second, naming algorithms via bit counts doesn't sound
forward-looking. SHA-3 is likely to have a 512-bit variant, for
example. How about using atoms to name the algorithms, e.g., SHA-1,
SHA-224, SHA-256, etc.? This is more likely to be robust after SHA-3
comes out, not to mention SHA-4 etc.
+ hash_func = &md5_buffer;
There's no need for the "&" here, or in similar assignments to
hash_func. (And there's no need for multiple spaces before the "=".)
+ digest = make_uninit_string (digest_size);
...
+ Lisp_Object value = make_uninit_string (2 * digest_size);
There's no need to call make_uninit_string twice, as only one
string is being returned. Any temporary buffer for the digest can
be put into the C stack. Or, perhaps better, use the same
uninitialized string for both the binary digest and the text
digest, and run the binary-to-text loop backwards (and without
using sprintf) so that the loop doesn't stomp on its own work.
Something like this:
unsigned char *p = SDATA (digest);
for (i = digest_size - 1; i >= 0; i--)
{
static char const hexdigit[16] = "0123456789abcdef";
int p_i = p[i];
p[2 * i] = hexdigit[p_i >> 4];
p[2 * i + 1] = hexdigit[p_i & 0xf];
}
The text-vs-binary checksum thing seems to be enough of a hassle that
perhaps it should be pulled out into a separate function, rather than
as a flag to the sha/secure-hash function. That is, secure-hash could
always return the text form, and if someone wants a binary form they
could call the text-to-binary converter.
Won't there need to be changes to the Emacs Lisp reference manual, and
to NEWS?
next prev parent reply other threads:[~2011-06-12 22:37 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-28 3:18 Adding sha256 and sha512 to C? sand
2011-05-28 3:58 ` Paul Eggert
2011-05-28 7:25 ` Eli Zaretskii
2011-05-30 4:06 ` Stefan Monnier
2011-06-11 5:43 ` Leo
2011-06-11 8:00 ` Eli Zaretskii
2011-06-11 12:37 ` Leo
2011-06-11 15:24 ` Eli Zaretskii
2011-06-11 16:02 ` Paul Eggert
2011-06-11 20:36 ` Juanma Barranquero
2011-06-12 0:34 ` YAMAMOTO Mitsuharu
2011-06-12 13:03 ` Leo
2011-06-12 14:05 ` Thien-Thi Nguyen
2011-06-12 15:48 ` Deniz Dogan
2011-06-12 17:06 ` Richard Riley
2011-06-12 22:37 ` Paul Eggert [this message]
2011-06-19 16:08 ` Leo
2011-05-29 4:22 ` Leo
2011-05-29 5:18 ` Paul Eggert
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4DF53FB3.9060208@cs.ucla.edu \
--to=eggert@cs.ucla.edu \
--cc=eliz@gnu.org \
--cc=emacs-devel@gnu.org \
--cc=mituharu@math.s.chiba-u.ac.jp \
--cc=monnier@iro.umontreal.ca \
--cc=sand@blarg.net \
--cc=sdl.web@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.