Add DSA support to OpenSsl and Cng assemblies - #11359
Conversation
| internal static extern SafeDsaHandle EvpPkeyGetDsa(SafeEvpPKeyHandle pkey); | ||
|
|
||
| [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EvpPkeySetDsa")] | ||
| [return: MarshalAs(UnmanagedType.Bool)] |
There was a problem hiding this comment.
I believe this attribute is required for fxcop CA1414... To encourage thinking about whether .U1 should be used if marshalling c++ bool. https://msdn.microsoft.com/en-us/library/ms182206.aspx
|
test Innerloop Windows_NT Release Build and Test please |
| /// continue to manage the lifetime of their reference. | ||
| /// </remarks> | ||
| /// <param name="handle">A pointer to an OpenSSL <c>EC_KEY*</c></param> | ||
| /// <exception cref="ArgumentException"><paramref name="handle" /> is invalid</exception> |
There was a problem hiding this comment.
This is public; why are you deleting it?
There was a problem hiding this comment.
Nevermind, I see that it was just moved.
|
@steveharter I'm about to merge #11366 could we hold this change until that's done? I expect this to have some conflicts, and I think it will be easier to fix in your side, since basically I would have to start all over again with my merge. |
a8d26a7 to
ba41851
Compare
|
To fix your CI failures, run: and then commit the changes on the packageIndex file and add them to your PR |
I was expecting a change in file src\System.Security.Cryptography.Algorithms\dir.props where you would rev up the version to 4.3.0.0. Can you add that? Refers to: src/System.Security.Cryptography.Algorithms/src/System.Security.Cryptography.Algorithms.csproj:13 in ba41851. [](commit_id = ba41851, deletion_comment = False) |
| <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
| <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" /> | ||
| <PropertyGroup> | ||
| <AssemblyVersion>4.3.0.0</AssemblyVersion> |
There was a problem hiding this comment.
Instead of adding a default assemblyversion here, could you remove this line from here (and from your src project as well) and update the dir.props bellow src/System.Security.Cryptography.Cng instead?
2972a20 to
95c46c1
Compare
| @@ -65,7 +65,7 @@ internal static int DsaKeySize(SafeDsaHandle dsa) | |||
| // there were some leading zero bytes truncated due to BIGNUM semantics. | |||
| // This minimizes the change the key size is wrong due to leading zero bits; there is only | |||
| // a 2^64 chance that the key has 64 leading zero bits and thus the keysize will be wrong. | |||
There was a problem hiding this comment.
I'm not sure what the second two lines of this comment are trying to say. Particularly why 64 zeroes are relevant.
There was a problem hiding this comment.
The value is returned from OpenSsl via bignum which will truncate the storage for leading zeros... So in theory without the rounding the odds of getting an incorrect key size would be 1:256.
Here's a reference point: https://www.openssl.org/docs/man1.0.1/crypto/BN_num_bits.html (see the NOTES section). In our case, we're getting the size in bytes of the P parameter. There is an OpenSsl method DSA_bits() which returns the size of P in bits, but that does not take in account an leading zeros from looking at that source
There was a problem hiding this comment.
@steveharter Yeah, I understand why we add 7, divide by 8, and multiply by 8. The comment says there's a 1:2^64 chance that there are 64 leading zeroes; but that's not particularly relevant.
p = a prime modulus, where 2L-1 < p < 2L for 512 <= L <= 1024 and L a multiple of 64
(FIPS 186-2, section 4)
Technically, BN_num_bits should always just be correct for p (or, rather L, since L is the size of p in bits); unless it's always off by 1 for indicating the significance of the "not negative" padding bit/byte. q appears to be equally rigid, but g, x and y are soft. Those relationships seem to also hold under FIPS 186-3.
That said, I'm not opposed to byte-alignment-normalization of the value for just-in-case (defense in depth for a future enhancement to the DSA spec); just that the comment seems to be a bit off.
There was a problem hiding this comment.
I'm assuming for each bit in a given p there is a 50% chance of it being zero. So for example if the first 8 bits are zero, there is one less byte required to store p in a bignum due to the semantics of bignum which doesn't pad leading bytes (thus the requested keysize would be off by 8 bits in this case). So 2^64 comes into place because we round 8 bytes (64 bits), thus the key size would be wrong (off by 64) if the first 64 bits are all zero.
There was a problem hiding this comment.
Because p has to be between 2L-1and 2L the high bit is guaranteed set. And since it's prime, and not the number 2, the low bit is also guaranteed set.
This formula is rounding up to the next byte (in bits), not to a 64-bit boundary:
f(7) => (7 + 7) / 8 * 8 => 14 / 8 * 8 => 1 * 8 => 8.
f(8) => (8 + 7) / 8 * 8 => 15 / 8 * 8 => 1 * 8 => 8.
f(9) => (9 + 7) / 8 * 8 => 16 / 8 * 8 => 2 * 8 => 16.
There was a problem hiding this comment.
That makes sense as I said I was assuming there was a 50% which if true then would have no guarantees about the strength of the key based on the key size passed in. I did remove part of that comment with last sync, but will tweak it again to remove reference to leading zeros.
There was a problem hiding this comment.
Also, that formula is in bytes, not bits. So it will round up to nearest 8 byte boundary.
Now that System.Collections.NonGeneric is published with serialization support, we can enable serialization tests for System.Collection.Specialized.
…otnet#11363) * Add tests to cover the XmlSchema and XmlSerializerFactory scenarios. * Update the code based on Shin's feedback. * change the code based on Shin's feedback.
* Add 2 missing members to Exception
Includes some changes to Algorithms as well.