[Cryptography] The GOTO Squirrel! [was GOTO Considered Harmful]

Patrick Chkoreff patrick at rayservers.net
Mon Mar 3 13:15:41 EST 2014


Eric Young wrote, On 03/03/2014 07:53 AM:

...
> bn_mul(bn_ctx,r,a,b);
> bn_add(bn_ctx,r,r,c);
> ret = bn_ctx->error;
> /* cleanup */
> return(ret);
> 
> It makes the code easier to read, and in this case, if the function
> fails, I don't actually care that much about which line it was.  You do
> need a little care to check ctx->error sometimes, especially if your
> algorithm has loops.


Nice, I like the straight-line look of it.  Then at certain critical
junctures where everything absolutely must be juuust right, you can add
this:

  assert(bn_ctx->error == 0);

I suppose you could have done the equivalent of "NaN" (not a number) as
a bignum value itself, but clearly you had reason to pass a context
around, so doing it there seems fine.


-- Patrick



More information about the cryptography mailing list