Beispiel #1
0
    def get_source_files(self):
        # Ensure library has been downloaded (sdist might have been skipped)
        download_library(self)

        return [
            absolute(os.path.join(root, filename))
            for root, _, filenames in os.walk(absolute("libsecp256k1"))
            for filename in filenames
        ]
Beispiel #2
0
    def get_source_files(self):
        # Ensure library has been downloaded (sdist might have been skipped)
        download_library(self)

        return [
            absolute(os.path.join(root, filename))
            for root, _, filenames in os.walk(absolute("libsecp256k1"))
            for filename in filenames
        ]
Beispiel #3
0
def _mk_ffi(sources, name="_libsecp256k1", bundled=True, **kwargs):
    ffi = FFI()
    code = []
    if 'INCLUDE_DIR' in os.environ:
        kwargs['include_dirs'] = [absolute(os.environ['INCLUDE_DIR'])]
    if 'LIB_DIR' in os.environ:
        kwargs['library_dirs'] = [absolute(os.environ['LIB_DIR'])]
    for source in sources:
        with open(source.h, 'rt') as h:
            ffi.cdef(h.read())
        code.append(source.include)
    if bundled:
        code.append("#define PY_USE_BUNDLED")
    ffi.set_source(name, "\n".join(code), **kwargs)
    return ffi
Beispiel #4
0
def _mk_ffi(sources, name="_libsecp256k1", bundled=True, **kwargs):
    ffi = FFI()
    code = []
    if "INCLUDE_DIR" in os.environ:
        kwargs["include_dirs"] = [absolute(os.environ["INCLUDE_DIR"])]
    if "LIB_DIR" in os.environ:
        kwargs["library_dirs"] = [absolute(os.environ["LIB_DIR"])]
    for source in sources:
        with open(source.h, "rt") as h:
            ffi.cdef(h.read())
        code.append(source.include)
    if bundled:
        code.append("#define PY_USE_BUNDLED")
    ffi.set_source(name, "\n".join(code), **kwargs)
    return ffi
Beispiel #5
0
def download_library(command):
    if command.dry_run:
        return
    libdir = absolute("libsecp256k1")
    if os.path.exists(os.path.join(libdir, "autogen.sh")):
        # Library already downloaded
        return
    if not os.path.exists(libdir):
        command.announce("downloading libsecp256k1 source code", level=log.INFO)
        try:
            r = urlopen(LIB_TARBALL_URL)
            if r.getcode() == 200:
                content = BytesIO(r.read())
                content.seek(0)
                with tarfile.open(fileobj=content) as tf:
                    dirname = tf.getnames()[0].partition('/')[0]
                    tf.extractall()
                shutil.move(dirname, libdir)
            else:
                raise SystemExit(
                    "Unable to download secp256k1 library: HTTP-Status: %d",
                    r.getcode()
                )
        except URLError as ex:
            raise SystemExit("Unable to download secp256k1 library: %s",
                             ex.message)
Beispiel #6
0
def download_library(command):
    if command.dry_run:
        return
    libdir = absolute('libsecp256k1')
    if os.path.exists(os.path.join(libdir, 'autogen.sh')):
        # Library already downloaded
        return
    if not os.path.exists(libdir):
        command.announce('downloading libsecp256k1 source code',
                         level=log.INFO)
        try:
            import requests

            r = requests.get(LIB_TARBALL_URL, stream=True)
            status_code = r.status_code
            if status_code == 200:
                content = BytesIO(r.raw.read())
                content.seek(0)
                with tarfile.open(fileobj=content) as tf:
                    dirname = tf.getnames()[0].partition('/')[0]
                    tf.extractall()
                shutil.move(dirname, libdir)
            else:
                raise SystemExit(
                    'Unable to download secp256k1 library: HTTP-Status: %d',
                    status_code)
        except requests.exceptions.RequestException as e:
            raise SystemExit('Unable to download secp256k1 library: %s',
                             str(e))
