[racket] Another PLaneTs crypto lib usage question?...

From: Doug Williams (m.douglas.williams at gmail.com)
Date: Mon Apr 30 19:50:24 EDT 2012

Try calling cipher-encrypt, which is a lower-level interface, instead
of the encrypt routine. The last part of Section 8.2 of the crypto
document is an example. Here is the example modified with padding
turned off. Note that in this case the message must a multiple of the
block size (96 in the case of aes:128), since there is no padding.


#lang racket

(require (planet vyzo/crypto) (planet vyzo/crypto/util))

(define (my-encrypt key iv)
  (lambda (ptext)
    (let ((octx (cipher-encrypt cipher:aes-128 key iv
                                #:padding #f)))
      (bytes-append (cipher-update! octx ptext)
                    (cipher-final! octx)))))

(define (my-decrypt key iv)
  (lambda (ctext)
    (let ((ictx (cipher-decrypt cipher:aes-128 key iv
                                #:padding #f)))
      (bytes-append (cipher-update! ictx ctext)
                    (cipher-final! ictx)))))

(define msg #"There is a cat in the box.There is a cat in the
box.There is a cat in the box.There is a cat in ")

(define-values (key iv) (generate-key cipher:aes-128))

((my-decrypt key iv) ((my-encrypt key iv) msg))



On Mon, Apr 30, 2012 at 11:08 AM, Rüdiger Asche <rac at ruediger-asche.de> wrote:
> Thanks for the response, but I'm not sure if that answers my question... I now understand that #:padding depicts an optional named parameter, but
> (define dummy (encrypt cipher:aes-128 devicekey nonce #"1234567887654321" #:padding #f))
> is not accepted by Racket, so how would I do it?
> Thanks!
> ----- Original Message -----
> From: Doug Williams
> To: Rüdiger Asche
> Cc: users at racket-lang.org
> Sent: Saturday, April 28, 2012 10:54 PM
> Subject: Re: [racket] Another PLaneTs crypto lib usage question?...
> I have forked the crypto package to perform these actions for my own code and to fix some other problems with post 1.0.0 versions of OpenSSL. I submitted a bug report that at least removes the errors when we go to later OpenSSL versions, but haven't seen any response. I don't have the throughput to take over maintenance of the package, but would be happy to give my forked version over to anyone who does.
> Do we have a process for taking over orphaned projects like this? Or does anyone know the original developers?
> Doug
> On Saturday, April 28, 2012, Rüdiger Asche wrote:
>> Hi there,
>> I'm working with the crypto lib from PLaneT. It actually works well, so far, thanks for the wrappers (it's a Scheme interface to OpenSSL).
>> My question is, how do I turn off padding, i.e. what do I have to pass (and where) as an additional parameter to e.g.
>> (define dummy (encrypt cipher:aes-128 devicekey nonce #"1234567887654321"))
>> to turn off padding (which would be the equivalent to calling EVP_CIPHER_CTX_set_padding())? I see that there is a wrapper for that function in the lib, but I guess I don't yet understand enough about syntaxes and wrappers to figure out how
>> (define (cipher-encrypt type key iv #:padding (pad? #t))
>>  ..
>> )
>> translates to a function call to encrypt where the pad parameter can be passed a value.
>> Thanks!!

Posted on the users mailing list.