[Swan-dev] static things in headers
Andrew Cagney
andrew.cagney at gmail.com
Thu Sep 7 15:25:41 UTC 2017
On 7 September 2017 at 04:20, Sahana Prasad <sahana.prasad07 at gmail.com>
wrote:
>
>
> On Wed, Sep 6, 2017 at 5:38 PM, D. Hugh Redelmeier <hugh at mimosa.com>
> wrote:
>
>> Perhaps I'm old fashioned but we have avoided putting static things in
>> headers.
>>
>> - they notionally take resources in every compilation unit that includes
>> the header. (But smart compilers can eliminate unused instances.)
>>
>> - .h files are about sharing and static things are not shared
>>
>> Exception: inline functions. An inline function is useful as a cleaner
>> replacement for macros. If I remember correctly, making an inline
>> function static makes the semantics simpler allowing a compiler to do
>> a better job.
>>
>> Currently the only exceptions I see are:
>>
>> linux/include/des/podd.h:59:static const unsigned char odd_parity[256] =
>> {
>> linux/include/des/sk.h:59:static const DES_LONG des_skb[8][64] = {
>> osxApp/MainMenuController.h:20:static AuthorizationRef gAuth;
>>
>> include/ietf_constants.h:1696:static const unsigned char
>> sha1_rsa_oid_blob[ASN1_SHA1_RSA_OID_SIZE] =
>> {0x30,0x0d,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x01
>> ,0x05,0x05,0x00};
>> include/ietf_constants.h:1698:static const uint8_t
>> len_sha1_rsa_oid_blob[ASN1_LEN_ALGO_IDENTIFIER] =
>> {ASN1_SHA1_RSA_OID_SIZE};
>>
>>
>> The first three are in imported code and should not be changed. The second
>> two, in my opinion, ought to be eliminated (definitions moved).
>>
>> I will change this. Thank you for the comments.
> This was implemented in a hard coded way for one value. But , in future
> there are many such blobs of varying lengths that would be used. So, this
> hardcoding shall be removed.
>
Does NSS know the value? We already do this:
programs/pluto/ike_alg_nss_ecp.c: SECOidData *pk11_data =
SECOID_FindOIDByTag(group->nss_oid);
lib/libswan/ike_alg_dh.c: .nss_oid = SEC_OID_SECG_EC_SECP256R1,
lib/libswan/ike_alg_dh.c: .nss_oid = SEC_OID_SECG_EC_SECP384R1,
lib/libswan/ike_alg_dh.c: .nss_oid = SEC_OID_SECG_EC_SECP521R1,
else, I'd stick with something simple in the header:
#define SHA1_RSA_OID {0x30,0x0d,0x06,0x09,0x2a,0x86
,0x48,0x86,0xf7,0x0d,0x01,0x01,0x05,0x05,0x00}
>
>
>> The objects defined in last two are only actually used one place so
>> there is probably no serious consequence to the current code.
>>
>> _______________________________________________
>> Swan-dev mailing list
>> Swan-dev at lists.libreswan.org
>> https://lists.libreswan.org/mailman/listinfo/swan-dev
>>
>
>
> _______________________________________________
> Swan-dev mailing list
> Swan-dev at lists.libreswan.org
> https://lists.libreswan.org/mailman/listinfo/swan-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.libreswan.org/pipermail/swan-dev/attachments/20170907/baece855/attachment.html>
More information about the Swan-dev
mailing list