Beispiel #7
0
def download_library(command):
    if command.dry_run:
        return
    libdir = absolute("libsecp256k1")
    if os.path.exists(os.path.join(libdir, "autogen.sh")):
        # Library already downloaded
        return
    if not os.path.exists(libdir):
        command.announce("downloading libsecp256k1 source code", level=log.INFO)
        try:
            r = urlopen(LIB_TARBALL_URL)
            if r.getcode() == 200:
                content = BytesIO(r.read())
                content.seek(0)
                with tarfile.open(fileobj=content) as tf:
                    dirname = tf.getnames()[0].partition('/')[0]
                    tf.extractall()
                shutil.move(dirname, libdir)
            else:
                raise SystemExit(
                    "Unable to download secp256k1 library: HTTP-Status: %d",
                    r.getcode()
                )
        except URLError as ex:
            raise SystemExit("Unable to download secp256k1 library: %s",
                             ex.message)
    def run(self):
        build_temp = os.path.abspath(self.build_temp)

        try:
            os.makedirs(build_temp)
        except OSError as e:
            if e.errno != errno.EEXIST:
                raise

        if not os.path.exists(absolute('libsecp256k1/configure')):
            # configure script hasn't been generated yet
            autogen = absolute('libsecp256k1/autogen.sh')
            os.chmod(absolute(autogen), 0o755)
            subprocess.check_call([autogen], cwd=absolute('libsecp256k1'))

        for filename in [
                'libsecp256k1/configure',
                'libsecp256k1/build-aux/compile',
                'libsecp256k1/build-aux/config.guess',
                'libsecp256k1/build-aux/config.sub',
                'libsecp256k1/build-aux/depcomp',
                'libsecp256k1/build-aux/install-sh',
                'libsecp256k1/build-aux/missing',
                'libsecp256k1/build-aux/test-driver',
        ]:
            try:
                os.chmod(absolute(filename), 0o755)
            except OSError as e:
                # some of these files might not exist depending on autoconf version
                if e.errno != errno.ENOENT:
                    # If the error isn't 'No such file or directory' something
                    # else is wrong and we want to know about it
                    raise

        cmd = [
            absolute('libsecp256k1/configure'),
            '--disable-shared',
            '--enable-static',
            '--disable-dependency-tracking',
            '--with-pic',
            '--enable-module-recovery',
            '--disable-jni',
            '--prefix',
            os.path.abspath(self.build_clib),
            '--enable-experimental',
            '--enable-module-ecdh',
            '--enable-benchmark=no',
            #  '--enable-endomorphism',
        ]

        log.debug('Running configure: {}'.format(' '.join(cmd)))
        subprocess.check_call(cmd, cwd=build_temp)

        subprocess.check_call([MAKE], cwd=build_temp)
        subprocess.check_call([MAKE, 'install'], cwd=build_temp)

        self.build_flags['include_dirs'].extend(
            build_flags('libsecp256k1', 'I', build_temp))
        self.build_flags['library_dirs'].extend(
            build_flags('libsecp256k1', 'L', build_temp))
Beispiel #9
0
    def run(self):
        if has_system_lib():
            log.info("Using system library")
            return

        build_temp = os.path.abspath(self.build_temp)

        try:
            os.makedirs(build_temp)
        except OSError as e:
            if e.errno != errno.EEXIST:
                raise

        if not os.path.exists(absolute("libsecp256k1/configure")):
            # configure script hasn't been generated yet
            autogen = absolute("libsecp256k1/autogen.sh")
            os.chmod(absolute(autogen), 0o755)
            subprocess.check_call(
                [autogen],
                cwd=absolute("libsecp256k1"),
            )

        for filename in [
            "libsecp256k1/configure",
            "libsecp256k1/build-aux/compile",
            "libsecp256k1/build-aux/config.guess",
            "libsecp256k1/build-aux/config.sub",
            "libsecp256k1/build-aux/depcomp",
            "libsecp256k1/build-aux/install-sh",
            "libsecp256k1/build-aux/missing",
            "libsecp256k1/build-aux/test-driver",
        ]:
            try:
                os.chmod(absolute(filename), 0o755)
            except OSError as e:
                # some of these files might not exist depending on autoconf version
                if e.errno != errno.ENOENT:
                    # If the error isn't "No such file or directory" something
                    # else is wrong and we want to know about it
                    raise

        cmd = [
            absolute("libsecp256k1/configure"),
            "--disable-shared",
            "--enable-static",
            "--disable-dependency-tracking",
            "--with-pic",
            "--enable-module-recovery",
            "--prefix",
            os.path.abspath(self.build_clib),
        ]
        if os.environ.get('SECP_BUNDLED_WITH_BIGNUM'):
            log.info("Building with bignum support (requires libgmp)")
            cmd.extend(["--with-bignum=gmp"])
        else:
            cmd.extend(["--without-bignum"])

        if os.environ.get('SECP_BUNDLED_EXPERIMENTAL'):
            log.info("Building experimental")
            cmd.extend([
                "--enable-experimental",
                "--enable-module-ecdh",
                "--enable-module-schnorr",
            ])

        log.debug("Running configure: {}".format(" ".join(cmd)))
        subprocess.check_call(
            cmd,
            cwd=build_temp,
        )

        subprocess.check_call(["make"], cwd=build_temp)
        subprocess.check_call(["make", "install"], cwd=build_temp)

        self.build_flags['include_dirs'].extend(build_flags('libsecp256k1', 'I', build_temp))
        self.build_flags['library_dirs'].extend(build_flags('libsecp256k1', 'L', build_temp))
        if not has_system_lib():
            self.build_flags['define'].append(('CFFI_ENABLE_RECOVERY', None))
        else:
            pass
