Bug 186967 - [GCrypt] Zero-prefix (if necessary) output of RSA-based encryption and signing operations
Summary: [GCrypt] Zero-prefix (if necessary) output of RSA-based encryption and signin...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Zan Dobersek
URL:
Keywords: InRadar
: 176358 176759 177529 180095 181139 (view as bug list)
Depends on:
Blocks:
 
Reported: 2018-06-23 05:26 PDT by Zan Dobersek
Modified: 2018-06-25 23:29 PDT (History)
6 users (show)

See Also:


Attachments
Patch (18.79 KB, patch)
2018-06-23 05:56 PDT, Zan Dobersek
no flags Details | Formatted Diff | Diff
Patch (19.01 KB, patch)
2018-06-25 00:03 PDT, Zan Dobersek
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Zan Dobersek 2018-06-23 05:26:59 PDT
[GCrypt] Zero-prefix (if necessary) RSA-OAEP encryption, RSA-PSS signing output
Comment 1 Zan Dobersek 2018-06-23 05:56:02 PDT
Created attachment 343431 [details]
Patch
Comment 2 Zan Dobersek 2018-06-23 05:57:04 PDT
*** Bug 176759 has been marked as a duplicate of this bug. ***
Comment 3 Zan Dobersek 2018-06-23 05:57:12 PDT
*** Bug 180095 has been marked as a duplicate of this bug. ***
Comment 4 Zan Dobersek 2018-06-23 05:57:18 PDT
*** Bug 181139 has been marked as a duplicate of this bug. ***
Comment 5 Zan Dobersek 2018-06-23 05:57:26 PDT
*** Bug 176358 has been marked as a duplicate of this bug. ***
Comment 6 Michael Catanzaro 2018-06-23 07:25:15 PDT
*** Bug 177529 has been marked as a duplicate of this bug. ***
Comment 7 Michael Catanzaro 2018-06-23 07:39:37 PDT
Comment on attachment 343431 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=343431&action=review

Excellent

> Source/WebCore/ChangeLog:11
> +        length of the RSA key. The way we retrieve the MPI data means libgcrypt
> +        can ignore the high-bit zero values and leave us with a valid result
> +        that's shorter in length compared to the RSA key. For instance, if the

Wow!

> Source/WebCore/crypto/gcrypt/CryptoAlgorithmRSAES_PKCS1_v1_5GCrypt.cpp:98
> +    ASSERT(!(key.keySizeInBits() % 8));

I'd probably use ASSERT_WITH_SECURITY_IMPLICATION

> Source/WebCore/crypto/gcrypt/GCryptUtilities.h:183
> +static inline std::optional<Vector<uint8_t>> mpiZeroPrefixedData(gcry_mpi_t paramMPI, size_t targetLength)

Isn't it pretty long for an inline hint? How long does it have to get before you worry about cache locality?

> Source/WebCore/crypto/gcrypt/GCryptUtilities.h:191
> +    // Fill out the output buffer with zeros. Properly determine the zero prefix length,
> +    // and copy the MPI data into memory area following the prefix (if any).

These are good comments. It's a difficult art, finding the right balance between too much information and not enough. OK, just felt you deserved a compliment here.
Comment 8 Zan Dobersek 2018-06-24 23:45:42 PDT
Comment on attachment 343431 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=343431&action=review

>> Source/WebCore/crypto/gcrypt/CryptoAlgorithmRSAES_PKCS1_v1_5GCrypt.cpp:98
>> +    ASSERT(!(key.keySizeInBits() % 8));
> 
> I'd probably use ASSERT_WITH_SECURITY_IMPLICATION

OK.

>> Source/WebCore/crypto/gcrypt/GCryptUtilities.h:183
>> +static inline std::optional<Vector<uint8_t>> mpiZeroPrefixedData(gcry_mpi_t paramMPI, size_t targetLength)
> 
> Isn't it pretty long for an inline hint? How long does it have to get before you worry about cache locality?

I don't think this harms cache locality. `inline` specifier is primarily used to denote functions that are defined in headers and that should remain the same in definition between different source files. Nowadays it's completely up to the compiler whether it decides to inline the function or not. This I guess primarily depends on compilation options (optimization flags, debugging options, link-time optimizations). If the `inline` specifier is removed, the compiler already complains of the function being unused in whatever translation unit the header is included in.

What I can do is move all the definitions into a standalone GCryptUtilities.cpp source file.

>> Source/WebCore/crypto/gcrypt/GCryptUtilities.h:191
>> +    // and copy the MPI data into memory area following the prefix (if any).
> 
> These are good comments. It's a difficult art, finding the right balance between too much information and not enough. OK, just felt you deserved a compliment here.

Thanks.
Comment 9 Zan Dobersek 2018-06-25 00:03:17 PDT
Created attachment 343488 [details]
Patch
Comment 10 Zan Dobersek 2018-06-25 00:05:53 PDT
Comment on attachment 343488 [details]
Patch

Clearing flags on attachment: 343488

Committed r233138: <https://trac.webkit.org/changeset/233138>
Comment 11 Zan Dobersek 2018-06-25 00:05:57 PDT
All reviewed patches have been landed.  Closing bug.
Comment 12 Radar WebKit Bug Importer 2018-06-25 00:06:24 PDT
<rdar://problem/41416540>
Comment 13 Zan Dobersek 2018-06-25 23:29:39 PDT
(In reply to Zan Dobersek from comment #8) 
> What I can do is move all the definitions into a standalone
> GCryptUtilities.cpp source file.
> 

Bug #187033.