Changeset 40247 in project


Ignore:
Timestamp:
07/01/21 22:49:11 (4 weeks ago)
Author:
Vasilij Schneidermann
Message:

openssl: Check for unknown key args

File:
1 edited

Legend:

Unmodified
Added
Removed
  • release/5/openssl/trunk/openssl.cipher.scm

    r40246 r40247  
    168168  (bitwise-and (EVP_CIPHER_CTX_flags ctx) EVP_CIPH_FLAG_AEAD_CIPHER))
    169169
    170 (define (cipher-context-init! context cipher key iv #!key
     170(define (remove-known-key-args known-keys args)
     171  (let loop ((args args)
     172             (unknown-args '()))
     173    (if (null? args)
     174        (reverse unknown-args)
     175        (let ((arg (car args)))
     176          (if (memv arg known-keys)
     177              (if (pair? (cdr args))
     178                  (loop (cddr args) unknown-args)
     179                  (loop (cdr args) unknown-args))
     180              (loop (cdr args) (cons arg unknown-args)))))))
     181
     182(define (check-unknown-key-args known-keys args)
     183  (let ((unknown-args (remove-known-key-args known-keys args)))
     184    (when (pair? unknown-args)
     185      (fprintf (current-error-port) "warning: unknown rest arguments: ~s\n" unknown-args))))
     186
     187(define (cipher-context-init! context cipher key iv
     188                              #!rest args
     189                              #!key
    171190                              (mode 'encrypt)
    172191                              (padding #t)
     
    184203  (define (ccm-cipher? ctx)
    185204    (bitwise-and (EVP_CIPHER_CTX_flags ctx) EVP_CIPH_CCM_MODE))
     205  (check-unknown-key-args '(#:mode #:padding #:effective-key-length #:auth-data
     206                            #:tag-length #:expected-tag #:effective-iv-length
     207                            #:message-length) args)
    186208  (let ((ctx (cipher-context-unwrap! context))
    187209        (key-length (or effective-key-length (blob-size key)))
Note: See TracChangeset for help on using the changeset viewer.