Beispiel #10
0
    def run(self):
        if has_system_lib():
            log.info('Using system library')
            return

        build_temp = os.path.abspath(self.build_temp)

        try:
            os.makedirs(build_temp)
        except OSError as e:
            if e.errno != errno.EEXIST:
                raise

        if not os.path.exists(absolute('libsecp256k1')):
            # library needs to be downloaded
            self.get_source_files()

        if not os.path.exists(absolute('libsecp256k1/configure')):
            # configure script hasn't been generated yet
            autogen = absolute('libsecp256k1/autogen.sh')
            os.chmod(absolute(autogen), 0o755)
            subprocess.check_call([autogen], cwd=absolute('libsecp256k1'))

        for filename in [
                'libsecp256k1/configure',
                'libsecp256k1/build-aux/compile',
                'libsecp256k1/build-aux/config.guess',
                'libsecp256k1/build-aux/config.sub',
                'libsecp256k1/build-aux/depcomp',
                'libsecp256k1/build-aux/install-sh',
                'libsecp256k1/build-aux/missing',
                'libsecp256k1/build-aux/test-driver',
        ]:
            try:
                os.chmod(absolute(filename), 0o755)
            except OSError as e:
                # some of these files might not exist depending on autoconf version
                if e.errno != errno.ENOENT:
                    # If the error isn't 'No such file or directory' something
                    # else is wrong and we want to know about it
                    raise

        cmd = [
            absolute('libsecp256k1/configure'),
            '--disable-shared',
            '--enable-static',
            '--disable-dependency-tracking',
            '--with-pic',
            '--enable-module-recovery',
            '--prefix',
            os.path.abspath(self.build_clib),
            '--enable-experimental',
            '--enable-module-ecdh',
            '--enable-benchmark=no',
            '--enable-tests=no',
            '--enable-openssl-tests=no',
            '--enable-exhaustive-tests=no',
        ]
        if 'COINCURVE_CROSS_HOST' in os.environ:
            cmd.append('--host={}'.format(os.environ['COINCURVE_CROSS_HOST']))

        log.debug('Running configure: {}'.format(' '.join(cmd)))
        subprocess.check_call(cmd, cwd=build_temp)

        subprocess.check_call([MAKE], cwd=build_temp)
        subprocess.check_call([MAKE, 'install'], cwd=build_temp)

        self.build_flags['include_dirs'].extend(
            build_flags('libsecp256k1', 'I', build_temp))
        self.build_flags['library_dirs'].extend(
            build_flags('libsecp256k1', 'L', build_temp))
        if not has_system_lib():
            self.build_flags['define'].append(('CFFI_ENABLE_RECOVERY', None))
        else:
            pass
Beispiel #11
0
        kwargs['include_dirs'] = [absolute(os.environ['INCLUDE_DIR'])]
    if 'LIB_DIR' in os.environ:
        kwargs['library_dirs'] = [absolute(os.environ['LIB_DIR'])]
    for source in sources:
        with open(source.h, 'rt') as h:
            ffi.cdef(h.read())
        code.append(source.include)
    if bundled:
        code.append("#define PY_USE_BUNDLED")
    ffi.set_source(name, "\n".join(code), **kwargs)
    return ffi


_base = [
    Source(
        absolute("_cffi_build/secp256k1.h"),
        "#include <secp256k1.h>",
    )
]

_modules = {
    'ecdh':
    Source(
        absolute("_cffi_build/secp256k1_ecdh.h"),
        "#include <secp256k1_ecdh.h>",
    ),
    'recovery':
    Source(
        absolute("_cffi_build/secp256k1_recovery.h"),
        "#include <secp256k1_recovery.h>",
    ),
Beispiel #12
0
    def run(self):
        if has_system_lib():
            log.info("Using system library")
            return

        build_temp = os.path.abspath(self.build_temp)

        try:
            os.makedirs(build_temp)
        except OSError as e:
            if e.errno != errno.EEXIST:
                raise

        if not os.path.exists(absolute("libsecp256k1/configure")):
            # configure script hasn't been generated yet
            autogen = absolute("libsecp256k1/autogen.sh")
            os.chmod(absolute(autogen), 0o755)
            subprocess.check_call(
                [autogen],
                cwd=absolute("libsecp256k1"),
            )

        for filename in [
            "libsecp256k1/configure",
            "libsecp256k1/build-aux/compile",
            "libsecp256k1/build-aux/config.guess",
            "libsecp256k1/build-aux/config.sub",
            "libsecp256k1/build-aux/depcomp",
            "libsecp256k1/build-aux/install-sh",
            "libsecp256k1/build-aux/missing",
            "libsecp256k1/build-aux/test-driver",
        ]:
            try:
                os.chmod(absolute(filename), 0o755)
            except OSError as e:
                # some of these files might not exist depending on autoconf version
                if e.errno != errno.ENOENT:
                    # If the error isn't "No such file or directory" something
                    # else is wrong and we want to know about it
                    raise

        cmd = [
            absolute("libsecp256k1/configure"),
            "--disable-shared",
            "--enable-static",
            "--disable-dependency-tracking",
            "--with-pic",
            "--enable-module-recovery",
            "--prefix",
            os.path.abspath(self.build_clib),
        ]
        if os.environ.get('SECP_BUNDLED_WITH_BIGNUM'):
            log.info("Building with bignum support (requires libgmp)")
            cmd.extend(["--with-bignum=gmp"])
        else:
            cmd.extend(["--without-bignum"])

        if os.environ.get('SECP_BUNDLED_EXPERIMENTAL'):
            log.info("Building experimental")
            cmd.extend([
                "--enable-experimental",
                "--enable-module-ecdh",
                "--enable-module-schnorr",
            ])

        log.debug("Running configure: {}".format(" ".join(cmd)))
        subprocess.check_call(
            cmd,
            cwd=build_temp,
        )

        subprocess.check_call(["make"], cwd=build_temp)
        subprocess.check_call(["make", "install"], cwd=build_temp)

        self.build_flags['include_dirs'].extend(build_flags('libsecp256k1', 'I', build_temp))
        self.build_flags['library_dirs'].extend(build_flags('libsecp256k1', 'L', build_temp))
        if not has_system_lib():
            self.build_flags['define'].append(('CFFI_ENABLE_RECOVERY', None))
        else:
            pass
Beispiel #13
0
    code = []
    if "INCLUDE_DIR" in os.environ:
        kwargs["include_dirs"] = [absolute(os.environ["INCLUDE_DIR"])]
    if "LIB_DIR" in os.environ:
        kwargs["library_dirs"] = [absolute(os.environ["LIB_DIR"])]
    for source in sources:
        with open(source.h, "rt") as h:
            ffi.cdef(h.read())
        code.append(source.include)
    if bundled:
        code.append("#define PY_USE_BUNDLED")
    ffi.set_source(name, "\n".join(code), **kwargs)
    return ffi


_base = [Source(absolute("_cffi_build/secp256k1.h"), "#include <secp256k1.h>")]

_modules = {
    "ecdh": Source(absolute("_cffi_build/secp256k1_ecdh.h"), "#include <secp256k1_ecdh.h>"),
    "recovery": Source(absolute("_cffi_build/secp256k1_recovery.h"), "#include <secp256k1_recovery.h>"),
    "schnorr": Source(absolute("_cffi_build/secp256k1_schnorr.h"), "#include <secp256k1_schnorr.h>"),
}


ffi = None

# The following is used to detect whether the library is already installed on
# the system (and if so which modules are enabled) or if we will use the
# bundled one.
if has_system_lib():
    _available = []
Beispiel #14
0
        kwargs['include_dirs'] = [absolute(os.environ['INCLUDE_DIR'])]
    if 'LIB_DIR' in os.environ:
        kwargs['library_dirs'] = [absolute(os.environ['LIB_DIR'])]
    for source in sources:
        with open(source.h, 'rt') as h:
            ffi.cdef(h.read())
        code.append(source.include)
    if bundled:
        code.append("#define PY_USE_BUNDLED")
    ffi.set_source(name, "\n".join(code), **kwargs)
    return ffi


_base = [
    Source(
        absolute("_cffi_build/secp256k1.h"),
        "#include <secp256k1.h>",
    )
]

_modules = {
    'ecdh':
    Source(
        absolute("_cffi_build/secp256k1_ecdh.h"),
        "#include <secp256k1_ecdh.h>",
    ),
    'recovery':
    Source(
        absolute("_cffi_build/secp256k1_recovery.h"),
        "#include <secp256k1_recovery.h>",
    ),