"makekey" for Linux

By Steggy
BCS Technology Limited
Email: [email protected]
Web Site: http://www.bcstechnology.net

The need for makekey has to do with interfacing to a Throughbred Dictionary-IV app originally written to run on SCO OSR5. I now have complete portability for any other use of the app.

Apparently there was once a Linux makekey, but it was "deprecated" in favor of "crypt(3)".

Apparently there was also (and may still be somewhere) a command line "crypt" that I could have "front-ended" for my needs, but it doesn't exist on my system. As there really isn't much to this, I just went ahead and wrote what I needed.

Compile source with gcc -lcrypt -m32 -o makekey makekey.c. The -m32 option is required on a 64 bit system. Operation is the same as makekey found on SCO, BSD, AIX, etc.



makekey: Generate Encrypted Password

Copyright (C)1994-2009 by BCS Technology Limited. All rights reserved.

Permission is granted to use, copy, modify and/or distribute this soft- ware, provided proper attribution and credit is given and all copyright notices remain intact. This software is *NOT* in the public domain and has *NOT* been GPLed.

DISCLAIMER: BCS Technology Limited does not warrant that this software
is suitable for any particular purpose, or that it will
even work as intended. No technical support of any kind
will be offered. We take no responsibility for anything
unpleasant that might happen to your system, your business
or your financial well-being due to the use of this soft-
ware. In other words, USE AT YOUR OWN RISK.


/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *                                                                         * *
* *                   makekey: Generate Encrypted Password                  * *
* *                                                                         * *
* * Copyright (C)1994-2009 by BCS Technology Limited.  All rights reserved. * *
* *                                                                         * *
* * Permission is granted to use, copy, modify and/or distribute this soft- * *
* * ware, provided proper attribution and credit is given and all copyright * *
* * notices remain intact.  This software is *NOT* in the public domain and * *
* * has *NOT* been GPLed.                                                   * *
* *                                                                         * *
* * DISCLAIMER:  BCS Technology Limited does not warrant that this software * *
* *              is suitable for any particular purpose,  or that  it  will * *
* *              even work as intended.  No technical support of  any  kind * *
* *              will be offered.  We take no responsibility  for  anything * *
* *              unpleasant that might happen to your system, your business * *
* *              or your financial well-being due to the use of this  soft- * *
* *              ware.  In other words, USE AT YOUR OWN RISK.               * *
* *                                                                         * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*                                                                             *
* makekey reads from STDIN & writes to STDOUT.  Input should consist of an 8  *
* character password string followed by a 2 character salt.  The salt charac- *
* ters should be taken from the letters a-z & A-Z, numerals, . & /.  The salt *
* is returned at the beginning of the encrypted output string.  Results are   *
* undefined if the input string is not 10 characters in total length.  Excess *
* input will be silently discarded.                                           *
*                                                                             *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

// To compile on most Linux distros:

//	gcc -o makekey -m32 -lcrypt makekey.c

/*===========================================================================*/

/* global declarations */

#define	INPBUFSIZ	10			// input buffer size
#define	KEYSIZ		8			// input key size
#define	SALTSIZ		2			// input salt size

char	NUL=' ';				// null string terminator

void	collect(char *);			// collect input

/*===========================================================================*/

/* makekey: generate encrypted password */

int main(void) {

    char	*ec;				// encrypted string pointer
    char	inpbuf[INPBUFSIZ+1];		// input buffer
    char	key[KEYSIZ+1];			// key
    char	salt[SALTSIZ+1];		// salt
    int		eclen;				// encrypted string length

    collect(inpbuf);				// collect input
    strncpy(key,inpbuf,KEYSIZ);			// extract key
    strncpy(salt,inpbuf+KEYSIZ,SALTSIZ);	// extract salt
    key[KEYSIZ]=NUL;				// terminate key
    salt[SALTSIZ]=NUL;				// terminate salt
    eclen=(strlen(ec=crypt(key,salt)));		// encrypt
    if (write(STDOUT_FILENO,ec,eclen)!=eclen)
	perror("stdout");			// output <> input
    exit(0);					// done
}
/*===========================================================================*/

/* collect input string, at most INPBUFSIZ chars */

void collect(char *buf) {

    int		c,ct=0;

    while ((c=getchar()) != EOF) {
	if (ct<INPBUFSIZ) {
	    *(buf++)=c;
	    ct++;
	}
    }
    *(buf)=NUL;					// terminate input string
}
/*===========================================================================*/

/* copyright declaration for `what' command */

    const char *what[]={
	"@(#)makekey: BCS Technology Limited Password Encrypter",
	"@(#)",
	"@(#)Copyright (C)1994-2009 by BCS Technology Limited.  All rights",
	"@(#)reserved.  Permission granted to  use,  copy,  modify  and/or",
	"@(#)distribute this software,  providing  proper  attribution  is",
	"@(#)given and copyright notices remain intact.   This software is",
	"@(#)*NOT* in the public domain and has *NOT* been GPLed.",
	"@(#)",
	"@(#)BCS Technology Limited DOES NOT accept any responsibility for",
	"@(#)anything bad that might occur as a consequence  of  using  or",
	"@(#)modifying this software.  USE AT YOUR OWN RISK."
    };
/*===========================================================================*/



Got something to add? Send me email.





(OLDER) <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

-> -> 'makekey' source code for Linux




Increase ad revenue 50-250% with Ezoic


More Articles by © Steggy



Kerio Samepage


Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us





We are stuck with technology when what we really want is just stuff that works. (Douglas Adams)

We made the buttons on the screen look so good you'll want to lick them. (Steve Jobs)








This post tagged: