Skip to content

Create a generic number ↔ name and let EVP use it#8878

Closed
levitte wants to merge 18 commits intoopenssl:masterfrom
levitte:evp-namemap
Closed

Create a generic number ↔ name and let EVP use it#8878
levitte wants to merge 18 commits intoopenssl:masterfrom
levitte:evp-namemap

Conversation

@levitte
Copy link
Member

@levitte levitte commented May 4, 2019

This creates a generic, per library context number ↔ name map, and has the EVP fetcher use it.

Checklist
  • documentation is added or updated

@levitte levitte added the branch: master Applies to master branch label May 4, 2019
@levitte levitte changed the title Evp namemap Create a generic number ↔ name and let EVP use it May 4, 2019
@levitte
Copy link
Member Author

levitte commented May 4, 2019

Arguably, this namemap could be used by the property code... I don't quite understand why crypto/property/property_string.c currently holds two databases, when they are really just string ↔ identity maps and those strings don't have any other inherent per se.

@paulidale
Copy link
Contributor

@levitte the reason that crypto/property/property_string.c holds two (name, value) databases is to distinguish between the names and the values. There are strict rules about what forms names can take and these are enforced. There are far laxer restrictions on values. Keeping them separate seemed expedient from the point of view of validity checking.

I'm not going to object to a merging of the two, so long as the semantics don't also change.

@paulidale
Copy link
Contributor

paulidale commented May 5, 2019

[edit: this whole comment is wrong]

There is a slight difference between the properties name ↔ value maps and this. The property maps are known to be indexed sequentially (from zero one) which makes a stack of names efficient, here the index doesn't have that property which makes a sparse array the better choice.

By switching the property implementation over, there will be a (small?) space cost but I don't think there will be a noticeable time cost. I believe the simplification to a single name ↔ value map across the library is a beneficial one that outweighs associated the costs.

@paulidale
Copy link
Contributor

Merging the two name ↔ value maps in the property code into a single map will allow properties like: "fips=foo, foo=bar" (where foo is not a property name) to be specified and parsed without error. I.e. the reservation of names without a period can be circumvented.

@levitte
Copy link
Member Author

levitte commented May 5, 2019

There is a slight difference between the properties name ↔ value maps and this. The property maps are known to be indexed sequentially (from zero) which makes a stack of names efficient, here the index doesn't have that property which makes a sparse array the better choice.

Uhmmmm, this namemap is indexed monotonically as well, but from one (zero indicates an "undefined" string). A string gets added by pushing it in the stack...

@levitte
Copy link
Member Author

levitte commented May 5, 2019

There's one bit that I find highly disturbing, and it's that this namemap is per library context... That would mean duplicating it unnecessarily if we're handling several library contexts within a unit. It's just a string to number cache, essentially, so there's no reason to make the numbers different per context.

I could force it to end up in the default library context, but that would mean that there must be one, and the FIPS module currently forbids that... I might have an idea or two on that, btw, but that's the matter of another PR.

@paulidale
Copy link
Contributor

I saw the use of sk_NAMEMAP_value and thought that it searched for some unknown reason.

Best to stick with the stack and it can directly replace the two property mappings.

@paulidale
Copy link
Contributor

Could we have this per context and default to the "default" context if none is directly set?

@paulidale
Copy link
Contributor

Properties index from 1 as well.

@levitte
Copy link
Member Author

levitte commented May 5, 2019

Could we have this per context and default to the "default" context if none is directly set?

We can. Also, this implementation only allows one namemap (per library context), and what you said about keeping property names and values separate makes me think that we need a mechanism to have more than one. This is perfectly viable, but needs an extension of the API.

@levitte
Copy link
Member Author

levitte commented May 5, 2019

I re-implemented it to make it possible to create free floating name maps.

@levitte
Copy link
Member Author

levitte commented May 5, 2019

Ooooh, this found me an interesting bug... we weren't doing things quite right when there is no pre-existing nid for a name...

@levitte levitte marked this pull request as ready for review May 5, 2019 07:05
@levitte
Copy link
Member Author

levitte commented May 5, 2019

This isn't in draft any more

levitte added 17 commits May 8, 2019 16:29
This avoids using the ASN1_OBJECT database, which is bloated for the
purpose of a simple number <-> name database.
We didn't deal very well with names that didn't have pre-defined NIDs,
as the NID zero travelled through the full process and resulted in an
inaccessible method.  By consequence, we need to refactor the method
construction callbacks to rely more on algorithm names.

We must, however, still store the legacy NID with the method, for the
sake of other code that depend on it (for example, CMS).
POD markup is only forbidden in the actual names, while permitted in
the description.
…uction

Now that the legacy NID isn't used as a main index for fetched
algorithms, the legacy NID was just transported around unnecessarily.
This is removed, and the legacy NID is simply set by EVP_{API}_fetch()
after the construction process is done.
@levitte
Copy link
Member Author

levitte commented May 12, 2019

Ping?

(btw, in a conversation yesterday, it was suggested that the strings could be bitstrings, i.e. binary data rather than just text... I don't mind the idea, but I also think that could be future development of this map functionality, it doesn't have to happen in this PR)

@levitte
Copy link
Member Author

levitte commented May 12, 2019

Doing the close+open thing to kick Appveyor

@levitte levitte closed this May 12, 2019
@levitte levitte reopened this May 12, 2019
@levitte
Copy link
Member Author

levitte commented May 12, 2019

Merged.

0211740 EVP_FETCH: remove the need to transport the legacy NID through construction
1f79ddf util/find-doc-nits: Fine tune detection of POD markup in NAME section
2e49c05 EVP_FETCH: deal with names without pre-defined NIDs
baff732 Make the generic EVP fetching mechanism use the namenum map
f2182a4 Create internal number<->name mapping API

@levitte levitte closed this May 12, 2019
levitte added a commit that referenced this pull request May 12, 2019
This can be used as a general name to identity map.

Reviewed-by: Paul Dale <[email protected]>
(Merged from #8878)
levitte added a commit that referenced this pull request May 12, 2019
This avoids using the ASN1_OBJECT database, which is bloated for the
purpose of a simple number <-> name database.

Reviewed-by: Paul Dale <[email protected]>
(Merged from #8878)
levitte added a commit that referenced this pull request May 12, 2019
We didn't deal very well with names that didn't have pre-defined NIDs,
as the NID zero travelled through the full process and resulted in an
inaccessible method.  By consequence, we need to refactor the method
construction callbacks to rely more on algorithm names.

We must, however, still store the legacy NID with the method, for the
sake of other code that depend on it (for example, CMS).

Reviewed-by: Paul Dale <[email protected]>
(Merged from #8878)
levitte added a commit that referenced this pull request May 12, 2019
POD markup is only forbidden in the actual names, while permitted in
the description.

Reviewed-by: Paul Dale <[email protected]>
(Merged from #8878)
levitte added a commit that referenced this pull request May 12, 2019
…uction

Now that the legacy NID isn't used as a main index for fetched
algorithms, the legacy NID was just transported around unnecessarily.
This is removed, and the legacy NID is simply set by EVP_{API}_fetch()
after the construction process is done.

Reviewed-by: Paul Dale <[email protected]>
(Merged from #8878)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

branch: master Applies to master branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants