Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1429253 > unrolled thread

Re: [PATCH v6 3/6] crypto: AF_ALG -- add asymmetric cipher interface

Started byMat Martineau <mathew.j.martineau@linux.intel.com>
First post2016-06-23 01:10 +0200
Last post2016-06-23 17:30 +0200
Articles 3 — 3 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [PATCH v6 3/6] crypto: AF_ALG -- add asymmetric cipher  interface Mat Martineau <mathew.j.martineau@linux.intel.com> - 2016-06-23 01:10 +0200
    Re: [PATCH v6 3/6] crypto: AF_ALG -- add asymmetric cipher interface Stephan Mueller <smueller@chronox.de> - 2016-06-23 07:10 +0200
      Re: [PATCH v6 3/6] crypto: AF_ALG -- add asymmetric cipher interface Denis Kenzior <denkenz@gmail.com> - 2016-06-23 17:30 +0200

#1429253 — Re: [PATCH v6 3/6] crypto: AF_ALG -- add asymmetric cipher interface

FromMat Martineau <mathew.j.martineau@linux.intel.com>
Date2016-06-23 01:10 +0200
SubjectRe: [PATCH v6 3/6] crypto: AF_ALG -- add asymmetric cipher interface
Message-ID<rMZrs-1su-45@gated-at.bofh.it>
Stephan and Tadeusz,

On Fri, 10 Jun 2016, Tadeusz Struk wrote:

> On 06/09/2016 11:36 AM, Stephan Mueller wrote:
>> Am Donnerstag, 9. Juni 2016, 11:27:13 schrieb Mat Martineau:
>>
>> Hi Mat, Tadeusz,
>>
>> Ok, after checking the code again, I think that dropping that sanity check
>> should be ok given that this length is part of the akcipher API.
>>
>> Tadeusz, as you are currently managing that patch set, would you re-spin it
>> with the following check removed?
>>
>> +     if (usedpages < akcipher_calcsize(ctx)) {
>> +             err = -EMSGSIZE;
>> +             goto unlock;
>> +     }
>>
>
> Ok, I'll update the patch.

Thanks, that helps (especially with pkcs1pad).

This brings me to another proposal for read buffer sizing: AF_ALG akcipher 
can guarantee that partial reads (where the read buffer is shorter than 
the output of the crypto op) will work using the same semantics as 
SOCK_DGRAM/SOCK_SEQPACKET. With those sockets, as much data as will fit is 
copied in to the read buffer and the remainder is discarded.

I realize there's a performance and memory tradeoff, since the crypto 
algorithm needs a sufficiently large output buffer that would have to be 
created by AF_ALG akcipher. The user could manage that tradeoff by 
providing a larger buffer (typically key_size?) if it wants to avoid 
allocating and copying intermediate buffers inside the kernel.


--
Mat Martineau
Intel OTC

[toc] | [next] | [standalone]


#1429445 — Re: [PATCH v6 3/6] crypto: AF_ALG -- add asymmetric cipher interface

FromStephan Mueller <smueller@chronox.de>
Date2016-06-23 07:10 +0200
SubjectRe: [PATCH v6 3/6] crypto: AF_ALG -- add asymmetric cipher interface
Message-ID<rN53P-5jQ-5@gated-at.bofh.it>
In reply to#1429253
Am Mittwoch, 22. Juni 2016, 15:45:38 schrieb Mat Martineau:

Hi Mat,

> > 
> > Ok, I'll update the patch.
> 
> Thanks, that helps (especially with pkcs1pad).

Tadeusz received the updated patch from me to integrate it into his patch set.
> 
> This brings me to another proposal for read buffer sizing: AF_ALG akcipher
> can guarantee that partial reads (where the read buffer is shorter than
> the output of the crypto op) will work using the same semantics as
> SOCK_DGRAM/SOCK_SEQPACKET. With those sockets, as much data as will fit is
> copied in to the read buffer and the remainder is discarded.
> 
> I realize there's a performance and memory tradeoff, since the crypto
> algorithm needs a sufficiently large output buffer that would have to be
> created by AF_ALG akcipher. The user could manage that tradeoff by
> providing a larger buffer (typically key_size?) if it wants to avoid
> allocating and copying intermediate buffers inside the kernel.

How shall the user know that something got truncated or that the kernel 
created memory?

Ciao
Stephan

[toc] | [prev] | [next] | [standalone]


#1429921 — Re: [PATCH v6 3/6] crypto: AF_ALG -- add asymmetric cipher interface

FromDenis Kenzior <denkenz@gmail.com>
Date2016-06-23 17:30 +0200
SubjectRe: [PATCH v6 3/6] crypto: AF_ALG -- add asymmetric cipher interface
Message-ID<rNeJP-3uS-5@gated-at.bofh.it>
In reply to#1429445
Hi Stephan,

 >>
>> This brings me to another proposal for read buffer sizing: AF_ALG akcipher
>> can guarantee that partial reads (where the read buffer is shorter than
>> the output of the crypto op) will work using the same semantics as
>> SOCK_DGRAM/SOCK_SEQPACKET. With those sockets, as much data as will fit is
>> copied in to the read buffer and the remainder is discarded.
>>
>> I realize there's a performance and memory tradeoff, since the crypto
>> algorithm needs a sufficiently large output buffer that would have to be
>> created by AF_ALG akcipher. The user could manage that tradeoff by
>> providing a larger buffer (typically key_size?) if it wants to avoid
>> allocating and copying intermediate buffers inside the kernel.
>
> How shall the user know that something got truncated or that the kernel
> created memory?
>

To the former point, recall the signature of recv:
ssize_t recv(int sockfd, void *buf, size_t len, int flags);

Traditionally, userspace apps can know that the buffer provided to recv 
was too small in two ways:

The return value from recv / recvmsg was >= len.

In the case of recvmsg, the MSG_TRUNC flag is set.

To quote man recv:

"All  three calls return the length of the message on successful comple‐
tion.  If a message is too long to fit in the supplied  buffer,  excess
bytes  may  be discarded depending on the type of socket the message is
received from."

and

"MSG_TRUNC (since Linux 2.2)

	For   raw   (AF_PACKET),   Internet   datagram   (since    Linux
	2.4.27/2.6.8),  netlink  (since Linux 2.6.22), and UNIX datagram
	(since Linux 3.4) sockets: return the real length of the  packet
	or datagram, even when it was longer than the passed buffer.
"

Regards,
-Denis

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web