/* Final touch. For each pixel, a donut of 8 neighbors is considered.
 * If the final touch table says 0 on the donut, then the pixel is cleaned.
 */
static void force_8_connectivity(unsigned char **pixels, int w, int h)
{
    int x, y;

    for (y = 0; y < h; y++)
    {
        unsigned char **prow = pixels + y;
        unsigned char *row = *prow;

        for (x = 0; x < w; x++) if (row[x])
        {
            row[x] = ( get_table_value(final_touch_table, prow, x) ? 1 : 0 );
        }
    }
}
/* Mark phase. For each pixel, a donut of 8 neighbors is considered.
 * If the mark table says 0 on the donut, then the pixel is a candidate for sweeping.
 */
static void mark(unsigned char **pixels, unsigned char **candidates, int w, int h)
{
    int x, y;

    for (y = 0; y < h; y++)
    {
        unsigned char **prow = pixels + y;
        unsigned char *row = *prow;
        unsigned char *candidates_row = candidates[y];

        for (x = 0; x < w; x++) if (row[x])
        {
            candidates_row[x] = get_table_value(mark_table, prow, x);
        }
    }
}
Exemple #3
0
int setEEorCA(
    struct object_field *table)
{
    char *val;
    int val_type;

    if (get_table_value("type", table, &val, &val_type) < 0)
    {
        warn(MISSING_CERT_TYPE, NULL);
        return (MISSING_CERT_TYPE);
    }
    if (strncasecmp(val, "EE", strlen("EE")) == 0)
        eecert = 1;

    return SUCCESS;
}
Exemple #4
0
void setSelfSigned(
    struct object_field *table)
{
    char *val;
    int val_type;

    // if self signed is true, set self signed bit and type to CA
    if (get_table_value("selfsigned", table, &val, &val_type) >= 0)
    {
        if ((val != NULL) && (strncasecmp(val, "true", strlen("true")) == 0))
        {
            selfSigned = 1;
            eecert = 0;
        }
    }
}
/* Sweep phase. If a pixel is a candidate for deletion
 * and its donut of neighbors scores 0 in the sweep table,
 * then the pixel is set to white.
 * Note that a cleaned pixel may affect subsequent sweeping.
 *
 * Returns 1 if the image has changed, 0 otherwise.
 */
static int sweep(unsigned char **pixels, unsigned char **candidates, int w, int h)
{
    int x, y;
    int result = 0;

    for (y = 0; y < h; y++)
    {
        unsigned char **prow = pixels + y;
        unsigned char *row = *prow;
        unsigned char *candidates_row = candidates[y];

        for (x = 0; x < w; x++)
        {
            if (row[x] && !candidates_row[x]
             && !get_table_value(sweep_table, prow, x))
            {
                row[x] = 0;
                result = 1;
            }
        }
    }
    return result;
}
Exemple #6
0
/*
 * Create an EE or CA certificate using the
 * table to set the fields. The table is build
 * using command line arguments
 */
int create_cert(
    struct object_field *table)
{

    int ret = 0;
    int i;
    struct Certificate cert;
    Certificate(&cert, (ushort) 0);     // constructor for the cert struct
    char *keyfile = NULL,
        *val;
    int val_type;

    eecert = 0;

    // is it a ca or ee cert
    if ((ret = setEEorCA(table)) != SUCCESS)
        return ret;

    setSelfSigned(table);

    // Read the certificate template into the certificate
    if (!templateFile)
    {
        if (eecert)
            templateFile = CONFIG_TEMPLATE_EE_CERT_get();
        else
            templateFile = CONFIG_TEMPLATE_CA_CERT_get();
    }
    ret = get_casn_file(&cert.self, (char *)templateFile, 0);
    if (ret < 0)
    {
        warn(FILE_OPEN_ERR, (char *)templateFile);
        return (FILE_OPEN_ERR);
    }

    // clear out fields in the template (only keeping a few);
    clear_cert(&cert);

    // fill in the default fields
    write_default_fields(&cert);

    // Populate the certificate fields with data from the
    // table. Note the table is populated from input arguments
    // If there is no function to call and the argument is optional then
    // it is ok otherwise it is an error.
    for (i = 0; table[i].name != NULL; i++)
    {
        if (table[i].func != NULL)
        {
            if (table[i].value != NULL)
            {
                if (table[i].func(&cert.self, table[i].value) < 0)
                {
                    fprintf(stderr, "Error writing %s into field %s\n",
                            table[i].value, table[i].name);
                }
            }
            else
            {
                if (table[i].required)
                    fprintf(stderr, "Missing value for %s\n", table[i].name);
            }
        }
    }

    // if signature value is set in the table, write that value as the
    // signature,
    // otherwise sign it
    if (get_table_value("signatureValue", table, &val, &val_type) != 0)
    {
        fprintf(stdout, "Error writing signature");
        return (-1);
    }

    if (val != NULL)            // input signature
    {
        if (write_sig(&cert, val) != SUCCESS)
        {
            fprintf(stdout, "Error writing signature");
            return (-1);
        }
    }
    else
    {                           // have to sign it, get key from subject
                                // keyfile if selfsigned else parents
        if (selfSigned)
            get_table_value("subjkeyfile", table, &keyfile, &val_type);
        else
            get_table_value("parentkeyfile", table, &keyfile, &val_type);

        if (keyfile == NULL || (sign_cert(&cert, keyfile) != SUCCESS))
            return -1;
    }

    // write out the certificate using the ouput filename
    if (get_table_value("outputfilename", table, &val, &val_type) < 0)
    {
        warn(FILE_WRITE_ERR, "outputfilename missing");
        return (FILE_WRITE_ERR);
    }
    if (put_casn_file(&cert.self, val, 0) < 0)
    {
        warn(FILE_WRITE_ERR, val);
        return (FILE_WRITE_ERR);
    }
    else
        warn(SUCCESS, val);

    return (SUCCESS);

}