cryptodev: support multiple cipher block sizes

Message ID 1612449252-395208-1-git-send-email-matan@nvidia.com (mailing list archive)
State Superseded, archived
Delegated to: akhil goyal
Headers
Series cryptodev: support multiple cipher block sizes |

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/travis-robot warning Travis build: failed
ci/iol-testing warning Testing issues
ci/iol-abi-testing success Testing PASS

Commit Message

Matan Azrad Feb. 4, 2021, 2:34 p.m. UTC
  In cryptography, a block cipher is a deterministic algorithm operating
on fixed-length groups of bits, called blocks.

A block cipher consists of two paired algorithms, one for encryption
and the other for decryption. Both algorithms accept two inputs:
an input block of size n bits and a key of size k bits; and both yield
an n-bit output block. The decryption algorithm is defined to be the
inverse function of the encryption.

Some cipher algorithms support multiple block sizes, e.g. AES-XTS
supports any block size in range [16B, 2^24B], in this case,
A plain-text data, divided into N amount of n-bits blocks, which is
encrypted to the same data size, cipher-text, must be decrypted in the
same division of N amount of n-bits blocks in order to get the same
plain-text data.

The current cryptodev API doesn't allow the user to select a specific
block size supported by the devices
In addition, there is no definition how the IV is detected per block
when single operation includes more than one block.

That causes applications to use single operation per block even though
all the data is continuous in memory what reduces datapath performance.

Add a new feature flag to support multiple block sizes, called
RTE_CRYPTODEV_FF_CIPHER_MULITPLE_BLOCKS.
Add a new field in cipher capability, called bsf - block size flags,
where the devices can report the range of the supported block sizes.
Add a new cipher transformation field, called block_size, where the user
can select one block size from the supported range.

All the new fields do not change the size of their structures.

Using flags to report the supported block sizes capability allows the
devices to report a range simply as same as the user to read it simply.
Also, thus sizes are usually common and probably will be shared between
the devices.

Signed-off-by: Matan Azrad <matan@nvidia.com>
---
 lib/librte_cryptodev/rte_crypto_sym.h | 12 ++++++++++++
 lib/librte_cryptodev/rte_cryptodev.h  | 23 ++++++++++++++++++++++-
 2 files changed, 34 insertions(+), 1 deletion(-)
  

Comments

Fan Zhang Feb. 5, 2021, 4:50 p.m. UTC | #1
Hi Matan,

It is a good idea to be able to show the varied block sizes of each PMD/algo.

> -----Original Message-----
> From: Matan Azrad <matan@nvidia.com>
> Sent: Thursday, February 4, 2021 2:34 PM
> To: dev@dpdk.org
> Cc: akhil.goyal@nxp.com; Doherty, Declan <declan.doherty@intel.com>;
> Somalapuram Amaranath <asomalap@amd.com>; Ruifeng Wang
> <ruifeng.wang@arm.com>; Ajit Khaparde <ajit.khaparde@broadcom.com>;
> Anoob Joseph <anoobj@marvell.com>; Zhang, Roy Fan
> <roy.fan.zhang@intel.com>; Griffin, John <john.griffin@intel.com>; De Lara
> Guarch, Pablo <pablo.de.lara.guarch@intel.com>; Michael Shamis
> <michaelsh@marvell.com>; Nagadheeraj Rottela
> <rnagadheeraj@marvell.com>; Ankur Dwivedi <adwivedi@marvell.com>;
> Gagandeep Singh <g.singh@nxp.com>; Jay Zhou <jianjay.zhou@huawei.com>
> Subject: [PATCH] cryptodev: support multiple cipher block sizes

[SNIP] 

