예제 #1
1
int
idxread (unit *ftnunit)
{
   register int    i;
   register char  *keyval, *field;
   int             newkeyid = 0, mode = ftnunit->f77idxlist.cimatch;

   keys = ftnunit->ukeys;
   ftnunit->f77recend = i = ftnunit->url;
   if (ftnunit->url > ftnunit->f77fio_size)
      check_buflen (ftnunit, ftnunit->url);
   while (i-- > 0)
      ftnunit->f77fio_buf[i] = '\0';
   if (ftnunit->f77idxlist.cikeyid >= 0 && ftnunit->ukeyid != ftnunit->f77idxlist.cikeyid) {
      ftnunit->ukeyid = ftnunit->f77idxlist.cikeyid;
      newkeyid = 1;
   }
/* 8/23/89 fix bug 4847 */
   else if (ftnunit->ukeyid < 0) {
      ftnunit->ukeyid = ftnunit->f77idxlist.cikeyid >= 0 ? ftnunit->f77idxlist.cikeyid : 0;
      newkeyid = 1;
   }
   if (mode) {
      field = ftnunit->f77fio_buf + KEYOFF (ftnunit->ukeyid);
      if (KEYTYPE (ftnunit->ukeyid) != ftnunit->f77idxlist.cikeytype)
	 err (ftnunit->f77errlist.cierr, 154, "indexed read");
      if (KEYTYPE (ftnunit->ukeyid) == CHARTYPE) {
	 keyval = ftnunit->f77idxlist.cikeyval.cicharval;
/* fix bug 4779 */
	 if ((i = ftnunit->f77idxlist.cikeyvallen) > KEYLEN (ftnunit->ukeyid))
	    err (ftnunit->f77errlist.cierr, 155, "indexed read");
	 /* For Fortran, there's no such thing as null terminators for
	 the string values, so use the string len value only 
	 while (*keyval && i-- > 0)
	    *field++ = *keyval++;
	 while (i-- > 0)
	    *field++ = ' ';
	*/
	 while (i-- > 0)
	    *field++ = *keyval++;
      } else
	 stlong (ftnunit->f77idxlist.cikeyval.ciintval, field);
   } else
      /* If the last read operation was locked try readign the same record
      again
      mode = (newkeyid ? ISFIRST : ISNEXT);
      */
      mode = (newkeyid ? ISFIRST : ftnunit->uerror == F_ERLOCKED ? ISCURR : ISNEXT);
      ftnunit->uerror = 0;	/* clear error for new operation */
   if (newkeyid) {
      dokey (ftnunit->ukeyid, ONEKEY);
      if (isstart (ftnunit->isfd, &onekey, ftnunit->url, ftnunit->f77fio_buf, mode)
	  < SUCCESS)
	 ierr (ftnunit->f77errlist.cierr, iserrno, "indexed read");
   }
   if (isread (ftnunit->isfd, ftnunit->f77fio_buf, mode) < SUCCESS)
      if (iserrno == EENDFILE) {
	 ftnunit->uend = 1;
	 err (ftnunit->f77errlist.ciend, EOF, "indexed read");
      } else
	 ierr (ftnunit->f77errlist.cierr, iserrno, "indexed read");
   /* When the read is successful, make sure the EOF flag is not set */
   ftnunit->uend = 0;
   return SUCCESS;
}
예제 #2
0
static int ecx_priv_encode(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pkey)
{
    const ECX_KEY *ecxkey = pkey->pkey.ecx;
    ASN1_OCTET_STRING oct;
    unsigned char *penc = NULL;
    int penclen;

    if (ecxkey == NULL || ecxkey->privkey == NULL) {
        ECerr(EC_F_ECX_PRIV_ENCODE, EC_R_INVALID_PRIVATE_KEY);
        return 0;
    }

    oct.data = ecxkey->privkey;
    oct.length = KEYLEN(pkey);
    oct.flags = 0;

    penclen = i2d_ASN1_OCTET_STRING(&oct, &penc);
    if (penclen < 0) {
        ECerr(EC_F_ECX_PRIV_ENCODE, ERR_R_MALLOC_FAILURE);
        return 0;
    }

    if (!PKCS8_pkey_set0(p8, OBJ_nid2obj(pkey->ameth->pkey_id), 0,
                         V_ASN1_UNDEF, NULL, penc, penclen)) {
        OPENSSL_clear_free(penc, penclen);
        ECerr(EC_F_ECX_PRIV_ENCODE, ERR_R_MALLOC_FAILURE);
        return 0;
    }

    return 1;
}
예제 #3
0
파일: hash.c 프로젝트: Lanozavr/pvs
static void print_symbol_info (FILE *fp, HASHTAB *symtab, int i)
{
  fprintf (fp, "%3d   %p (%3d)  %s\n",
	   i,
	   KEYINFO (symtab, i),
	   KEYLEN  (symtab, i),
	   KEYSTR  (symtab, i));
}
예제 #4
0
static int ecx_pub_cmp(const EVP_PKEY *a, const EVP_PKEY *b)
{
    const ECX_KEY *akey = a->pkey.ecx;
    const ECX_KEY *bkey = b->pkey.ecx;

    if (akey == NULL || bkey == NULL)
        return -2;

    return CRYPTO_memcmp(akey->pubkey, bkey->pubkey, KEYLEN(a)) == 0;
}
예제 #5
0
static int ecx_ctrl(EVP_PKEY *pkey, int op, long arg1, void *arg2)
{
    switch (op) {

    case ASN1_PKEY_CTRL_SET1_TLS_ENCPT:
        return ecx_key_op(pkey, pkey->ameth->pkey_id, NULL, arg2, arg1,
                          KEY_OP_PUBLIC);

    case ASN1_PKEY_CTRL_GET1_TLS_ENCPT:
        if (pkey->pkey.ecx != NULL) {
            unsigned char **ppt = arg2;

            *ppt = OPENSSL_memdup(pkey->pkey.ecx->pubkey, KEYLEN(pkey));
            if (*ppt != NULL)
                return KEYLEN(pkey);
        }
        return 0;

    default:
        return -2;

    }
}
예제 #6
0
static int ecx_key_print(BIO *bp, const EVP_PKEY *pkey, int indent,
                         ASN1_PCTX *ctx, ecx_key_op_t op)
{
    const ECX_KEY *ecxkey = pkey->pkey.ecx;
    const char *nm = OBJ_nid2ln(pkey->ameth->pkey_id);

    if (op == KEY_OP_PRIVATE) {
        if (ecxkey == NULL || ecxkey->privkey == NULL) {
            if (BIO_printf(bp, "%*s<INVALID PRIVATE KEY>\n", indent, "") <= 0)
                return 0;
            return 1;
        }
        if (BIO_printf(bp, "%*s%s Private-Key:\n", indent, "", nm) <= 0)
            return 0;
        if (BIO_printf(bp, "%*spriv:\n", indent, "") <= 0)
            return 0;
        if (ASN1_buf_print(bp, ecxkey->privkey, KEYLEN(pkey),
                           indent + 4) == 0)
            return 0;
    } else {
        if (ecxkey == NULL) {
            if (BIO_printf(bp, "%*s<INVALID PUBLIC KEY>\n", indent, "") <= 0)
                return 0;
            return 1;
        }
        if (BIO_printf(bp, "%*s%s Public-Key:\n", indent, "", nm) <= 0)
            return 0;
    }
    if (BIO_printf(bp, "%*spub:\n", indent, "") <= 0)
        return 0;

    if (ASN1_buf_print(bp, ecxkey->pubkey, KEYLEN(pkey),
                       indent + 4) == 0)
        return 0;
    return 1;
}
예제 #7
0
static int ecx_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey)
{
    const ECX_KEY *ecxkey = pkey->pkey.ecx;
    unsigned char *penc;

    if (ecxkey == NULL) {
        ECerr(EC_F_ECX_PUB_ENCODE, EC_R_INVALID_KEY);
        return 0;
    }

    penc = OPENSSL_memdup(ecxkey->pubkey, KEYLEN(pkey));
    if (penc == NULL) {
        ECerr(EC_F_ECX_PUB_ENCODE, ERR_R_MALLOC_FAILURE);
        return 0;
    }

    if (!X509_PUBKEY_set0_param(pk, OBJ_nid2obj(pkey->ameth->pkey_id),
                                V_ASN1_UNDEF, NULL, penc, KEYLEN(pkey))) {
        OPENSSL_free(penc);
        ECerr(EC_F_ECX_PUB_ENCODE, ERR_R_MALLOC_FAILURE);
        return 0;
    }
    return 1;
}
예제 #8
0
static void ecx_free(EVP_PKEY *pkey)
{
    if (pkey->pkey.ecx != NULL)
        OPENSSL_secure_clear_free(pkey->pkey.ecx->privkey, KEYLEN(pkey));
    OPENSSL_free(pkey->pkey.ecx);
}
예제 #9
0
static int ecx_size(const EVP_PKEY *pkey)
{
    return KEYLEN(pkey);
}
예제 #10
-2
int
dokey(int keyid, int mode)
{
   switch (mode) {
   case NOMATCH:
      return KEYOFF (keyid) != onekey.k_start ||
	 KEYLEN (keyid) != onekey.k_leng ||
	 KEYTYPE (keyid) != onekey.k_type;

   case ONEKEY:
      onekey.k_start = KEYOFF (keyid);
      onekey.k_leng = (short) (KEYLEN (keyid));
      onekey.k_type = KEYTYPE (keyid);
      break;

   case UNITKEY:
      KEYOFF (keyid) = onekey.k_start;
      KEYEND (keyid) = (short) (onekey.k_start + onekey.k_leng - 1);
      KEYTYPE (keyid) = onekey.k_type;
      break;
   }
   return 0; /* return value is ignored */
}