> +#define RTE_CRYPTO_CIPHER_BSF_ALL 0x1
> +/* All the sizes from the algorithm standard */
> +#define RTE_CRYPTO_CIPHER_BSF_512_BYTES 0x2
> +#define RTE_CRYPTO_CIPHER_BSF_520_BYTES 0x4
> +#define RTE_CRYPTO_CIPHER_BSF_4048_BYTES 0x8
> +#define RTE_CRYPTO_CIPHER_BSF_4096_BYTES 0x10
> +#define RTE_CRYPTO_CIPHER_BSF_4160_BYTES 0x20
> +#define RTE_CRYPTO_CIPHER_BSF_1M_BYTES 0x40
> +
> +/**
>   * Symmetric Crypto Capability
>   */
>  struct rte_cryptodev_symmetric_capability {
> @@ -122,11 +135,19 @@ struct rte_cryptodev_symmetric_capability {
>  			enum rte_crypto_cipher_algorithm algo;
>  			/**< cipher algorithm */
>  			uint16_t block_size;
> -			/**< algorithm block size */
> +			/**<
> +			 * algorithm block size
> +			 * For algorithms support more than single block size,
> +			 * this is the default block size supported by the
> +			 * driver, all the supported sizes are reflected in the
> +			 * bsf field.
> +			 */
>  			struct rte_crypto_param_range key_size;
>  			/**< cipher key size range */
>  			struct rte_crypto_param_range iv_size;
>  			/**< Initialisation vector data size range */
> +			uint32_t bsf;
> +			/**< Block size flags */

The doubt I have is limited block sizes 32-bit bsf can represents. Although it is good enough now for AES-XTS but it already used 1/4 of all available representation of the different block sizes. If we are to include more block sizes for different algorithms we really don't have much room left.
Also bsf seems to be a duplication to existing block_size. 

There should be a better way to describe varied block sizes in capability.

>  		} cipher;
>  		/**< Symmetric Cipher transform capabilities */
>  		struct {
> --
> 1.8.3.1

Regards,
Fan
  
Arkadiusz Kusztal Feb. 8, 2021, 12:10 p.m. UTC | #2
Hi Matan,

Few comments/questions inline with [Arek]

> -----Original Message-----
> From: dev <dev-bounces@dpdk.org> On Behalf Of Matan Azrad
> Sent: Thursday, February 4, 2021 3:34 PM
> To: dev@dpdk.org
> Cc: akhil.goyal@nxp.com; Doherty, Declan <declan.doherty@intel.com>;
> Somalapuram Amaranath <asomalap@amd.com>; Ruifeng Wang
> <ruifeng.wang@arm.com>; Ajit Khaparde <ajit.khaparde@broadcom.com>;
> Anoob Joseph <anoobj@marvell.com>; Zhang, Roy Fan
> <roy.fan.zhang@intel.com>; Griffin, John <john.griffin@intel.com>; De Lara
> Guarch, Pablo <pablo.de.lara.guarch@intel.com>; Michael Shamis
> <michaelsh@marvell.com>; Nagadheeraj Rottela
> <rnagadheeraj@marvell.com>; Ankur Dwivedi <adwivedi@marvell.com>;
> Gagandeep Singh <g.singh@nxp.com>; Jay Zhou <jianjay.zhou@huawei.com>
> Subject: [dpdk-dev] [PATCH] cryptodev: support multiple cipher block sizes
> 
> In cryptography, a block cipher is a deterministic algorithm operating on fixed-
> length groups of bits, called blocks.
> 
> A block cipher consists of two paired algorithms, one for encryption and the
> other for decryption. Both algorithms accept two inputs:
> an input block of size n bits and a key of size k bits; and both yield an n-bit output
> block. The decryption algorithm is defined to be the inverse function of the
> encryption.
> 
> Some cipher algorithms support multiple block sizes, e.g. AES-XTS supports any
> block size in range [16B, 2^24B], in this case, A plain-text data, divided into N
> amount of n-bits blocks, which is encrypted to the same data size, cipher-text,
> must be decrypted in the same division of N amount of n-bits blocks in order to
> get the same plain-text data.
[Arek] - Except that the last data block does not need to be n-bit long, beside that and lack of chaining it makes XTS no different to any other block cipher mode of operation.
Block size itself for XTS-AES is always 16 bytes in the first place which is AES constraint.
2^20 * 16B -> 2^24B constraint from IEEE 1619-2017, SP800-38E is data unit length that contains "data unit in bytes/ 16" AES blocks where last one can be incomplete.

> 
> The current cryptodev API doesn't allow the user to select a specific block size
> supported by the devices In addition, there is no definition how the IV is
> detected per block when single operation includes more than one block.

[Arek] - Do you mean tweak increment per data unit? Like one op as a data stream (multiple data units) and tweak incremented by pmd?

> 
> That causes applications to use single operation per block even though all the
> data is continuous in memory what reduces datapath performance.
> 
> Add a new feature flag to support multiple block sizes, called
> RTE_CRYPTODEV_FF_CIPHER_MULITPLE_BLOCKS.
> Add a new field in cipher capability, called bsf - block size flags, where the
> devices can report the range of the supported block sizes.
> Add a new cipher transformation field, called block_size, where the user can
> select one block size from the supported range.
> 
> All the new fields do not change the size of their structures.
> 
> Using flags to report the supported block sizes capability allows the devices to
> report a range simply as same as the user to read it simply.
> Also, thus sizes are usually common and probably will be shared between the
> devices.
> 
> Signed-off-by: Matan Azrad <matan@nvidia.com>
> ---
>  lib/librte_cryptodev/rte_crypto_sym.h | 12 ++++++++++++
> lib/librte_cryptodev/rte_cryptodev.h  | 23 ++++++++++++++++++++++-
>  2 files changed, 34 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/librte_cryptodev/rte_crypto_sym.h
> b/lib/librte_cryptodev/rte_crypto_sym.h
> index 9d572ec..9a1215d 100644
> --- a/lib/librte_cryptodev/rte_crypto_sym.h
> +++ b/lib/librte_cryptodev/rte_crypto_sym.h
> @@ -265,6 +265,18 @@ struct rte_crypto_cipher_xform {
>  		 * which can be in the range 7 to 13 inclusive.
>  		 */
>  	} iv;	/**< Initialisation vector parameters */
> +
> +	uint32_t block_size;
> +	/**< When RTE_CRYPTODEV_FF_CIPHER_MULITPLE_BLOCKS is
> reported, this is
> +	 * the block size of the algorithm, otherwise or when the value is 0,
> +	 * use the default block size provided in the capability.
> +	 * The value should be in the range defined by the bsf field in the
> +	 * cipher capability.

[Arek] - nowadays algorithms rather don't have different block sizes, though I see people set this field even for stream ciphers.
If such algorithm would happen it probably could just get a suffix in crypto_cipher_enum. Otherwise some fixed size array could be added.

> +	 *
> +	 * - For AES-XTS it is the size of data-unit, from IEEE Std 1619-2007.
> +	 * For-each data-unit in the operation, the tweak(IV) value is
> +	 * assigned consecutively starting from the operation assigned tweak.
> +	 */
[Arek] - if data unit would be session value (key scope in xts naming) where the number of units would be taken from, sym_op->len ?
(For standard storage example: data unit size -> logical block size, sym_op->len -> range of consecutive logical blocks.)
If so it probably could be session-less op as this cipher key would be unusable after it.

>  };
> 
>  /** Symmetric Authentication / Hash Algorithms diff --git
> a/lib/librte_cryptodev/rte_cryptodev.h b/lib/librte_cryptodev/rte_cryptodev.h
> index ae34f33..60ba839 100644
> --- a/lib/librte_cryptodev/rte_cryptodev.h
> +++ b/lib/librte_cryptodev/rte_cryptodev.h
> @@ -96,6 +96,19 @@ struct rte_crypto_param_range {  };
> 
>  /**
> + * Crypto device supported block size flags for cipher algorithms
> + * Each flag represents single or range of supported block sizes  */
> +#define RTE_CRYPTO_CIPHER_BSF_ALL 0x1
> +/* All the sizes from the algorithm standard */ #define
> +RTE_CRYPTO_CIPHER_BSF_512_BYTES 0x2 #define
> +RTE_CRYPTO_CIPHER_BSF_520_BYTES 0x4 #define
> +RTE_CRYPTO_CIPHER_BSF_4048_BYTES 0x8 #define
> +RTE_CRYPTO_CIPHER_BSF_4096_BYTES 0x10 #define
> +RTE_CRYPTO_CIPHER_BSF_4160_BYTES 0x20 #define
> +RTE_CRYPTO_CIPHER_BSF_1M_BYTES 0x40
[Arek] - when adding constants source should be attached as well.
> +
> +/**
>   * Symmetric Crypto Capability
>   */
>  struct rte_cryptodev_symmetric_capability { @@ -122,11 +135,19 @@ struct
> rte_cryptodev_symmetric_capability {
>  			enum rte_crypto_cipher_algorithm algo;
>  			/**< cipher algorithm */
>  			uint16_t block_size;
> -			/**< algorithm block size */
> +			/**<
> +			 * algorithm block size
> +			 * For algorithms support more than single block size,
> +			 * this is the default block size supported by the
> +			 * driver, all the supported sizes are reflected in the
> +			 * bsf field.
> +			 */
>  			struct rte_crypto_param_range key_size;
>  			/**< cipher key size range */
>  			struct rte_crypto_param_range iv_size;
>  			/**< Initialisation vector data size range */
> +			uint32_t bsf;
> +			/**< Block size flags */
>  		} cipher;
>  		/**< Symmetric Cipher transform capabilities */
>  		struct {
> --
> 1.8.3.1
  
Matan Azrad Feb. 8, 2021, 1:36 p.m. UTC | #3
Hi Kuztal

From: Kusztal, ArkadiuszX
> Hi Matan,
> 
> Few comments/questions inline with [Arek]
> 
> > -----Original Message-----
> > From: dev <dev-bounces@dpdk.org> On Behalf Of Matan Azrad
> > Sent: Thursday, February 4, 2021 3:34 PM
> > To: dev@dpdk.org
> > Cc: akhil.goyal@nxp.com; Doherty, Declan <declan.doherty@intel.com>;
> > Somalapuram Amaranath <asomalap@amd.com>; Ruifeng Wang
> > <ruifeng.wang@arm.com>; Ajit Khaparde <ajit.khaparde@broadcom.com>;
> > Anoob Joseph <anoobj@marvell.com>; Zhang, Roy Fan
> > <roy.fan.zhang@intel.com>; Griffin, John <john.griffin@intel.com>; De
> > Lara Guarch, Pablo <pablo.de.lara.guarch@intel.com>; Michael Shamis
> > <michaelsh@marvell.com>; Nagadheeraj Rottela
> > <rnagadheeraj@marvell.com>; Ankur Dwivedi <adwivedi@marvell.com>;
> > Gagandeep Singh <g.singh@nxp.com>; Jay Zhou <jianjay.zhou@huawei.com>
> > Subject: [dpdk-dev] [PATCH] cryptodev: support multiple cipher block
> > sizes
> >
> > In cryptography, a block cipher is a deterministic algorithm operating
> > on fixed- length groups of bits, called blocks.
> >
> > A block cipher consists of two paired algorithms, one for encryption
> > and the other for decryption. Both algorithms accept two inputs:
> > an input block of size n bits and a key of size k bits; and both yield
> > an n-bit output block. The decryption algorithm is defined to be the
> > inverse function of the encryption.
> >
> > Some cipher algorithms support multiple block sizes, e.g. AES-XTS
> > supports any block size in range [16B, 2^24B], in this case, A
> > plain-text data, divided into N amount of n-bits blocks, which is
> > encrypted to the same data size, cipher-text, must be decrypted in the
> > same division of N amount of n-bits blocks in order to get the same plain-text
> data.
> [Arek] - Except that the last data block does not need to be n-bit long, beside
> that and lack of chaining it makes XTS no different to any other block cipher
> mode of operation.
> Block size itself for XTS-AES is always 16 bytes in the first place which is AES
> constraint.
> 2^20 * 16B -> 2^24B constraint from IEEE 1619-2017, SP800-38E is data unit
> length that contains "data unit in bytes/ 16" AES blocks where last one can be
> incomplete.
> 
> >
> > The current cryptodev API doesn't allow the user to select a specific
> > block size supported by the devices In addition, there is no
> > definition how the IV is detected per block when single operation includes
> more than one block.
> 
> [Arek] - Do you mean tweak increment per data unit? Like one op as a data
> stream (multiple data units) and tweak incremented by pmd?

It can be defined differently per algorithm.
I know from AES-XTS standard that the tweak should be incremented by 1 per data-unit.
So, yes, here, the driver\device should take care for the incrementation.
  

> 
> >
> > That causes applications to use single operation per block even though
> > all the data is continuous in memory what reduces datapath performance.
> >
> > Add a new feature flag to support multiple block sizes, called
> > RTE_CRYPTODEV_FF_CIPHER_MULITPLE_BLOCKS.
> > Add a new field in cipher capability, called bsf - block size flags,
> > where the devices can report the range of the supported block sizes.
> > Add a new cipher transformation field, called block_size, where the
> > user can select one block size from the supported range.
> >
> > All the new fields do not change the size of their structures.
> >
> > Using flags to report the supported block sizes capability allows the
> > devices to report a range simply as same as the user to read it simply.
> > Also, thus sizes are usually common and probably will be shared
> > between the devices.
> >
> > Signed-off-by: Matan Azrad <matan@nvidia.com>
> > ---
> >  lib/librte_cryptodev/rte_crypto_sym.h | 12 ++++++++++++
> > lib/librte_cryptodev/rte_cryptodev.h  | 23 ++++++++++++++++++++++-
> >  2 files changed, 34 insertions(+), 1 deletion(-)
> >
> > diff --git a/lib/librte_cryptodev/rte_crypto_sym.h
> > b/lib/librte_cryptodev/rte_crypto_sym.h
> > index 9d572ec..9a1215d 100644
> > --- a/lib/librte_cryptodev/rte_crypto_sym.h
> > +++ b/lib/librte_cryptodev/rte_crypto_sym.h
> > @@ -265,6 +265,18 @@ struct rte_crypto_cipher_xform {
> >                * which can be in the range 7 to 13 inclusive.
> >                */
> >       } iv;   /**< Initialisation vector parameters */
> > +
> > +     uint32_t block_size;
> > +     /**< When RTE_CRYPTODEV_FF_CIPHER_MULITPLE_BLOCKS is
> > reported, this is
> > +      * the block size of the algorithm, otherwise or when the value is 0,
> > +      * use the default block size provided in the capability.
> > +      * The value should be in the range defined by the bsf field in the
> > +      * cipher capability.
> 
> [Arek] - nowadays algorithms rather don't have different block sizes, though I
> see people set this field even for stream ciphers.
> If such algorithm would happen it probably could just get a suffix in
> crypto_cipher_enum. Otherwise some fixed size array could be added.

First, if no different block size per algorithm, why do we need this parameter at all?

Second,
Cipher block defined to be like this D(E(b)) = b
D: decryption function
E: encryption function
P: plain-text block data.

In case of AES-XTS the cipher block size is the data-unit size.
There is a big range of optional data, see in standard.


> > +      *
> > +      * - For AES-XTS it is the size of data-unit, from IEEE Std 1619-2007.
> > +      * For-each data-unit in the operation, the tweak(IV) value is
> > +      * assigned consecutively starting from the operation assigned tweak.
> > +      */
> [Arek] - if data unit would be session value (key scope in xts naming) where the
> number of units would be taken from, sym_op->len ?

Yes, it is already defined there that it must be multiple of block size(data-unit in AES-XTS case).

> (For standard storage example: data unit size -> logical block size, sym_op->len
> -> range of consecutive logical blocks.) If so it probably could be session-less op
> as this cipher key would be unusable after it.
> 

Can be session and session-less modes.

If the user want to operate on different groups of blocks in the same stream
he can use the same session(key) with different ops.

Am I missing here?

> >  };
> >
> >  /** Symmetric Authentication / Hash Algorithms diff --git
> > a/lib/librte_cryptodev/rte_cryptodev.h
> > b/lib/librte_cryptodev/rte_cryptodev.h
> > index ae34f33..60ba839 100644
> > --- a/lib/librte_cryptodev/rte_cryptodev.h
> > +++ b/lib/librte_cryptodev/rte_cryptodev.h
> > @@ -96,6 +96,19 @@ struct rte_crypto_param_range {  };
> >
> >  /**
> > + * Crypto device supported block size flags for cipher algorithms
> > + * Each flag represents single or range of supported block sizes  */
> > +#define RTE_CRYPTO_CIPHER_BSF_ALL 0x1
> > +/* All the sizes from the algorithm standard */ #define
> > +RTE_CRYPTO_CIPHER_BSF_512_BYTES 0x2 #define
> > +RTE_CRYPTO_CIPHER_BSF_520_BYTES 0x4 #define
> > +RTE_CRYPTO_CIPHER_BSF_4048_BYTES 0x8 #define
> > +RTE_CRYPTO_CIPHER_BSF_4096_BYTES 0x10 #define
> > +RTE_CRYPTO_CIPHER_BSF_4160_BYTES 0x20 #define
> > +RTE_CRYPTO_CIPHER_BSF_1M_BYTES 0x40
> [Arek] - when adding constants source should be attached as well.
> > +
> > +/**
> >   * Symmetric Crypto Capability
> >   */
> >  struct rte_cryptodev_symmetric_capability { @@ -122,11 +135,19 @@
> > struct rte_cryptodev_symmetric_capability {
> >                       enum rte_crypto_cipher_algorithm algo;
> >                       /**< cipher algorithm */
> >                       uint16_t block_size;
> > -                     /**< algorithm block size */
> > +                     /**<
> > +                      * algorithm block size
> > +                      * For algorithms support more than single block size,
> > +                      * this is the default block size supported by the
> > +                      * driver, all the supported sizes are reflected in the
> > +                      * bsf field.
> > +                      */
> >                       struct rte_crypto_param_range key_size;
> >                       /**< cipher key size range */
> >                       struct rte_crypto_param_range iv_size;
> >                       /**< Initialisation vector data size range */
> > +                     uint32_t bsf;
> > +                     /**< Block size flags */
> >               } cipher;
> >               /**< Symmetric Cipher transform capabilities */
> >               struct {
> > --
> > 1.8.3.1
  
Arkadiusz Kusztal Feb. 8, 2021, 3:28 p.m. UTC | #4
> > > Subject: [dpdk-dev] [PATCH] cryptodev: support multiple cipher block
> > > sizes
> > >
> > > In cryptography, a block cipher is a deterministic algorithm
> > > operating on fixed- length groups of bits, called blocks.
> > >
> > > A block cipher consists of two paired algorithms, one for encryption
> > > and the other for decryption. Both algorithms accept two inputs:
> > > an input block of size n bits and a key of size k bits; and both
> > > yield an n-bit output block. The decryption algorithm is defined to
> > > be the inverse function of the encryption.
> > >
> > > Some cipher algorithms support multiple block sizes, e.g. AES-XTS
> > > supports any block size in range [16B, 2^24B], in this case, A
> > > plain-text data, divided into N amount of n-bits blocks, which is
> > > encrypted to the same data size, cipher-text, must be decrypted in
> > > the same division of N amount of n-bits blocks in order to get the
> > > same plain-text
> > data.
> > [Arek] - Except that the last data block does not need to be n-bit
> > long, beside that and lack of chaining it makes XTS no different to
> > any other block cipher mode of operation.
> > Block size itself for XTS-AES is always 16 bytes in the first place
> > which is AES constraint.
> > 2^20 * 16B -> 2^24B constraint from IEEE 1619-2017, SP800-38E is data
> > unit length that contains "data unit in bytes/ 16" AES blocks where
> > last one can be incomplete.
> >
> > >
> > > The current cryptodev API doesn't allow the user to select a
> > > specific block size supported by the devices In addition, there is
> > > no definition how the IV is detected per block when single operation
> > > includes
> > more than one block.
> >
> > [Arek] - Do you mean tweak increment per data unit? Like one op as a
> > data stream (multiple data units) and tweak incremented by pmd?
> 
> It can be defined differently per algorithm.
[Arek] - what do you mean?
> I know from AES-XTS standard that the tweak should be incremented by 1 per
> data-unit.
> So, yes, here, the driver\device should take care for the incrementation.
[Arek] - then it should be stated in rte_crypto_sym_op iv comments.

> 
> 
> >
> > >
> > > That causes applications to use single operation per block even
> > > though all the data is continuous in memory what reduces datapath
> performance.
> > >
> > > Add a new feature flag to support multiple block sizes, called
> > > RTE_CRYPTODEV_FF_CIPHER_MULITPLE_BLOCKS.
> > > Add a new field in cipher capability, called bsf - block size flags,
> > > where the devices can report the range of the supported block sizes.
> > > Add a new cipher transformation field, called block_size, where the
> > > user can select one block size from the supported range.
> > >
> > > All the new fields do not change the size of their structures.
> > >
> > > Using flags to report the supported block sizes capability allows
> > > the devices to report a range simply as same as the user to read it simply.
> > > Also, thus sizes are usually common and probably will be shared
> > > between the devices.
> > >
> > > Signed-off-by: Matan Azrad <matan@nvidia.com>
> > > ---
> > >  lib/librte_cryptodev/rte_crypto_sym.h | 12 ++++++++++++
> > > lib/librte_cryptodev/rte_cryptodev.h  | 23 ++++++++++++++++++++++-
> > >  2 files changed, 34 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/lib/librte_cryptodev/rte_crypto_sym.h
> > > b/lib/librte_cryptodev/rte_crypto_sym.h
> > > index 9d572ec..9a1215d 100644
> > > --- a/lib/librte_cryptodev/rte_crypto_sym.h
> > > +++ b/lib/librte_cryptodev/rte_crypto_sym.h
> > > @@ -265,6 +265,18 @@ struct rte_crypto_cipher_xform {
> > >                * which can be in the range 7 to 13 inclusive.
> > >                */
> > >       } iv;   /**< Initialisation vector parameters */
> > > +
> > > +     uint32_t block_size;
[Arek] - looking from your answers below, this one could just be aes_xts_dataunit_len.

> > > +     /**< When RTE_CRYPTODEV_FF_CIPHER_MULITPLE_BLOCKS is
> > > reported, this is
> > > +      * the block size of the algorithm, otherwise or when the value is 0,
> > > +      * use the default block size provided in the capability.
> > > +      * The value should be in the range defined by the bsf field in the
> > > +      * cipher capability.
> >
> > [Arek] - nowadays algorithms rather don't have different block sizes,
> > though I see people set this field even for stream ciphers.
> > If such algorithm would happen it probably could just get a suffix in
> > crypto_cipher_enum. Otherwise some fixed size array could be added.
> 
> First, if no different block size per algorithm, why do we need this parameter at
> all?
[Arek] - I am not sure but looks like informative, especially that it is only one 16bit long field.
 
> 
> Second,
> Cipher block defined to be like this D(E(b)) = b
> D: decryption function
> E: encryption function
> P: plain-text block data.
> 
> In case of AES-XTS the cipher block size is the data-unit size.
> There is a big range of optional data, see in standard.
[Arek] - Currently in DPDK we have 3 block cipher algorithms:
TDEA(3DES) - 8 byte block, AES - 16 byte block, KASUMI -8byte (but deprecated since 3G),
Additionally IPsec ietf defines NULL as block cipher with 1 byte len, but ETSI doesn't do that with EEA,EIA,NIA-0.

> 
> 
> > > +      *
> > > +      * - For AES-XTS it is the size of data-unit, from IEEE Std 1619-2007.
> > > +      * For-each data-unit in the operation, the tweak(IV) value is
> > > +      * assigned consecutively starting from the operation assigned tweak.
> > > +      */
> > [Arek] - if data unit would be session value (key scope in xts naming)
> > where the number of units would be taken from, sym_op->len ?
> 
> Yes, it is already defined there that it must be multiple of block size(data-unit in
> AES-XTS case).
[Arek]  - this comment was meant for cipher block modes that needs input aligned to block cipher len, like CBC padding.
In case of XTS it should be something like : multiple of xform xts_data_unit len or one of two:
- data unit len itself in case device does not support multiple data units.
- 0 and data unit len would be taken from session/xform in case device does not support multiple data units.

> 
> > (For standard storage example: data unit size -> logical block size,
> > sym_op->len
> > -> range of consecutive logical blocks.) If so it probably could be
> > -> session-less op
> > as this cipher key would be unusable after it.
> >
> 
> Can be session and session-less modes.
> 
> If the user want to operate on different groups of blocks in the same stream he
> can use the same session(key) with different ops.
[Arek] - yes, it should be possible to do that if user keep track of tweak value.

> 
> Am I missing here?
> 
> > >  };
> > >
> > >  /** Symmetric Authentication / Hash Algorithms diff --git
> > > a/lib/librte_cryptodev/rte_cryptodev.h
> > > b/lib/librte_cryptodev/rte_cryptodev.h
> > > index ae34f33..60ba839 100644
> > > --- a/lib/librte_cryptodev/rte_cryptodev.h
> > > +++ b/lib/librte_cryptodev/rte_cryptodev.h
> > > @@ -96,6 +96,19 @@ struct rte_crypto_param_range {  };
> > >
> > >  /**
> > > + * Crypto device supported block size flags for cipher algorithms
> > > + * Each flag represents single or range of supported block sizes
> > > +*/ #define RTE_CRYPTO_CIPHER_BSF_ALL 0x1
> > > +/* All the sizes from the algorithm standard */ #define
> > > +RTE_CRYPTO_CIPHER_BSF_512_BYTES 0x2 #define
> > > +RTE_CRYPTO_CIPHER_BSF_520_BYTES 0x4 #define
> > > +RTE_CRYPTO_CIPHER_BSF_4048_BYTES 0x8 #define
> > > +RTE_CRYPTO_CIPHER_BSF_4096_BYTES 0x10 #define
> > > +RTE_CRYPTO_CIPHER_BSF_4160_BYTES 0x20 #define
> > > +RTE_CRYPTO_CIPHER_BSF_1M_BYTES 0x40
> > [Arek] - when adding constants source should be attached as well.
> > > +
> > > +/**
> > >   * Symmetric Crypto Capability
> > >   */
> > >  struct rte_cryptodev_symmetric_capability { @@ -122,11 +135,19 @@
> > > struct rte_cryptodev_symmetric_capability {
> > >                       enum rte_crypto_cipher_algorithm algo;
> > >                       /**< cipher algorithm */
> > >                       uint16_t block_size;
> > > -                     /**< algorithm block size */
> > > +                     /**<
> > > +                      * algorithm block size
> > > +                      * For algorithms support more than single block size,
> > > +                      * this is the default block size supported by the
> > > +                      * driver, all the supported sizes are reflected in the
> > > +                      * bsf field.
> > > +                      */
> > >                       struct rte_crypto_param_range key_size;
> > >                       /**< cipher key size range */
> > >                       struct rte_crypto_param_range iv_size;
> > >                       /**< Initialisation vector data size range */
> > > +                     uint32_t bsf;
> > > +                     /**< Block size flags */
> > >               } cipher;
> > >               /**< Symmetric Cipher transform capabilities */
> > >               struct {
> > > --
> > > 1.8.3.1
  
Matan Azrad Feb. 8, 2021, 6:23 p.m. UTC | #5
Hi Kusztal

First, thank you for this review and the suggestions.

From: Kusztal, ArkadiuszX
> > > > Subject: [dpdk-dev] [PATCH] cryptodev: support multiple cipher
> > > > block sizes
> > > >
> > > > In cryptography, a block cipher is a deterministic algorithm
> > > > operating on fixed- length groups of bits, called blocks.
> > > >
> > > > A block cipher consists of two paired algorithms, one for
> > > > encryption and the other for decryption. Both algorithms accept two
> inputs:
> > > > an input block of size n bits and a key of size k bits; and both
> > > > yield an n-bit output block. The decryption algorithm is defined
> > > > to be the inverse function of the encryption.
> > > >
> > > > Some cipher algorithms support multiple block sizes, e.g. AES-XTS
> > > > supports any block size in range [16B, 2^24B], in this case, A
> > > > plain-text data, divided into N amount of n-bits blocks, which is
> > > > encrypted to the same data size, cipher-text, must be decrypted in
> > > > the same division of N amount of n-bits blocks in order to get the
> > > > same plain-text
> > > data.
> > > [Arek] - Except that the last data block does not need to be n-bit
> > > long, beside that and lack of chaining it makes XTS no different to
> > > any other block cipher mode of operation.

The question is what is block:
The 16B of AES or the AES-XTS standard data-unit definition.

My intention here is like AES-XTS data-unit, and you understand it as AES 16B block(at least for this comment 😊).

Please try to understand it as data-unit (replace any "block" word in "data-unit")
Now, can you understand the commit log better without exceptions?

The important point for the API that I want, with you and the community help, to add is the "size" which the application and the drivers\devices must know in order to know how to decrypt an encrypted data.   

For AES-XTS this "size" is not always 16B.

So, if someone get a cipher-text which was encrypted by AES-XTS with initial tweak T and 2 keys K0,K1 it is not enough information in order to do decryption.
The 16B block of AES is not helping here.
Here, the user must know the data-unit size.
The formula D(E(b)) = b that I wrote below must use b as data-unit.
Are you agree?

> > > Block size itself for XTS-AES is always 16 bytes in the first place
> > > which is AES constraint.
> > > 2^20 * 16B -> 2^24B constraint from IEEE 1619-2017, SP800-38E is
> > > data unit length that contains "data unit in bytes/ 16" AES blocks
> > > where last one can be incomplete.
> > > >
> > > > The current cryptodev API doesn't allow the user to select a
> > > > specific block size supported by the devices In addition, there is
> > > > no definition how the IV is detected per block when single
> > > > operation includes
> > > more than one block.
> > >
> > > [Arek] - Do you mean tweak increment per data unit? Like one op as a
> > > data stream (multiple data units) and tweak incremented by pmd?
> >
> > It can be defined differently per algorithm.
> [Arek] - what do you mean?

Maybe in other algorithms standards the IV can be changed differently than AES-XTS, I'm not familiar with all the algorithms 😊.

> > I know from AES-XTS standard that the tweak should be incremented by 1
> > per data-unit.
> > So, yes, here, the driver\device should take care for the incrementation.
> [Arek] - then it should be stated in rte_crypto_sym_op iv comments.

I stated it in the cipher transformation structure where the tweak is defined as IV for AES-XTS.

Do you think we need to add comment in the op too?

> >
> >
> > >
> > > >
> > > > That causes applications to use single operation per block even
> > > > though all the data is continuous in memory what reduces datapath
> > performance.
> > > >
> > > > Add a new feature flag to support multiple block sizes, called
> > > > RTE_CRYPTODEV_FF_CIPHER_MULITPLE_BLOCKS.
> > > > Add a new field in cipher capability, called bsf - block size
> > > > flags, where the devices can report the range of the supported block sizes.
> > > > Add a new cipher transformation field, called block_size, where
> > > > the user can select one block size from the supported range.
> > > >
> > > > All the new fields do not change the size of their structures.
> > > >
> > > > Using flags to report the supported block sizes capability allows
> > > > the devices to report a range simply as same as the user to read it simply.
> > > > Also, thus sizes are usually common and probably will be shared
> > > > between the devices.
> > > >
> > > > Signed-off-by: Matan Azrad <matan@nvidia.com>
> > > > ---
> > > >  lib/librte_cryptodev/rte_crypto_sym.h | 12 ++++++++++++
> > > > lib/librte_cryptodev/rte_cryptodev.h  | 23 ++++++++++++++++++++++-
> > > >  2 files changed, 34 insertions(+), 1 deletion(-)
> > > >
> > > > diff --git a/lib/librte_cryptodev/rte_crypto_sym.h
> > > > b/lib/librte_cryptodev/rte_crypto_sym.h
> > > > index 9d572ec..9a1215d 100644
> > > > --- a/lib/librte_cryptodev/rte_crypto_sym.h
> > > > +++ b/lib/librte_cryptodev/rte_crypto_sym.h
> > > > @@ -265,6 +265,18 @@ struct rte_crypto_cipher_xform {
> > > >                * which can be in the range 7 to 13 inclusive.
> > > >                */
> > > >       } iv;   /**< Initialisation vector parameters */
> > > > +
> > > > +     uint32_t block_size;
> [Arek] - looking from your answers below, this one could just be
> aes_xts_dataunit_len.

Are you sure there is no any other cipher algorithm that have something similar to data-unit of AES-XTS?
 
> > > > +     /**< When RTE_CRYPTODEV_FF_CIPHER_MULITPLE_BLOCKS is
> > > > reported, this is
> > > > +      * the block size of the algorithm, otherwise or when the value is 0,
> > > > +      * use the default block size provided in the capability.
> > > > +      * The value should be in the range defined by the bsf field in the
> > > > +      * cipher capability.
> > >
> > > [Arek] - nowadays algorithms rather don't have different block
> > > sizes, though I see people set this field even for stream ciphers.
> > > If such algorithm would happen it probably could just get a suffix
> > > in crypto_cipher_enum. Otherwise some fixed size array could be added.
> >
> > First, if no different block size per algorithm, why do we need this
> > parameter at all?
> [Arek] - I am not sure but looks like informative, especially that it is only one
> 16bit long field.

Yes, it is 16 bits, but it is not needed, I don't think applications use this capability if it is defined by definition per algorithm.
Looks like candidate for deprecation if so.

> >
> > Second,
> > Cipher block defined to be like this D(E(b)) = b
> > D: decryption function
> > E: encryption function
> > b: plain-text block data.
> >
> > In case of AES-XTS the cipher block size is the data-unit size.
> > There is a big range of optional data, see in standard.
> [Arek] - Currently in DPDK we have 3 block cipher algorithms:
> TDEA(3DES) - 8 byte block, AES - 16 byte block, KASUMI -8byte (but deprecated
> since 3G), Additionally IPsec ietf defines NULL as block cipher with 1 byte len,
> but ETSI doesn't do that with EEA,EIA,NIA-0.

OK

> >
> >
> > > > +      *
> > > > +      * - For AES-XTS it is the size of data-unit, from IEEE Std 1619-2007.
> > > > +      * For-each data-unit in the operation, the tweak(IV) value is
> > > > +      * assigned consecutively starting from the operation assigned tweak.
> > > > +      */
> > > [Arek] - if data unit would be session value (key scope in xts
> > > naming) where the number of units would be taken from, sym_op->len ?
> >
> > Yes, it is already defined there that it must be multiple of block
> > size(data-unit in AES-XTS case).
> [Arek]  - this comment was meant for cipher block modes that needs input
> aligned to block cipher len, like CBC padding.

So, Do you think the current comment is wrong?

> In case of XTS it should be something like : multiple of xform xts_data_unit len
> or one of two:
> - data unit len itself in case device does not support multiple data units.
> - 0 and data unit len would be taken from session/xform in case device does not
> support multiple data units.

Yes, the first one doesn't break API, so it is better.

> >
> > > (For standard storage example: data unit size -> logical block size,
> > > sym_op->len
> > > -> range of consecutive logical blocks.) If so it probably could be
> > > -> session-less op
> > > as this cipher key would be unusable after it.
> > >
> >
> > Can be session and session-less modes.
> >
> > If the user want to operate on different groups of blocks in the same
> > stream he can use the same session(key) with different ops.
> [Arek] - yes, it should be possible to do that if user keep track of tweak value.
> 
> >
> > Am I missing here?
> >
> > > >  };
> > > >
> > > >  /** Symmetric Authentication / Hash Algorithms diff --git
> > > > a/lib/librte_cryptodev/rte_cryptodev.h
> > > > b/lib/librte_cryptodev/rte_cryptodev.h
> > > > index ae34f33..60ba839 100644
> > > > --- a/lib/librte_cryptodev/rte_cryptodev.h
> > > > +++ b/lib/librte_cryptodev/rte_cryptodev.h
> > > > @@ -96,6 +96,19 @@ struct rte_crypto_param_range {  };
> > > >
> > > >  /**
> > > > + * Crypto device supported block size flags for cipher algorithms
> > > > + * Each flag represents single or range of supported block sizes
> > > > +*/ #define RTE_CRYPTO_CIPHER_BSF_ALL 0x1
> > > > +/* All the sizes from the algorithm standard */ #define
> > > > +RTE_CRYPTO_CIPHER_BSF_512_BYTES 0x2 #define
> > > > +RTE_CRYPTO_CIPHER_BSF_520_BYTES 0x4 #define
> > > > +RTE_CRYPTO_CIPHER_BSF_4048_BYTES 0x8 #define
> > > > +RTE_CRYPTO_CIPHER_BSF_4096_BYTES 0x10 #define
> > > > +RTE_CRYPTO_CIPHER_BSF_4160_BYTES 0x20 #define
> > > > +RTE_CRYPTO_CIPHER_BSF_1M_BYTES 0x40
> > > [Arek] - when adding constants source should be attached as well.
> > > > +
> > > > +/**
> > > >   * Symmetric Crypto Capability
> > > >   */
> > > >  struct rte_cryptodev_symmetric_capability { @@ -122,11 +135,19 @@
> > > > struct rte_cryptodev_symmetric_capability {
> > > >                       enum rte_crypto_cipher_algorithm algo;
> > > >                       /**< cipher algorithm */
> > > >                       uint16_t block_size;
> > > > -                     /**< algorithm block size */
> > > > +                     /**<
> > > > +                      * algorithm block size
> > > > +                      * For algorithms support more than single block size,
> > > > +                      * this is the default block size supported by the
> > > > +                      * driver, all the supported sizes are reflected in the
> > > > +                      * bsf field.
> > > > +                      */
> > > >                       struct rte_crypto_param_range key_size;
> > > >                       /**< cipher key size range */
> > > >                       struct rte_crypto_param_range iv_size;
> > > >                       /**< Initialisation vector data size range
> > > > */
> > > > +                     uint32_t bsf;
> > > > +                     /**< Block size flags */
> > > >               } cipher;
> > > >               /**< Symmetric Cipher transform capabilities */
> > > >               struct {
> > > > --
> > > > 1.8.3.1
  
Anoob Joseph Feb. 26, 2021, 5:01 a.m. UTC | #6
Hi Matan,

With the current spec, AES-XTS operation offloading would mean application is expected to track data blocks and the corresponding tweak & cipher stealing, while the final crypto operation gets offloaded to PMD. This proposal aims at moving the entire AES-XTS operation (including tweak update) to PMD. Did I understand the proposal right?

If yes, I believe this is a good feature to be added. But I've few questions,

1. Who is responsible for cipher stealing? Do we expect PMD to pad the final data unit?
2. If we treat AES-XTS as an operation for just encrypting and decrypting a large blob of data, the current proposal would be good enough. But often, AES-XTS is used in disk encryption where selected pages are updated without requiring the entire disk to be decrypted (& encrypted after). Did you consider if we could extend the spec to support such a use case also? (Agreed that we could do page updates by handling tweak etc from application as is being done now).
3. On top level, this requirement has similarities to rte_security. Did you consider that route?

Thanks,
Anoob

> -----Original Message-----
> From: Matan Azrad <matan@nvidia.com>
> Sent: Thursday, February 4, 2021 8:04 PM
> To: dev@dpdk.org
> Cc: akhil.goyal@nxp.com; Declan Doherty <declan.doherty@intel.com>;
> Somalapuram Amaranath <asomalap@amd.com>; Ruifeng Wang
> <ruifeng.wang@arm.com>; Ajit Khaparde <ajit.khaparde@broadcom.com>;
> Anoob Joseph <anoobj@marvell.com>; Fan Zhang
> <roy.fan.zhang@intel.com>; John Griffin <john.griffin@intel.com>; Pablo de
> Lara <pablo.de.lara.guarch@intel.com>; Michael Shamis
> <michaelsh@marvell.com>; Nagadheeraj Rottela
> <rnagadheeraj@marvell.com>; Ankur Dwivedi <adwivedi@marvell.com>;
> Gagandeep Singh <g.singh@nxp.com>; Jay Zhou
> <jianjay.zhou@huawei.com>
> Subject: [EXT] [PATCH] cryptodev: support multiple cipher block sizes
> 
> External Email
> 
> ----------------------------------------------------------------------
> In cryptography, a block cipher is a deterministic algorithm operating on
> fixed-length groups of bits, called blocks.
> 
> A block cipher consists of two paired algorithms, one for encryption and the
> other for decryption. Both algorithms accept two inputs:
> an input block of size n bits and a key of size k bits; and both yield an n-bit
> output block. The decryption algorithm is defined to be the inverse function
> of the encryption.
> 
> Some cipher algorithms support multiple block sizes, e.g. AES-XTS supports
> any block size in range [16B, 2^24B], in this case, A plain-text data, divided
> into N amount of n-bits blocks, which is encrypted to the same data size,
> cipher-text, must be decrypted in the same division of N amount of n-bits
> blocks in order to get the same plain-text data.
> 
> The current cryptodev API doesn't allow the user to select a specific block
> size supported by the devices In addition, there is no definition how the IV is
> detected per block when single operation includes more than one block.
> 
> That causes applications to use single operation per block even though all the
> data is continuous in memory what reduces datapath performance.
> 
> Add a new feature flag to support multiple block sizes, called
> RTE_CRYPTODEV_FF_CIPHER_MULITPLE_BLOCKS.
> Add a new field in cipher capability, called bsf - block size flags, where the
> devices can report the range of the supported block sizes.
> Add a new cipher transformation field, called block_size, where the user can
> select one block size from the supported range.
> 
> All the new fields do not change the size of their structures.
> 
> Using flags to report the supported block sizes capability allows the devices
> to report a range simply as same as the user to read it simply.
> Also, thus sizes are usually common and probably will be shared between the
> devices.
> 
> Signed-off-by: Matan Azrad <matan@nvidia.com>
> ---
>  lib/librte_cryptodev/rte_crypto_sym.h | 12 ++++++++++++
> lib/librte_cryptodev/rte_cryptodev.h  | 23 ++++++++++++++++++++++-
>  2 files changed, 34 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/librte_cryptodev/rte_crypto_sym.h
> b/lib/librte_cryptodev/rte_crypto_sym.h
> index 9d572ec..9a1215d 100644
> --- a/lib/librte_cryptodev/rte_crypto_sym.h
> +++ b/lib/librte_cryptodev/rte_crypto_sym.h
> @@ -265,6 +265,18 @@ struct rte_crypto_cipher_xform {
>  		 * which can be in the range 7 to 13 inclusive.
>  		 */
>  	} iv;	/**< Initialisation vector parameters */
> +
> +	uint32_t block_size;
> +	/**< When RTE_CRYPTODEV_FF_CIPHER_MULITPLE_BLOCKS is
> reported, this is
> +	 * the block size of the algorithm, otherwise or when the value is 0,
> +	 * use the default block size provided in the capability.
> +	 * The value should be in the range defined by the bsf field in the
> +	 * cipher capability.
> +	 *
> +	 * - For AES-XTS it is the size of data-unit, from IEEE Std 1619-2007.
> +	 * For-each data-unit in the operation, the tweak(IV) value is
> +	 * assigned consecutively starting from the operation assigned
> tweak.
> +	 */
>  };
> 
>  /** Symmetric Authentication / Hash Algorithms diff --git
> a/lib/librte_cryptodev/rte_cryptodev.h
> b/lib/librte_cryptodev/rte_cryptodev.h
> index ae34f33..60ba839 100644
> --- a/lib/librte_cryptodev/rte_cryptodev.h
> +++ b/lib/librte_cryptodev/rte_cryptodev.h
> @@ -96,6 +96,19 @@ struct rte_crypto_param_range {  };
> 
>  /**
> + * Crypto device supported block size flags for cipher algorithms
> + * Each flag represents single or range of supported block sizes  */
> +#define RTE_CRYPTO_CIPHER_BSF_ALL 0x1
> +/* All the sizes from the algorithm standard */ #define
> +RTE_CRYPTO_CIPHER_BSF_512_BYTES 0x2 #define
> +RTE_CRYPTO_CIPHER_BSF_520_BYTES 0x4 #define
> +RTE_CRYPTO_CIPHER_BSF_4048_BYTES 0x8 #define
> +RTE_CRYPTO_CIPHER_BSF_4096_BYTES 0x10 #define
> +RTE_CRYPTO_CIPHER_BSF_4160_BYTES 0x20 #define
> +RTE_CRYPTO_CIPHER_BSF_1M_BYTES 0x40
> +
> +/**
>   * Symmetric Crypto Capability
>   */
>  struct rte_cryptodev_symmetric_capability { @@ -122,11 +135,19 @@ struct
> rte_cryptodev_symmetric_capability {
>  			enum rte_crypto_cipher_algorithm algo;
>  			/**< cipher algorithm */
>  			uint16_t block_size;
> -			/**< algorithm block size */
> +			/**<
> +			 * algorithm block size
> +			 * For algorithms support more than single block size,
> +			 * this is the default block size supported by the
> +			 * driver, all the supported sizes are reflected in the
> +			 * bsf field.
> +			 */
>  			struct rte_crypto_param_range key_size;
>  			/**< cipher key size range */
>  			struct rte_crypto_param_range iv_size;
>  			/**< Initialisation vector data size range */
> +			uint32_t bsf;
> +			/**< Block size flags */
>  		} cipher;
>  		/**< Symmetric Cipher transform capabilities */
>  		struct {
> --
> 1.8.3.1
  
Arkadiusz Kusztal Feb. 26, 2021, 7:50 a.m. UTC | #7
> -----Original Message-----
> From: Matan Azrad <matan@nvidia.com>
> Sent: Monday, February 8, 2021 7:23 PM
> To: Kusztal, ArkadiuszX <arkadiuszx.kusztal@intel.com>; dev@dpdk.org
> Cc: akhil.goyal@nxp.com; Doherty, Declan <declan.doherty@intel.com>;
> Somalapuram Amaranath <asomalap@amd.com>; Ruifeng Wang
> <ruifeng.wang@arm.com>; Ajit Khaparde <ajit.khaparde@broadcom.com>;
> Anoob Joseph <anoobj@marvell.com>; Zhang, Roy Fan
> <roy.fan.zhang@intel.com>; Griffin, John <john.griffin@intel.com>; De Lara
> Guarch, Pablo <pablo.de.lara.guarch@intel.com>; Michael Shamis
> <michaelsh@marvell.com>; Nagadheeraj Rottela
> <rnagadheeraj@marvell.com>; Ankur Dwivedi <adwivedi@marvell.com>;
> Gagandeep Singh <g.singh@nxp.com>; Jay Zhou <jianjay.zhou@huawei.com>
> Subject: RE: [dpdk-dev] [PATCH] cryptodev: support multiple cipher block sizes
> 
> Hi Kusztal
> 
> First, thank you for this review and the suggestions.
> 
> From: Kusztal, ArkadiuszX
> > > > > Subject: [dpdk-dev] [PATCH] cryptodev: support multiple cipher
> > > > > block sizes
> > > > >
> > > > > In cryptography, a block cipher is a deterministic algorithm
> > > > > operating on fixed- length groups of bits, called blocks.
> > > > >
> > > > > A block cipher consists of two paired algorithms, one for
> > > > > encryption and the other for decryption. Both algorithms accept
> > > > > two
> > inputs:
> > > > > an input block of size n bits and a key of size k bits; and both
> > > > > yield an n-bit output block. The decryption algorithm is defined
> > > > > to be the inverse function of the encryption.
> > > > >
> > > > > Some cipher algorithms support multiple block sizes, e.g.
> > > > > AES-XTS supports any block size in range [16B, 2^24B], in this
> > > > > case, A plain-text data, divided into N amount of n-bits blocks,
> > > > > which is encrypted to the same data size, cipher-text, must be
> > > > > decrypted in the same division of N amount of n-bits blocks in
> > > > > order to get the same plain-text
> > > > data.
> > > > [Arek] - Except that the last data block does not need to be n-bit
> > > > long, beside that and lack of chaining it makes XTS no different
> > > > to any other block cipher mode of operation.
> 
> The question is what is block:
> The 16B of AES or the AES-XTS standard data-unit definition.
> 
> My intention here is like AES-XTS data-unit, and you understand it as AES 16B
> block(at least for this comment 😊).
[Arek] - yes, and right now you are correct. Data unit of data stream, not algorithm block size.
> 
> Please try to understand it as data-unit (replace any "block" word in "data-unit")
> Now, can you understand the commit log better without exceptions?
> 
> The important point for the API that I want, with you and the community help,
> to add is the "size" which the application and the drivers\devices must know in
> order to know how to decrypt an encrypted data.
> 
> For AES-XTS this "size" is not always 16B.
> 
> So, if someone get a cipher-text which was encrypted by AES-XTS with initial
> tweak T and 2 keys K0,K1 it is not enough information in order to do decryption.
> The 16B block of AES is not helping here.
> Here, the user must know the data-unit size.
> The formula D(E(b)) = b that I wrote below must use b as data-unit.
> Are you agree?
> 
> > > > Block size itself for XTS-AES is always 16 bytes in the first
> > > > place which is AES constraint.
> > > > 2^20 * 16B -> 2^24B constraint from IEEE 1619-2017, SP800-38E is
> > > > data unit length that contains "data unit in bytes/ 16" AES blocks
> > > > where last one can be incomplete.
> > > > >
> > > > > The current cryptodev API doesn't allow the user to select a
> > > > > specific block size supported by the devices In addition, there
> > > > > is no definition how the IV is detected per block when single
> > > > > operation includes
> > > > more than one block.
> > > >
> > > > [Arek] - Do you mean tweak increment per data unit? Like one op as
> > > > a data stream (multiple data units) and tweak incremented by pmd?
> > >
> > > It can be defined differently per algorithm.
> > [Arek] - what do you mean?
> 
> Maybe in other algorithms standards the IV can be changed differently than AES-
> XTS, I'm not familiar with all the algorithms 😊.
> 
> > > I know from AES-XTS standard that the tweak should be incremented by
> > > 1 per data-unit.
> > > So, yes, here, the driver\device should take care for the incrementation.
> > [Arek] - then it should be stated in rte_crypto_sym_op iv comments.
> 
> I stated it in the cipher transformation structure where the tweak is defined as IV
> for AES-XTS.
> 
> Do you think we need to add comment in the op too?
[Arek] - on the other hand no, having it in xform should be ok, especially that no really good place to put it in op
> 
> > >
> > >
> > > >
> > > > >
> > > > > That causes applications to use single operation per block even
> > > > > though all the data is continuous in memory what reduces
> > > > > datapath
> > > performance.
> > > > >
> > > > > Add a new feature flag to support multiple block sizes, called
> > > > > RTE_CRYPTODEV_FF_CIPHER_MULITPLE_BLOCKS.
> > > > > Add a new field in cipher capability, called bsf - block size
> > > > > flags, where the devices can report the range of the supported block
> sizes.
> > > > > Add a new cipher transformation field, called block_size, where
> > > > > the user can select one block size from the supported range.
> > > > >
> > > > > All the new fields do not change the size of their structures.
> > > > >
> > > > > Using flags to report the supported block sizes capability
> > > > > allows the devices to report a range simply as same as the user to read it
> simply.
> > > > > Also, thus sizes are usually common and probably will be shared
> > > > > between the devices.
> > > > >
> > > > > Signed-off-by: Matan Azrad <matan@nvidia.com>
> > > > > ---
> > > > >  lib/librte_cryptodev/rte_crypto_sym.h | 12 ++++++++++++
> > > > > lib/librte_cryptodev/rte_cryptodev.h  | 23
> > > > > ++++++++++++++++++++++-
> > > > >  2 files changed, 34 insertions(+), 1 deletion(-)
> > > > >
> > > > > diff --git a/lib/librte_cryptodev/rte_crypto_sym.h
> > > > > b/lib/librte_cryptodev/rte_crypto_sym.h
> > > > > index 9d572ec..9a1215d 100644
> > > > > --- a/lib/librte_cryptodev/rte_crypto_sym.h
> > > > > +++ b/lib/librte_cryptodev/rte_crypto_sym.h
> > > > > @@ -265,6 +265,18 @@ struct rte_crypto_cipher_xform {
> > > > >                * which can be in the range 7 to 13 inclusive.
> > > > >                */
> > > > >       } iv;   /**< Initialisation vector parameters */
> > > > > +
> > > > > +     uint32_t block_size;
> > [Arek] - looking from your answers below, this one could just be
> > aes_xts_dataunit_len.
> 
> Are you sure there is no any other cipher algorithm that have something similar
> to data-unit of AES-XTS?
[Arek] - from what we currently have - no by definition but I agree, it actually could be something like dataunit_len;
> 
> > > > > +     /**< When RTE_CRYPTODEV_FF_CIPHER_MULITPLE_BLOCKS is
> > > > > reported, this is
> > > > > +      * the block size of the algorithm, otherwise or when the value is 0,
> > > > > +      * use the default block size provided in the capability.
> > > > > +      * The value should be in the range defined by the bsf field in the
> > > > > +      * cipher capability.
> > > >
> > > > [Arek] - nowadays algorithms rather don't have different block
> > > > sizes, though I see people set this field even for stream ciphers.
> > > > If such algorithm would happen it probably could just get a suffix
> > > > in crypto_cipher_enum. Otherwise some fixed size array could be added.
> > >
> > > First, if no different block size per algorithm, why do we need this
> > > parameter at all?
> > [Arek] - I am not sure but looks like informative, especially that it
> > is only one 16bit long field.
> 
> Yes, it is 16 bits, but it is not needed, I don't think applications use this capability
> if it is defined by definition per algorithm.
> Looks like candidate for deprecation if so.
[Arek] - this actually should be for another discussion, as for varying block size RC5 can have different block sizes (but you will rather not find it in modern cipher suites).
Another option is wide block encryption though I am not sure what is current popularity of it.
From the network perspective current trend is to go for stream ciphers (GCM, CCM, ChaCha) and stream cipher is obvious choice for wireless.

> 
> > >
> > > Second,
> > > Cipher block defined to be like this D(E(b)) = b
> > > D: decryption function
> > > E: encryption function
> > > b: plain-text block data.
> > >
> > > In case of AES-XTS the cipher block size is the data-unit size.
> > > There is a big range of optional data, see in standard.
> > [Arek] - Currently in DPDK we have 3 block cipher algorithms:
> > TDEA(3DES) - 8 byte block, AES - 16 byte block, KASUMI -8byte (but
> > deprecated since 3G), Additionally IPsec ietf defines NULL as block
> > cipher with 1 byte len, but ETSI doesn't do that with EEA,EIA,NIA-0.
> 
> OK
> 
> > >
> > >
> > > > > +      *
> > > > > +      * - For AES-XTS it is the size of data-unit, from IEEE Std 1619-2007.
> > > > > +      * For-each data-unit in the operation, the tweak(IV) value is
> > > > > +      * assigned consecutively starting from the operation assigned
> tweak.
> > > > > +      */
> > > > [Arek] - if data unit would be session value (key scope in xts
> > > > naming) where the number of units would be taken from, sym_op->len ?
> > >
> > > Yes, it is already defined there that it must be multiple of block
> > > size(data-unit in AES-XTS case).
> > [Arek]  - this comment was meant for cipher block modes that needs
> > input aligned to block cipher len, like CBC padding.
> 
> So, Do you think the current comment is wrong?
Arek] - yes, current comment is wrong. It does not allow XTS data unit that is not multiple of block size.
 
> 
> > In case of XTS it should be something like : multiple of xform
> > xts_data_unit len or one of two:
> > - data unit len itself in case device does not support multiple data units.
> > - 0 and data unit len would be taken from session/xform in case device
> > does not support multiple data units.
> 
> Yes, the first one doesn't break API, so it is better.
[Arek] - ok so something like:
Multiple of xform xts_data_unit or data unit len itself in case device does not support multiple data units.

Maybe some additional option would be needed if PMD can work both ways (with and without auto tweak increment).

> 
> > >
> > > > (For standard storage example: data unit size -> logical block
> > > > size, sym_op->len
> > > > -> range of consecutive logical blocks.) If so it probably could
> > > > -> be session-less op
> > > > as this cipher key would be unusable after it.
> > > >
> > >
> > > Can be session and session-less modes.
> > >
> > > If the user want to operate on different groups of blocks in the
> > > same stream he can use the same session(key) with different ops.
> > [Arek] - yes, it should be possible to do that if user keep track of tweak value.
> >
> > >
> > > Am I missing here?
> > >
> > > > >  };
> > > > >
> > > > >  /** Symmetric Authentication / Hash Algorithms diff --git
> > > > > a/lib/librte_cryptodev/rte_cryptodev.h
> > > > > b/lib/librte_cryptodev/rte_cryptodev.h
> > > > > index ae34f33..60ba839 100644
> > > > > --- a/lib/librte_cryptodev/rte_cryptodev.h
> > > > > +++ b/lib/librte_cryptodev/rte_cryptodev.h
> > > > > @@ -96,6 +96,19 @@ struct rte_crypto_param_range {  };
> > > > >
> > > > >  /**
> > > > > + * Crypto device supported block size flags for cipher
> > > > > +algorithms
> > > > > + * Each flag represents single or range of supported block
> > > > > +sizes */ #define RTE_CRYPTO_CIPHER_BSF_ALL 0x1
> > > > > +/* All the sizes from the algorithm standard */ #define
> > > > > +RTE_CRYPTO_CIPHER_BSF_512_BYTES 0x2 #define
> > > > > +RTE_CRYPTO_CIPHER_BSF_520_BYTES 0x4 #define
> > > > > +RTE_CRYPTO_CIPHER_BSF_4048_BYTES 0x8 #define
> > > > > +RTE_CRYPTO_CIPHER_BSF_4096_BYTES 0x10 #define
> > > > > +RTE_CRYPTO_CIPHER_BSF_4160_BYTES 0x20 #define
> > > > > +RTE_CRYPTO_CIPHER_BSF_1M_BYTES 0x40
> > > > [Arek] - when adding constants source should be attached as well.
> > > > > +
> > > > > +/**
> > > > >   * Symmetric Crypto Capability
> > > > >   */
> > > > >  struct rte_cryptodev_symmetric_capability { @@ -122,11 +135,19
> > > > > @@ struct rte_cryptodev_symmetric_capability {
> > > > >                       enum rte_crypto_cipher_algorithm algo;
> > > > >                       /**< cipher algorithm */
> > > > >                       uint16_t block_size;
> > > > > -                     /**< algorithm block size */
> > > > > +                     /**<
> > > > > +                      * algorithm block size
> > > > > +                      * For algorithms support more than single block size,
> > > > > +                      * this is the default block size supported by the
> > > > > +                      * driver, all the supported sizes are reflected in the
> > > > > +                      * bsf field.
> > > > > +                      */
> > > > >                       struct rte_crypto_param_range key_size;
> > > > >                       /**< cipher key size range */
> > > > >                       struct rte_crypto_param_range iv_size;
> > > > >                       /**< Initialisation vector data size range
> > > > > */
> > > > > +                     uint32_t bsf;
> > > > > +                     /**< Block size flags */
> > > > >               } cipher;
> > > > >               /**< Symmetric Cipher transform capabilities */
> > > > >               struct {
> > > > > --
> > > > > 1.8.3.1
  
Matan Azrad March 1, 2021, 7:55 a.m. UTC | #8
From: Anoob Joseph
> Hi Matan,
> 
> With the current spec, AES-XTS operation offloading would mean application is
> expected to track data blocks and the corresponding tweak & cipher stealing,
> while the final crypto operation gets offloaded to PMD. This proposal aims at
> moving the entire AES-XTS operation (including tweak update) to PMD. Did I
> understand the proposal right?

Yes, we want to define well what is the "data-unit" size from AES-XTS standard per session (or operation), then, to allow to the PMD users to send multiple data-units in one operation.
The initial tweak(for the first data-unit) will be set by the user in the operation, and according the standard(probably what you call "spec") the rest data-units tweak values should  be assigned consecutively, so this part will be done by the PMD\device in multiple data-units case. 

> 
> If yes, I believe this is a good feature to be added. But I've few questions,
> 
> 1. Who is responsible for cipher stealing? Do we expect PMD to pad the final
> data unit?

Sure, this is the offload, no? to support what the algorithm defines.

> 2. If we treat AES-XTS as an operation for just encrypting and decrypting a large
> blob of data, the current proposal would be good enough. But often, AES-XTS is
> used in disk encryption where selected pages are updated without requiring the
> entire disk to be decrypted (& encrypted after). Did you consider if we could
> extend the spec to support such a use case also? (Agreed that we could do page
> updates by handling tweak etc from application as is being done now).

Sure,
For any amount of consecutive data-units, the user can do encrypt\decrypt in one operation: 1, 2, all the disk..... in one mbuf or chain of mbufs...
But the blob of data must be multiple of the session data-unit size parameter that I want to define now in the session API(\ transformation).

> 3. On top level, this requirement has similarities to rte_security. Did you
> consider that route?

No, but why do you care? The regular crypto API should support it too, it is basic...


> Thanks,
> Anoob

Thank you.
 
> > -----Original Message-----
> > From: Matan Azrad <matan@nvidia.com>
> > Sent: Thursday, February 4, 2021 8:04 PM
> > To: dev@dpdk.org
> > Cc: akhil.goyal@nxp.com; Declan Doherty <declan.doherty@intel.com>;
> > Somalapuram Amaranath <asomalap@amd.com>; Ruifeng Wang
> > <ruifeng.wang@arm.com>; Ajit Khaparde <ajit.khaparde@broadcom.com>;
> > Anoob Joseph <anoobj@marvell.com>; Fan Zhang
> > <roy.fan.zhang@intel.com>; John Griffin <john.griffin@intel.com>;
> > Pablo de Lara <pablo.de.lara.guarch@intel.com>; Michael Shamis
> > <michaelsh@marvell.com>; Nagadheeraj Rottela
> > <rnagadheeraj@marvell.com>; Ankur Dwivedi <adwivedi@marvell.com>;
> > Gagandeep Singh <g.singh@nxp.com>; Jay Zhou <jianjay.zhou@huawei.com>
> > Subject: [EXT] [PATCH] cryptodev: support multiple cipher block sizes
> >
> > External Email
> >
> > ----------------------------------------------------------------------
> > In cryptography, a block cipher is a deterministic algorithm operating
> > on fixed-length groups of bits, called blocks.
> >
> > A block cipher consists of two paired algorithms, one for encryption
> > and the other for decryption. Both algorithms accept two inputs:
> > an input block of size n bits and a key of size k bits; and both yield
> > an n-bit output block. The decryption algorithm is defined to be the
> > inverse function of the encryption.
> >
> > Some cipher algorithms support multiple block sizes, e.g. AES-XTS
> > supports any block size in range [16B, 2^24B], in this case, A
> > plain-text data, divided into N amount of n-bits blocks, which is
> > encrypted to the same data size, cipher-text, must be decrypted in the
> > same division of N amount of n-bits blocks in order to get the same plain-text
> data.
> >
> > The current cryptodev API doesn't allow the user to select a specific
> > block size supported by the devices In addition, there is no
> > definition how the IV is detected per block when single operation includes
> more than one block.
> >
> > That causes applications to use single operation per block even though
> > all the data is continuous in memory what reduces datapath performance.
> >
> > Add a new feature flag to support multiple block sizes, called
> > RTE_CRYPTODEV_FF_CIPHER_MULITPLE_BLOCKS.
> > Add a new field in cipher capability, called bsf - block size flags,
> > where the devices can report the range of the supported block sizes.
> > Add a new cipher transformation field, called block_size, where the
> > user can select one block size from the supported range.
> >
> > All the new fields do not change the size of their structures.
> >
> > Using flags to report the supported block sizes capability allows the
> > devices to report a range simply as same as the user to read it simply.
> > Also, thus sizes are usually common and probably will be shared
> > between the devices.
> >
> > Signed-off-by: Matan Azrad <matan@nvidia.com>
> > ---
> >  lib/librte_cryptodev/rte_crypto_sym.h | 12 ++++++++++++
> > lib/librte_cryptodev/rte_cryptodev.h  | 23 ++++++++++++++++++++++-
> >  2 files changed, 34 insertions(+), 1 deletion(-)
> >
> > diff --git a/lib/librte_cryptodev/rte_crypto_sym.h
> > b/lib/librte_cryptodev/rte_crypto_sym.h
> > index 9d572ec..9a1215d 100644
> > --- a/lib/librte_cryptodev/rte_crypto_sym.h
> > +++ b/lib/librte_cryptodev/rte_crypto_sym.h
> > @@ -265,6 +265,18 @@ struct rte_crypto_cipher_xform {
> >                * which can be in the range 7 to 13 inclusive.
> >                */
> >       } iv;   /**< Initialisation vector parameters */
> > +
> > +     uint32_t block_size;
> > +     /**< When RTE_CRYPTODEV_FF_CIPHER_MULITPLE_BLOCKS is
> > reported, this is
> > +      * the block size of the algorithm, otherwise or when the value is 0,
> > +      * use the default block size provided in the capability.
> > +      * The value should be in the range defined by the bsf field in the
> > +      * cipher capability.
> > +      *
> > +      * - For AES-XTS it is the size of data-unit, from IEEE Std 1619-2007.
> > +      * For-each data-unit in the operation, the tweak(IV) value is
> > +      * assigned consecutively starting from the operation assigned
> > tweak.
> > +      */
> >  };
> >
> >  /** Symmetric Authentication / Hash Algorithms diff --git
> > a/lib/librte_cryptodev/rte_cryptodev.h
> > b/lib/librte_cryptodev/rte_cryptodev.h
> > index ae34f33..60ba839 100644
> > --- a/lib/librte_cryptodev/rte_cryptodev.h
> > +++ b/lib/librte_cryptodev/rte_cryptodev.h
> > @@ -96,6 +96,19 @@ struct rte_crypto_param_range {  };
> >
> >  /**
> > + * Crypto device supported block size flags for cipher algorithms
> > + * Each flag represents single or range of supported block sizes  */
> > +#define RTE_CRYPTO_CIPHER_BSF_ALL 0x1
> > +/* All the sizes from the algorithm standard */ #define
> > +RTE_CRYPTO_CIPHER_BSF_512_BYTES 0x2 #define
> > +RTE_CRYPTO_CIPHER_BSF_520_BYTES 0x4 #define
> > +RTE_CRYPTO_CIPHER_BSF_4048_BYTES 0x8 #define
> > +RTE_CRYPTO_CIPHER_BSF_4096_BYTES 0x10 #define
> > +RTE_CRYPTO_CIPHER_BSF_4160_BYTES 0x20 #define
> > +RTE_CRYPTO_CIPHER_BSF_1M_BYTES 0x40
> > +
> > +/**
> >   * Symmetric Crypto Capability
> >   */
> >  struct rte_cryptodev_symmetric_capability { @@ -122,11 +135,19 @@
> > struct rte_cryptodev_symmetric_capability {
> >                       enum rte_crypto_cipher_algorithm algo;
> >                       /**< cipher algorithm */
> >                       uint16_t block_size;
> > -                     /**< algorithm block size */
> > +                     /**<
> > +                      * algorithm block size
> > +                      * For algorithms support more than single block size,
> > +                      * this is the default block size supported by the
> > +                      * driver, all the supported sizes are reflected in the
> > +                      * bsf field.
> > +                      */
> >                       struct rte_crypto_param_range key_size;
> >                       /**< cipher key size range */
> >                       struct rte_crypto_param_range iv_size;
> >                       /**< Initialisation vector data size range */
> > +                     uint32_t bsf;
> > +                     /**< Block size flags */
> >               } cipher;
> >               /**< Symmetric Cipher transform capabilities */
> >               struct {
> > --
> > 1.8.3.1
  
Arkadiusz Kusztal March 1, 2021, 9:29 a.m. UTC | #9
> -----Original Message-----
> From: dev <dev-bounces@dpdk.org> On Behalf Of Matan Azrad
> Sent: Monday, March 1, 2021 8:56 AM
> To: Anoob Joseph <anoobj@marvell.com>; dev@dpdk.org
> Cc: Doherty, Declan <declan.doherty@intel.com>; Somalapuram Amaranath
> <asomalap@amd.com>; Ruifeng Wang <ruifeng.wang@arm.com>; Ajit
> Khaparde <ajit.khaparde@broadcom.com>; Zhang, Roy Fan
> <roy.fan.zhang@intel.com>; Griffin, John <john.griffin@intel.com>; De Lara
> Guarch, Pablo <pablo.de.lara.guarch@intel.com>; Michael Shamis
> <michaelsh@marvell.com>; Nagadheeraj Rottela
> <rnagadheeraj@marvell.com>; Ankur Dwivedi <adwivedi@marvell.com>;
> Gagandeep Singh <g.singh@nxp.com>; Jay Zhou <jianjay.zhou@huawei.com>;
> Akhil Goyal <gakhil@marvell.com>; Jerin Jacob Kollanukkaran
> <jerinj@marvell.com>
> Subject: Re: [dpdk-dev] [EXT] [PATCH] cryptodev: support multiple cipher block
> sizes
> 
> 
> 
> From: Anoob Joseph
> > Hi Matan,
> >
> > With the current spec, AES-XTS operation offloading would mean
> > application is expected to track data blocks and the corresponding
> > tweak & cipher stealing, while the final crypto operation gets
> > offloaded to PMD. This proposal aims at moving the entire AES-XTS
> > operation (including tweak update) to PMD. Did I understand the proposal
> right?
> 
> Yes, we want to define well what is the "data-unit" size from AES-XTS standard
> per session (or operation), then, to allow to the PMD users to send multiple
> data-units in one operation.
> The initial tweak(for the first data-unit) will be set by the user in the operation,
> and according the standard(probably what you call "spec") the rest data-units
> tweak values should  be assigned consecutively, so this part will be done by the
> PMD\device in multiple data-units case.
> 
> >
> > If yes, I believe this is a good feature to be added. But I've few
> > questions,
> >
> > 1. Who is responsible for cipher stealing? Do we expect PMD to pad the
> > final data unit?
>
[Arek] - data units (including final) are of the same size, ciphertext stealing may concern only last AES block from every data unit if data unit size is not multiple of AES block size.
As there is ciphertext stealing no padding needed.
 
> Sure, this is the offload, no? to support what the algorithm defines.
.
> 
> > 2. If we treat AES-XTS as an operation for just encrypting and
> > decrypting a large blob of data, the current proposal would be good
> > enough. But often, AES-XTS is used in disk encryption where selected
> > pages are updated without requiring the entire disk to be decrypted (&
> > encrypted after). Did you consider if we could extend the spec to
> > support such a use case also? (Agreed that we could do page updates by
> handling tweak etc from application as is being done now).
> 
> Sure,
> For any amount of consecutive data-units, the user can do encrypt\decrypt in
> one operation: 1, 2, all the disk..... in one mbuf or chain of mbufs...
> But the blob of data must be multiple of the session data-unit size parameter
> that I want to define now in the session API(\ transformation).
> 
> > 3. On top level, this requirement has similarities to rte_security.
> > Did you consider that route?
> 
> No, but why do you care? The regular crypto API should support it too, it is
> basic...
> 
> 
> > Thanks,
> > Anoob
> 
> Thank you.
> 
> > > -----Original Message-----
> > > From: Matan Azrad <matan@nvidia.com>
> > > Sent: Thursday, February 4, 2021 8:04 PM
> > > To: dev@dpdk.org
> > > Cc: akhil.goyal@nxp.com; Declan Doherty <declan.doherty@intel.com>;
> > > Somalapuram Amaranath <asomalap@amd.com>; Ruifeng Wang
> > > <ruifeng.wang@arm.com>; Ajit Khaparde <ajit.khaparde@broadcom.com>;
> > > Anoob Joseph <anoobj@marvell.com>; Fan Zhang
> > > <roy.fan.zhang@intel.com>; John Griffin <john.griffin@intel.com>;
> > > Pablo de Lara <pablo.de.lara.guarch@intel.com>; Michael Shamis
> > > <michaelsh@marvell.com>; Nagadheeraj Rottela
> > > <rnagadheeraj@marvell.com>; Ankur Dwivedi <adwivedi@marvell.com>;
> > > Gagandeep Singh <g.singh@nxp.com>; Jay Zhou
> > > <jianjay.zhou@huawei.com>
> > > Subject: [EXT] [PATCH] cryptodev: support multiple cipher block
> > > sizes
> > >
> > > External Email
> > >
> > > --------------------------------------------------------------------
> > > -- In cryptography, a block cipher is a deterministic algorithm
> > > operating on fixed-length groups of bits, called blocks.
> > >
> > > A block cipher consists of two paired algorithms, one for encryption
> > > and the other for decryption. Both algorithms accept two inputs:
> > > an input block of size n bits and a key of size k bits; and both
> > > yield an n-bit output block. The decryption algorithm is defined to
> > > be the inverse function of the encryption.
> > >
> > > Some cipher algorithms support multiple block sizes, e.g. AES-XTS
> > > supports any block size in range [16B, 2^24B], in this case, A
> > > plain-text data, divided into N amount of n-bits blocks, which is
> > > encrypted to the same data size, cipher-text, must be decrypted in
> > > the same division of N amount of n-bits blocks in order to get the
> > > same plain-text
> > data.
> > >
> > > The current cryptodev API doesn't allow the user to select a
> > > specific block size supported by the devices In addition, there is
> > > no definition how the IV is detected per block when single operation
> > > includes
> > more than one block.
> > >
> > > That causes applications to use single operation per block even
> > > though all the data is continuous in memory what reduces datapath
> performance.
> > >
> > > Add a new feature flag to support multiple block sizes, called
> > > RTE_CRYPTODEV_FF_CIPHER_MULITPLE_BLOCKS.
> > > Add a new field in cipher capability, called bsf - block size flags,
> > > where the devices can report the range of the supported block sizes.
> > > Add a new cipher transformation field, called block_size, where the
> > > user can select one block size from the supported range.
> > >
> > > All the new fields do not change the size of their structures.
> > >
> > > Using flags to report the supported block sizes capability allows
> > > the devices to report a range simply as same as the user to read it simply.
> > > Also, thus sizes are usually common and probably will be shared
> > > between the devices.
> > >
> > > Signed-off-by: Matan Azrad <matan@nvidia.com>
> > > ---
> > >  lib/librte_cryptodev/rte_crypto_sym.h | 12 ++++++++++++
> > > lib/librte_cryptodev/rte_cryptodev.h  | 23 ++++++++++++++++++++++-
> > >  2 files changed, 34 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/lib/librte_cryptodev/rte_crypto_sym.h
> > > b/lib/librte_cryptodev/rte_crypto_sym.h
> > > index 9d572ec..9a1215d 100644
> > > --- a/lib/librte_cryptodev/rte_crypto_sym.h
> > > +++ b/lib/librte_cryptodev/rte_crypto_sym.h
> > > @@ -265,6 +265,18 @@ struct rte_crypto_cipher_xform {
> > >                * which can be in the range 7 to 13 inclusive.
> > >                */
> > >       } iv;   /**< Initialisation vector parameters */
> > > +
> > > +     uint32_t block_size;
> > > +     /**< When RTE_CRYPTODEV_FF_CIPHER_MULITPLE_BLOCKS is
> > > reported, this is
> > > +      * the block size of the algorithm, otherwise or when the value is 0,
> > > +      * use the default block size provided in the capability.
> > > +      * The value should be in the range defined by the bsf field in the
> > > +      * cipher capability.
> > > +      *
> > > +      * - For AES-XTS it is the size of data-unit, from IEEE Std 1619-2007.
> > > +      * For-each data-unit in the operation, the tweak(IV) value is
> > > +      * assigned consecutively starting from the operation assigned
> > > tweak.
> > > +      */
> > >  };
> > >
> > >  /** Symmetric Authentication / Hash Algorithms diff --git
> > > a/lib/librte_cryptodev/rte_cryptodev.h
> > > b/lib/librte_cryptodev/rte_cryptodev.h
> > > index ae34f33..60ba839 100644
> > > --- a/lib/librte_cryptodev/rte_cryptodev.h
> > > +++ b/lib/librte_cryptodev/rte_cryptodev.h
> > > @@ -96,6 +96,19 @@ struct rte_crypto_param_range {  };
> > >
> > >  /**
> > > + * Crypto device supported block size flags for cipher algorithms
> > > + * Each flag represents single or range of supported block sizes
> > > +*/ #define RTE_CRYPTO_CIPHER_BSF_ALL 0x1
> > > +/* All the sizes from the algorithm standard */ #define
> > > +RTE_CRYPTO_CIPHER_BSF_512_BYTES 0x2 #define
> > > +RTE_CRYPTO_CIPHER_BSF_520_BYTES 0x4 #define
> > > +RTE_CRYPTO_CIPHER_BSF_4048_BYTES 0x8 #define
> > > +RTE_CRYPTO_CIPHER_BSF_4096_BYTES 0x10 #define
> > > +RTE_CRYPTO_CIPHER_BSF_4160_BYTES 0x20 #define
> > > +RTE_CRYPTO_CIPHER_BSF_1M_BYTES 0x40
> > > +
> > > +/**
> > >   * Symmetric Crypto Capability
> > >   */
> > >  struct rte_cryptodev_symmetric_capability { @@ -122,11 +135,19 @@
> > > struct rte_cryptodev_symmetric_capability {
> > >                       enum rte_crypto_cipher_algorithm algo;
> > >                       /**< cipher algorithm */
> > >                       uint16_t block_size;
> > > -                     /**< algorithm block size */
> > > +                     /**<
> > > +                      * algorithm block size
> > > +                      * For algorithms support more than single block size,
> > > +                      * this is the default block size supported by the
> > > +                      * driver, all the supported sizes are reflected in the
> > > +                      * bsf field.
> > > +                      */
> > >                       struct rte_crypto_param_range key_size;
> > >                       /**< cipher key size range */
> > >                       struct rte_crypto_param_range iv_size;
> > >                       /**< Initialisation vector data size range */
> > > +                     uint32_t bsf;
> > > +                     /**< Block size flags */
> > >               } cipher;
> > >               /**< Symmetric Cipher transform capabilities */
> > >               struct {
> > > --
> > > 1.8.3.1
  

Patch

diff --git a/lib/librte_cryptodev/rte_crypto_sym.h b/lib/librte_cryptodev/rte_crypto_sym.h
index 9d572ec..9a1215d 100644
--- a/lib/librte_cryptodev/rte_crypto_sym.h
+++ b/lib/librte_cryptodev/rte_crypto_sym.h
@@ -265,6 +265,18 @@  struct rte_crypto_cipher_xform {
 		 * which can be in the range 7 to 13 inclusive.
 		 */
 	} iv;	/**< Initialisation vector parameters */
+
+	uint32_t block_size;
+	/**< When RTE_CRYPTODEV_FF_CIPHER_MULITPLE_BLOCKS is reported, this is
+	 * the block size of the algorithm, otherwise or when the value is 0,
+	 * use the default block size provided in the capability.
+	 * The value should be in the range defined by the bsf field in the
+	 * cipher capability.
+	 *
+	 * - For AES-XTS it is the size of data-unit, from IEEE Std 1619-2007.
+	 * For-each data-unit in the operation, the tweak(IV) value is
+	 * assigned consecutively starting from the operation assigned tweak.
+	 */
 };
 
 /** Symmetric Authentication / Hash Algorithms
diff --git a/lib/librte_cryptodev/rte_cryptodev.h b/lib/librte_cryptodev/rte_cryptodev.h
index ae34f33..60ba839 100644
--- a/lib/librte_cryptodev/rte_cryptodev.h
+++ b/lib/librte_cryptodev/rte_cryptodev.h
@@ -96,6 +96,19 @@  struct rte_crypto_param_range {
 };
 
 /**
+ * Crypto device supported block size flags for cipher algorithms
+ * Each flag represents single or range of supported block sizes
+ */
+#define RTE_CRYPTO_CIPHER_BSF_ALL 0x1
+/* All the sizes from the algorithm standard */
+#define RTE_CRYPTO_CIPHER_BSF_512_BYTES 0x2
+#define RTE_CRYPTO_CIPHER_BSF_520_BYTES 0x4
+#define RTE_CRYPTO_CIPHER_BSF_4048_BYTES 0x8
+#define RTE_CRYPTO_CIPHER_BSF_4096_BYTES 0x10
+#define RTE_CRYPTO_CIPHER_BSF_4160_BYTES 0x20
+#define RTE_CRYPTO_CIPHER_BSF_1M_BYTES 0x40
+
+/**
  * Symmetric Crypto Capability
  */
 struct rte_cryptodev_symmetric_capability {
@@ -122,11 +135,19 @@  struct rte_cryptodev_symmetric_capability {
 			enum rte_crypto_cipher_algorithm algo;
 			/**< cipher algorithm */
 			uint16_t block_size;
-			/**< algorithm block size */
+			/**<
+			 * algorithm block size
+			 * For algorithms support more than single block size,
+			 * this is the default block size supported by the
+			 * driver, all the supported sizes are reflected in the
+			 * bsf field.
+			 */
 			struct rte_crypto_param_range key_size;
 			/**< cipher key size range */
 			struct rte_crypto_param_range iv_size;
 			/**< Initialisation vector data size range */
+			uint32_t bsf;
+			/**< Block size flags */
 		} cipher;
 		/**< Symmetric Cipher transform capabilities */
 		struct {